Skip to main content

21 Useful Linux Commands for System Administrators

Follow >> fb.com/edu.dheeraj


In this article we are going to review some of the useful and frequently used Linux or Unix commands for Linux System Administrators that are used in their daily life. This is not a complete but it’s a compact list of commands to refer when needed. Let us start one by one how we can use those commands with examples.





1. Uptime Command

In Linux uptime command shows since how long your system is running and the number of users are currently logged in and also displays load average for 1,5 and 15 minutes intervals.

# uptime

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

Check Uptime Version

Uptime command don’t have other options other than uptime and version. It gives information only in hours:mins if it less than 1 day.

[tecmint@tecmint ~]$ uptime -V
procps version 3.2.8

2. W Command

It will 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:27:44 up 34 min,  1 user,  load average: 0.00, 0.00, 0.08
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
tecmint  pts/0    192.168.50.1     07:59    0.00s  0.29s  0.09s w

Available options

  1. -h : displays no header entries.
  2. -s : without JCPU and PCPU.
  3. -f : Removes from field.
  4. -V : (upper letter) – Shows versions.

3. Users Command

Users command displays currently logged in users. This command don’t have other parameters other than help and version.
# users

tecmint



4. Who Command

who command simply return user name, date, time and host information. who command is similar to w command. Unlike w command who doesn’t print what users are doing. Lets illustrate and see the different between who and w commands.
# who

tecmint  pts/0        2012-09-18 07:59 (192.168.50.1)
 
# w

08:43:58 up 50 min,  1 user,  load average: 0.64, 0.18, 0.06
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
tecmint  pts/0    192.168.50.1     07:59    0.00s  0.43s  0.10s w
 
 
 

Who command Options

  1. -b : Displays last system reboot date and time.
  2. -r : Shows current runlet.
  3. -a, –all : Displays all information in cumulatively.

5. Whoami Command

whoami command print the name of current user. You can also use “who am i” command to display the current user. If you are logged in as a root using sudo command “whoami” command return root as current user. Use “who am i” command if you want to know the exact user logged in.

# whoami

Dips

6. ls Command

ls command display list of files in human readable format.
 
# ls -l

total 114
dr-xr-xr-x.   2 root root  4096 Sep 18 08:46 bin
dr-xr-xr-x.   5 root root  1024 Sep  8 15:49 boot

Sort file as per last modified time.

# ls -ltr

total 40
-rw-r--r--. 1 root root  6546 Sep 17 18:42 install.log.syslog
-rw-r--r--. 1 root root 22435 Sep 17 18:45 install.log
-rw-------. 1 root root  1003 Sep 17 18:45 anaconda-ks.cfg
 
 

7. Crontab Command

List schedule jobs for current user with crontab command and -l option.

# crontab -l 00 10 * * * /bin/ls >/ls.txt 

Edit your crontab with -e option. In the below example will open schedule jobs in VI editor. Make a necessary changes and quit pressing :wq keys which saves the setting automatically.

# crontab -e

8. Less Command

less command allows quickly view file. You can page up and down. Press ‘q‘ to quit from less window.

# less install.log

Installing setup-2.8.14-10.el6.noarch
warning: setup-2.8.14-10.el6.noarch: Header V3 RSA/SHA256 Signature, key ID c105b9de: NOKEY
Installing filesystem-2.4.30-2.1.el6.i686
Installing ca-certificates-2010.63-3.el6.noarch
Installing xml-common-0.6.3-32.el6.noarch
Installing tzdata-2010l-1.el6.noarch
Installing iso-codes-3.16-2.el6.noarch

 

9. More Command

more command allows quickly view file and shows details in percentage. You can page up and down. Press ‘q‘ to quit out from more window.

# more install.log

Installing setup-2.8.14-10.el6.noarch
warning: setup-2.8.14-10.el6.noarch: Header V3 RSA/SHA256 Signature, key ID c105b9de: NOKEY
Installing filesystem-2.4.30-2.1.el6.i686
Installing ca-certificates-2010.63-3.el6.noarch
Installing xml-common-0.6.3-32.el6.noarch
Installing tzdata-2010l-1.el6.noarch
Installing iso-codes-3.16-2.el6.noarch
--More--(10%)

 

10. CP Command

Copy file from source to destination preserving same mode.

# cp -p fileA fileB
 
You will be prompted before overwrite to file.

# cp -i fileA fileB

11. MV Command

Rename fileA to fileB. -i options prompt before overwrite. Ask for confirmation if exist already.

# mv -i fileA fileB

12. Cat Command

cat command used to view multiple file at the same time.

# cat fileA fileB
 
You combine more and less command with cat command to view file contain if that doesn’t fit in single screen / page.

# cat install.log | less

# cat install.log | more
 
 

13. Cd command (change directory)

with cd command (change directory) it will goes to fileA directory.

# cd /fileA

 

14. pwd command (print working directory)

pwd command return with present working directory.

# pwd /root

 

15. Sort command

Sorting lines of text files in ascending order. with -r options will sort in descending order.

#sort fileA.txt #sort -r fileA.txt
 

16. VI Command

