Linux System
Administration Commands
Listing the currently logged-in users
• When a user logged-in, Linux stores his information
#cat /var/run/utmp
• username, terminal number and login time
• #who
• #who am I
Knowing the last successful login,
failed login attempts and system reboot
time
• keeping track of active users,
• keeps the record of previous successful login
sessions,
• failed login attempts
• last system reboots.
• stores information about previous successful login
sessions in the file /var/log/wtmp.
• stores information about the failed login attempts
in the file /var/log/btmp.
last, last reboot, lastb
commands
#last
• The last command prints the list of users who had
successfully accessed the system.
#last reboot
• The last reboot command prints the last reboot
time of the system.
• #lastb
• The lastb command prints the list of failed login
attempts.
Getting detailed information about active users
• detailed information about active users
• what they are doing
#w
• w command provides two types of information; System
specific and User specific.
• System specific information
• Current time of day
• System uptime
• Total number of active users (currently logged in)
• Average load (number of jobs in run queue)
User specific information
• User login name
• Terminal number from which user is logged in
• Host name (Name of system where user is logged in)
• Login session time (the time the user stayed logged-in)
• Last activity time (the time since the user last typed
anything)
• JCPU time (the time taken by all process excluding past
background jobs.)
• PCPU time (the time taken by current process)
• Current process
Knowing hostname, kernel version
number, processor type and hardware
architecture
#uname
• Used to view the basic system information such as
• hostname
• operating system name
• hardware platform
• kernel information
common options with
description
Option Description
• -s kernel name
• -n node name
• -r kernel release
• -v kernel build date
• -m hardware name
• -p processor type
• -i hardware platform
• -o OS name
• -a all above information
Viewing and setting the
hostname
• To view the hostname only, use
the hostname command.
#hostname
• To view the detailed information about hostname
along with the hardware information, use
the hostnamectl command.
# hostnamectl
Viewing and setting the date and time
• To view basic date and time, we use the command
#date
To view detailed information, we use the command
#timedatectl
Linux uptime
• The uptime command tells us how long a system has
been running.
• current system time
• duration for which system has been running
• number of users logged in
• system load average
Linux service
• service command start, stop and restart
• a daemon or services will be initiated by calling the
script.
• Usually all scripts are stored in /etc/init.d directory.
status command
• To stop a service
#service script_name status
#service network status
start command
• To start a service
#service script_name start
#service network start
stop command
• To stop a service
#service script_name stop
#service network stop
restart command
• To restart a service
#service script_name restart
#service network restart
Linux Terminating
• To terminate a process
• to run the system uninterruptedly
• after terminating a process without rebooting the
system.
• internal or external.
Command Function
kill Need to specify PID number
killall Kill more than one process with a single name
pkill Need to specify name of the process
xkill Kill a x server client
How to know PID?
• To terminate a process, we need to know the PID’s
#ps - A
Common signal names and numbers
Signal Name Signal Number Signal Use
SIGNULL 0 NULL, check access to PID
SIGHUP 1 Hangup
SIGINT 2 Interrupt
SIGQUIT 3 Quit
SIGKILL 9 Kill
SIGTERM 15 Terminate
SIGSTOP 24 Stop
SIGTSTP 25 Stop/pause the process
SIGCONT 26 Continue a stopped process
To list signal names, the following command is used
#kill –l
Linux kill
• The most common command to terminate a
process is kill command
• kill command sends signal to the specified process.
• For sending signal either signal name or signal
number can be used.
kill -SIGNAL PID
#kill -9 2134
Pmap command
• The command pmap reports memory map of one
process or multiple processes.
• It displays information about memory usage and
address space of a process.
• To check pmap of a process we need PID of the
process.
#pmap PID
#pmap 2134
Linux ls command options
ls option Description
ls -a In Linux, hidden files start with . (dot) symbol
and they are not visible in the regular directory.
The (ls -a) command will enlist the whole list of
the current directory including the hidden files.
ls -l It will show the list in a long list format.
ls -lh This command will show you the file sizes in
human readable format. Size of the file is very
difficult to read when displayed in terms of byte.
The (ls -lh)command will give you the data in
terms of Mb, Gb, Tb, etc.
ls -lhS If you want to display your files in descending
order (highest at the top) according to their size,
then you can use (ls -lhS) command.
ls -l - -block-size=[SIZE] It is used to display the files in a specific size
format. Here, in [SIZE] you can assign size
according to your requirement.
ls -d */ It is used to display only subdirectories.
ls -g or ls -lG With this you can exclude column of group
information and owner.
ls -n It is used to print group ID and owner ID instead of
their names.
ls --color=[VALUE] This command is used to print list as colored or
discolored.
ls -li This command prints the index number if file is in
the first column.
ls -p It is used to identify the directory easily by marking
the directories with a slash (/) line sign.
ls -r It is used to print the list in reverse order.
ls -R It will display the content of the sub-directories
also.
ls -lX It will group the files with same extensions together
in the list.
ls -lt It will sort the list by displaying recently modified
filed at top.
ls ~ It gives the contents of home directory.
ls ../ It give the contents of parent directory.
ls --version It checks the version of ls command.