30 Helpful Linux commands for every system admin and developer must know. today I am sharing 30 Helpful Linux Commands for Linux so you can learn more about Linux commands and the use of these 30 Helpful Linux Commands.

1. Uptime Command

In Linux uptime command shows system status how long it has been online and the number of users who are currently logged in and also displays the load average of a system for 15, 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 do you know that you can also check the uptime program version, It gives information only in hours:mins: sec if it is less than 1 day.

# uptime -V
procps version 3.2.8

2. W Command

The w command show users currently logged in and their process along with showing load averageslogin name nameremote hostlogin timeidle timeJCPUPCPU, 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
serverconfig  pts/0    192.168.50.1     07:59    0.00s  0.29s  0.09s w

Additional Options

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

3. Users Command

Users command show you on display all the currently logged-in users.

# users

serverconfig

4. Who Command

who command shows you user name, date, time, and host information. who command is similar to w command. Unlike the w command doesn’t print what users are doing. Let’s illustrate and see the difference between who and w commands.

# who

serverconfig  pts/0        2012-09-18 07:59 (192.18.30.12)
# 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
server config  pts/0    192.168.50.1     07:59    0.00s  0.43s  0.10s w

Who command Options

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

5. Whoami Command

In Linux, a whoami command is used to display the currently logged-in username into your Linux system. If you are logged in as a root using sudo command “whoami” command return root as the current user.

# whoami

root

6. ls Command

ls command displays a list of files in a 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

For more examples of the ls command, please check out our articles:

7. Crontab Command

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

# crontab -l

00 10 * * * /bin/ls >/ls.txt

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

# crontab -e

8. Less Command

less command allows quickly viewing the 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

cp command copies file from source to destination preserving the same mode.

# cp -p fileA fileB

You will be prompted before overwrite to file.

# cp -i fileA fileB

11. MV Command

An mv command renames fileA to fileB using the -i option, which prompts confirmation before overwriting. Ask for confirmation if exist already.

# mv -i fileA fileB

12. Cat Command

The cat command is used to view multiple files 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 the cd command (change directory or switch directory) it will go to fileA directory.

# cd /fileA

14. pwd command (print working directory)

A pwd command return with the present working directory.

# pwd

/root

15. Sort command

The sort command is used to sort 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 the most popular text editor available in most UNIX-like OS. Below examples open file in read-only with -R option. Press ‘:q‘ to quit from vi windows.

# vi -R /etc/shadows

17. SSH Command (Secure Shell)

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

# ssh narad@192.168.50.2

To check the version of ssh use the option -V (uppercase) shows version of ssh.

# ssh -V

OpenSSH_8.2p1 Ubuntu-4ubuntu0.3, OpenSSL 1.1.1f  31 Mar 2020

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.168.50.2).

# ftp 192.168.50.2

# sftp 192.168.50.2

Putting multiple files in remote host with mput similarly, we can do mget to download multiple files from the remote host.

# ftp > mput *.txt

# ftp > mget *.txt

19. Systemctl Command

Systemctl command is a systemd management tool that is used to manage services, check running statuses, start and enable services and work with the configuration files.

# systemctl start httpd.service
# systemctl enable httpd.service
# systemctl status httpd.service

20. Free command

The free command shows freetotal, 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 show 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.

Using the top command with u the option will display specific User process details as shown below. Press ‘O‘ (uppercase letter) to sort as desired by you. Press ‘q‘ to quit from the top screen.

# top -u serverconfig

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 serverconfig   20   0 11468 1648  920 S  0.0  0.2   0:00.59 sshd
1890 sevrerconfig   20   0  5124 1668 1416 S  0.0  0.2   0:00.44 bash
6698 serverconfig   20   0 11600 1668  924 S  0.0  0.2   0:01.19 sshd
6699 serverconfig   20   0  5124 1596 1352 S  0.0  0.2   0:00.11 bash

For more about top command, we’ve already compiled a list of 12 TOP Command Examples in Linux.

22. Tar Command

The tar command is used to compress files and folders in Linux. For example, the below command will create an archive for /home directory with the file name archive-name.tar.

# tar -cvf archive-name.tar /home

To extract the tar archive file use the option as follows.

# tar -xvf archive-name.tar