Vi is a most popular text editor available most of the UNIX-like OS. Below examples open file in read only with -R option. Press ‘:q‘ to quit from vi window.

# vi -R /etc/shadows
 

17. SSH Command (Secure Shell)

SSH command is used to login into remote host. For example the below ssh command will connect to remote host (192.158.30.8) using user as Dips.

# ssh Dips@192.158.30.8
  To check the version of ssh use option -V (uppercase) shows version of ssh.

# ssh -V OpenSSH_5.3p1, OpenSSL 1.0.0-fips 29 Mar 2010

 

 18. Ftp or sftp Command

ftp or sftp command is used to connect to remote ftp host. ftp is (file transfer protocol) and sftp is (secure file transfer protocol). For example the below commands will connect to ftp host (192.148.57.23).

# ftp 192.148.57.23
 # sftp 192.148.57.23
  Putting multiple files in remote host with mput similarly we can do mget to download multiple files from remote host.

# ftp > mput *.txt # ftp > mget *.txt
 

19. Service Command

Service command call script located at /etc/init.d/ directory and execute the script. There are two ways to start the any service. For example we start the service called httpd with service command.

# service httpd start
  OR
 # /etc/init.d/httpd start

20. Free command

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

# free total used free shared buffers cached Mem: 1030800 735944 294856 0 51648 547696 -/+ buffers/cache: 136600 894200 Swap: 2064376 0 2064376 

Free with -t options shows total memory used and available to use in bytes.

# free -t total used free shared buffers cached Mem: 1030800 736096 294704 0 51720 547704 -/+ buffers/cache: 136672 894128 Swap: 2064376 0 2064376 Total: 3095176 736096 2359080

21. Top Command

top command 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. Use top command with ‘u‘ option this will display specific User process details as shown below. Press ‘O‘ (uppercase letter) to sort as per desired by you. Press ‘q‘ to quit from top screen.

# top -u tecmint top - 11:13:11 up 3:19, 2 users, load average: 0.00, 0.00, 0.00 Tasks: 116 total, 1 running, 115 sleeping, 0 stopped, 0 zombie Cpu(s): 0.0%us, 0.3%sy, 0.0%ni, 99.7%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st Mem: 1030800k total, 736188k used, 294612k free, 51760k buffers Swap: 2064376k total, 0k used, 2064376k free, 547704k cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 1889 tecmint 20 0 11468 1648 920 S 0.0 0.2 0:00.59 sshd 1890 tecmint 20 0 5124 1668 1416 S 0.0 0.2 0:00.44 bash 6698 tecmint 20 0 11600 1668 924 S 0.0 0.2 0:01.19 sshd 6699 tecmint 20 0 5124 1596 1352 S 0.0 0.2 0:00.11 bash
 

Comments

Popular posts from this blog

[Fix] SSL Error or Invalid Security Certificate Problem While Opening Facebook or Other Websites

Today we are going to address a very strange and annoying issue which occurs when you try to open a website using  HTTPS  (Hypertext Transfer Protocol Secure) protocol such as  Facebook, Twitter, Google, etc . The problem occurs in all web browsers whether its  Internet Explorer ,  Google Chrome ,  Mozilla Firefox  or  Opera  but the error messages and problem symptom might differ in different web browsers. Problem Symptom: When you open a HTTPS website such as Facebook, Twitter, etc in your favorite web browser, following things happen: In Google Chrome web browser: The website doesn't open and you see a  red cross on padlock icon  and a  red line through the https://  text in the addressbar with following error message: SSL Error Cannot connect to the real www.facebook.com Something is currently interfering with your secure connection to www.facebook.com. Try to reload this page in a few m...

FAQ's Salesforce Lightning Platform Query Optimizer

This article comprises the FAQs related to salesforce internal platform Query Optimizer.and provides valuable information that will help understand how to improve the performance of SOQL queries. For more information, you may also check this Dreamforce Session . 1. Query Optimizer Q: Does Salesforce have its own SQL optimization logic instead of Oracle's built-in? A: Force.com is a multi-tenant platform. To consider multitenant statistics, the platform has its own SOQL query optimizer that determines optimal SQL to satisfy a specific tenant's request. Q: How frequently generated are the statistics used by the query optimizer? A: Statistics are gathered weekly. Where statistics are not calculated, the optimizer also performs dynamic pre-queries, whose results are cached for 1 hour Q: Is there any way to flush the cache when doing your performance testing so your results are not cached biased? A: Unfortunately not. Queries with selective filters will perform mor...

Google Tricks

Google isn't just for hypochondriacs looking up their symptoms or for trying to find a cool new restaurant. By just entering a few simple search terms, you can use Google to help plan and organize your life. It is  amazing . 1.) You can use Google as a timer, just set the time in the search bar as shown here. 2.) Google will also help you calculate your tips. 3.) You can find out what date any holiday falls on. 4.) Google will also find movie release dates for you. 5.) You can find full schedules for your favorite television shows. 6.) Google will also find the songs of your favorite bands. 7.) You can use the search engine to find what books your favorite authors wrote. 8.) It'll look up flight information for you. 9.) Do you know what time the sun rises? It'll tell you. 10.) It'll also give you information on your...