Commands For Linux System Administration


PS : This page keeps on updating !

SystemAdministration                                                                                  

The startup and shutdown scripts are located in /etc/rc.d . These are usually used by root and used for system maintenance or emergency filesystem repairs. Use with caution, as some of these commands may damage your system.

Users
Show all logged on users. This is the approximate equivalent of
# who -q

Groups
Shows all groups in the system
# groups
# echo $GROUPS

Chown
The chown command changes the ownership of a file or files. This command is a useful method that root can use to shift file ownership from one user to another.
# chown filename/dirname
# chown -R filename/dirname  // Appending the ownership to the child folders/files

Chgrp
The chgrp command changes the group ownership of a file or files
# chgrp filename/dirname

Useradd
It adds a user account to the system and creates a home directory for that particular user
# useradd username

Userdel
This command removes a user account from the system  and deletes associated files.
# userdel username
# userdel -r username // removes the home directory as well

GroupDel
Delete a group
# groupdel gpname

Creating a user and assign it to a group

# usermod -G <gp name> <user name>   // existing group and existing user
# useradd -G  <gp name> <user name>   //  existing group and new user

Usermod
Modify/renaming a user account. Changes may be made to the password, group membership, expiration date, and other attributes of a given user's account. With this command, a user's password may be locked, which has the effect of disabling the account.
#usermod -l newname oldname

Groupmod
Modify a given group. The group name and/or ID number may be changed using this command.
#groupmod

Id
It lists the real and effective user IDs and the group IDs of the user associated with the current process.
#id

Password
Creating/reset a password for user
# passwd username
Removing password for a user
# passwd -d username

Putting A Program In The Background
# monitor.sh &
[1] 1234

To view the background process
#bg
[2]+ monitort.sh &

Listing Your Processes
Display a list of the processes we have launched
# ps
PID TTY TIME CMD
121 pts/4 00:00:00 bash
226 pts/4 00:00:00 monitor.sh
237 pts/4 00:00:00 ps

Killing A Process
Suppose that you have a program that becomes unresponsive,To identify the process you want to kill. You can use either jobs or ps. If you use jobs you will get back a job number.

# kill %1
    OR
# kill 226 // process id

Uptime
How long your system is running and the number of users are currently logged in and also displays load average of the machine for 1,5 and 15 minutes intervals.

# uptime
08:16:26 up 22 min,  1 user,  load average: 0.00, 0.03, 0.22

W
Displays users currently logged in and their process along-with shows load averages. also shows the login name, tty name, remote host, login time, idle time, JCPU, PCPU, command and processes.

# w
08:12:00 up 55 min,  1 user,  load average: 0.00, 0.03, 0.08
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
vivek        pts/0    192.168.100.33     08:08       0.00s     0.29s    0.09s   w

ls
Lists files and folders.

#ls           // Just display
#ls -ltr     // Sort file as per last modified time.

Crontab
Used for task scheduling .

# crontab -e -u <username>
* * * * * mkdir /heloo
These five stars represents min,hour,day of month,month,day of week

#crontab -l     // to list
#crontab -e   // to edit

Less
It helps quick view file. You can page up and page down to scrol. Press ‘q‘ to quit.

More
It helps to view file and shows details in percentage. You can page up and down. Press ‘q‘ to quit out from more window.

Cat
It is used to view single/multiple file at the same time.

#cat error.log access.log  
#cat apache.log | less     // with less command
#cat apache.log | more  // with more command

pwd (Present Working Directory)
It return with present working directory.

#pwd

Free
Free command shows free, total and swap memory information in bytes.

# free -m
                      total       used       free     shared    buffers     cached
Mem:         24020      13548      10471          0         43        666
-/+ buffers/cache:      12838      11182
Swap:         8191          0       8191

Top
It displays processor activity of your system and also displays tasks managed by kernel in real-time. It’ll show processor and memory are being used. Press ‘q‘ to quit. [Task manager in windows]

Grep
Search for a given string in a file.

# grep vivek /etc/passwd
vivek:x:502:502::/home/vivek:/bin/bash

Find
Search files, strings and directories.

# find / -name vivek
/home/vivek
/root/home/vivek

lsof
It Lists of all open files.

last
we can watch users login informations.

#last -n 10   // Displays last 10 users login details

ifconfig
For displaying ipaddress and its corresponding details

#ifconfig
#ifconfig eth0 down                    // Disable an Interface
#ifconfig eth0 up                       // Enable an Interface
#ifconfig eth0 192.168.100.1  // Assign IP Address to an Interface
#ifconfig eth0 netmask 255.255.255.0          // Change Subnet Mask of Interface eth0
#ifconfig eth0 broadcast 192.168.100.255  // Change Broadcast Address of Interface eth0
#ifconfig eth0 192.168.100.12 netmask 255.255.255.0 broadcast 192.168.100.255 // Assign IP Address, Netmask and Broadcast to Interface eth0

netstat
netstat command displays various network related information such as network connections, routing tables, interface statistics, masquerade connections, etc.....

#netstat -a       // List All Network Ports
#netstat -at    // List All TCP Ports
#netstat -s    // Show Statistics for All Ports

nslookup

#nslookup google.com                         //  Used to obtain for quering Domain Name System
#nslookup -query=mx google.com     // Query Mail Exchanger Record
#nslookup -type=ns google.com       // Query Name Server
#nslookup -type=any google.com   // Query DNS Record
#nslookup -type=soa google.com  // Query Start of Authority

dig
Used for querying DNS name servers for information about host addresses, mail exchanges, name servers, and others.

#dig google.com

wall
It sends a message to everybody logged in the terminal.only if mesg permission set to "yes"

#wall "Hey !"

mesg
To control if people can use the “write” command, to send text to you over the screen.

#mesg y/n

ac
Show users' total logged in time, as read from /var/log/wtmp
#ac
total     1764.94

hostname
Shows macines name

#hostname   // to view machine name
#hostname <new name>  //  to change hostname (temporary)
#vim /etc/sysconfig/network  // to change hostname field (permanent)

nmap
Network mapper and port scanner. This command scans a server to locate open ports and the services associated with those ports. It can also report information about packet filters and firewalls. This is an important security tool for locking down a network against hacking attempts.


mount
Mount a filesystem, usually on an external device, such as a floppy or CDROM. The file /etc/fstab provides a handy listing of available filesystems, partitions, and devices, including options, that may be automatically or manually mounted.mount -a mounts all filesystems and partitions listed in /etc/fstab

# mount    // will display all mounted partitions

Example for manual mounting
mount /dev/cdrom /mnt                       //   mount cdrom to /mnt partition
Example for permanant mounting
vim /etc/fstab
/dev/hda7    /data   ext3  defaults 00   // mount hda7 to /data

# umount
To umount the drives.

# umount /dev/cdrom



Commands For Linux System Administration Commands For Linux System Administration Reviewed by vivek sathisan on 13:00 Rating: 5

No comments:

© Copyright to vivek sathisan. Powered by Blogger.