23. Grep Command

grep command search for a given string in a file. Only serverconfig user displays from /etc/passwd file. we can use -i an option for ignoring case sensitivity.

# grep serverconfig /etc/passwd

serverconfig:x:500:500::/home/serverconfig:/bin/bash

24. Find Command

Find command used to search filesstrings, and directories. The below example of find command search serverconfig word in ‘/‘ partition and return the output.

# find / -name serverconfig

/var/spool/mail/serverconfig
/home/serverconfig
/root/home/serverconfig

25. lsof Command

lsof mean List of all open files. Below lsof a command list of all opened files by user serverconfig.

# lsof -u serverconfig

COMMAND  PID    USER   FD   TYPE     DEVICE SIZE/OFF   NODE NAME
sshd    1889 serverconfig  cwd    DIR      253,0     4096      2 /
sshd    1889 serverconfig  txt    REG      253,0   532336 298069 /usr/sbin/sshd
sshd    1889 serverconfig  DEL    REG      253,0          412940 /lib/libcom_err.so.2.1
sshd    1889 serverconfig  DEL    REG      253,0          393156 /lib/ld-2.12.so
sshd    1889 serverconfig  DEL    REG      253,0          298643 /usr/lib/libcrypto.so.1.0.0
sshd    1889 serverconfig  DEL    REG      253,0          393173 /lib/libnsl-2.12.so
sshd    1889 serverconfig  DEL    REG      253,0          412937 /lib/libkrb5support.so.0.1
sshd    1889 serverconfig  DEL    REG      253,0          412961 /lib/libplc4.so

26. last command

With the last command, we can watch the user’s activity in the system. This command can execute normal users also. It will display complete user’s info like terminaltimedatesystem reboot or boot, and kernel version. A useful command to troubleshoot.

# last

serverconfig  pts/1        192.168.50.1     Tue Sep 18 08:50   still logged in
serverconfig  pts/0        192.168.50.1     Tue Sep 18 07:59   still logged in
reboot   system boot  2.6.32-279.el6.i Tue Sep 18 07:54 - 11:38  (03:43)
root     pts/1        192.168.50.1     Sun Sep 16 10:40 - down   (03:53)
root     pts/0        :0.0             Sun Sep 16 10:36 - 13:09  (02:32)
root     tty1         :0               Sun Sep 16 10:07 - down   (04:26)
reboot   system boot  2.6.32-279.el6.i Sun Sep 16 09:57 - 14:33  (04:35)
narad    pts/2        192.168.50.1     Thu Sep 13 08:07 - down   (01:15)

You can use last with username to know for specific user’s activity as shown below.

# last serverconfig

serverconfig  pts/1        192.168.50.1     Tue Sep 18 08:50   still logged in
serverconfig  pts/0        192.168.50.1     Tue Sep 18 07:59   still logged in
serverconfig  pts/1        192.168.50.1     Thu Sep 13 08:07 - down   (01:15)
serverconfig  pts/4        192.168.50.1     Wed Sep 12 10:12 - 12:29  (02:17)

27. ps command

The ps command displays processes running in the system. The below example show the init to process only.

# ps -ef | grep init

root         1     0  0 07:53 ?        00:00:04 /sbin/init
root      7508  6825  0 11:48 pts/1    00:00:00 grep init

28. kill command

Use the kill command to terminate the process. First, find process id with ps command as shown below and kill the process with kill -9 command.

# ps -ef | grep init
root         1     0  0 07:53 ?        00:00:04 /sbin/init
root      7508  6825  0 11:48 pts/1    00:00:00 grep init

# kill- 9 7508

29. rm command

rm command used to remove or delete a file without prompting for confirmation.

# rm filename

Use the -i option to get confirmation before removing it. Using options ‘-r‘ and ‘-f‘ will remove the file forcefully without confirmation.

# rm -i test.txt

rm: remove regular file `test.txt'?

30. mkdir command example.

mkdir command is used to create directories under Linux.

# mkdir directoryname

This is a handy day-to-day used basic commands in Linux / Unix-like operating system. Kindly share through our comment box if we missed out.

Comments to: 30 Helpful Linux Commands for System Administrators

    Your email address will not be published. Required fields are marked *