30 Linux practical commands required by the system administrator
In this article, we will introduce some practical and commonly used Linux or Unix commands, which are commonly used by Linux system administrators. This article is not a complete list, but a brief list of commands that can be used as needed. The following example shows how to use these commands one by one.
1. uptime command
In Linux, the uptime command shows how long your system is running and the number of currently logged-on users. In addition, it also displays the average load values at intervals of 1 minute, 5 minutes, and 15 minutes.
- # Uptime
- 08:16:26 up 22 min, 1 user, load average: 0.00, 0.03, 0.22
Check uptime version
The uptime command has no other options except uptime (normal running time) and version (version. If the time is less than one day, it only gives information in the form of hours: mins.
- [Tecmint @ tecmint ~] $ Uptime-V
- Procps version 3.2.8
2. w command
This command displays the currently logged-on users and their processes, and the average load value. It also displays the logon name, tty name, remote host, Logon Time, idle time, JCPU, PCPU, commands, 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.00 s 0.29 s 0.09 s w
Available options
◆-H: The title is not displayed.
◆-S: JCPU and PCPU are not displayed.
◆-F: The field information is not displayed.
◆-V: (uppercase V)-display version.
3. users command
The users command displays the currently logged-on users. Except help and version, this command has no other parameters.
- # Users
- Tecmint
4. who command
The who command only returns the user name, date, time, and host information. The who command is similar to the w command. Unlike w commands, who does not output the information about operations performed by users. Let's take a look at the differences between the 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.00 s 0.43 s 0.10 s w
Who Command Options
◆-B: displays the last system restart date and time.
◆-R: displays the current running level.
◆-A,-all: displays all accumulated information.
5. whoami command
The whoami command outputs the name of the current user. You can also use the "who am I" command to display the current user. If you log on using the sudo command as the root user, the "whoami" command returns that the root user is the current user. If you want to know which login user is specific, use the "who am I" command.
- # Whoami
- Tecmint
6. ls command
The ls command displays the list of objects in human readable format.
- # Ls-l
-
- Total 114
- Dr-xr-x. 2 root 4096 Sep 18 08:46 bin
- Dr-xr-x. 5 root 1024 Sep 8 :49 boot
Sort files by the last modification time.
- # Ls-ltr
-
- Total 40
- -Rw-r --. 1 root 6546 Sep 17 install. log. syslog
- -Rw-r --. 1 root 22435 Sep 17 18:45 install. log
- -Rw -------. 1 root 1003 Sep 17 anaconda-ks.cfg
7. crontab command
You can use the crontab command and the-l option to list the scheduled tasks of the current user.
- # Crontab-l
- 00 10 ***/bin/ls>/ls.txt
You can use the-e Option to edit crontab. In the following example, you can use the VI editing tool to open a scheduled task. Make necessary changes and press: wq to exit. This will automatically save the settings.
- # Crontab-e
8. less command
The less command allows you to quickly view files. You can flip pages up and down. Press "q" to exit the 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
The more command allows you to quickly view files and display details in percentages. You can flip pages up and down. Press "q" to exit the 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 the file from the source to the destination and retain the same mode.
- # Cp-p fileA fileB
The system will prompt you before overwriting the file.
- # Cp-I fileA fileB
11. mv command
Rename fileA to fileB. -I option will be prompted before overwriting. If the file already exists, confirmation is required.
- # Mv-I fileA fileB
12. cat command
The cat command is used to view multiple files at the same time.
- # Cat fileA fileB
If a file cannot be displayed on a screen or page, you can use the cat command to merge more and less commands to view the file content.
- # Cat install. log | less
-
- # Cat install. log | more
13. cd command (Change directory)
With the cd command (Change directory), it will enter the fileA directory.
- # Cd/fileA
14. pwd command (output working directory)
The pwd command returns the current working directory.
- # Pwd
-
- /Root
15. sort command
Sort text files of a row in ascending order. If the-r option is used, it will be sorted in descending order.
- # Sort fileA.txt
-
- # Sort-r fileA.txt
16. vi command
For most UNIX-like operating systems, vi is the most popular text editor. The following example uses the-R option to open a file in read-only mode. Press ": q" to exit the vi window.
- # Vi-R/etc/shadows
17. ssh command (Security shell)
The ssh command is used to log on to the remote host. For example, the following ssh example uses the user as the narad to connect to the host (192.168.50.2 ).
- # Ssh narad@192.168.50.2
To check the ssh version, use option-V (uppercase) to display the ssh version.
- # Ssh-V
-
- OpenSSH_5.3p1, OpenSSL 1.0.0-fips 29 Mar 2010
18. ftp or sftp commands
The ftp or sftp command is used to connect to a remote ftp host. Ftp is the file transfer protocol, while sftp is the Secure File Transfer Protocol. For example, the following command will connect to the ftp host (192.168.50.2 ).
- # Ftp 192.168.50.2
-
- # Sftp 192.168.50.2
Just as you can use mput to upload multiple files to a remote host, we can also use mget to download multiple files from the remote host.
- # Ftp> mput *. txt
-
- # Ftp> mget *. txt
19. service Command
The service command calls the script in the/etc/init. d/directory and executes the script. There are two ways to start any service. For example, we use the service command to start a service named httpd.
- # Service httpd start
-
- OR
-
- #/Etc/init. d/httpd start
20. free command
The free command displays information about idle memory, total memory, and swap, in bytes.
- # Free
-
- Total used free shared buffers cached
- Mem: 1030800 735944 294856 0 51648 547696
- -/+ Buffers/cache: 136600 894200
- Swap: 2064376 0 2064376
The free command using the-t option shows the total memory used and available memory, 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
The top command displays the processor activity of the system and tasks managed in real time by the kernel. It displays the processor and memory used. If you use the top command with the "u" option, the detailed information of the specific user process is displayed, as shown below. Simply press "O" (in upper case) to sort it as you want. Press "q" to exit the top screen.
- # Top-u tecmint
-
- Top-11:13:11 up, 2 users, load average: 0.00, 0.00, 0.00
- Task: 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: 1030800 k total, 736188 k used, 294612 k free, 51760 k buffers
- Swap: 2064376 k total, 0 k used, 2064376 k free, 547704 k cached
-
- Pid user pr ni virt res shr s % CPU % mem time + COMMAND
- 1889 tecmint 20 0 11468 1648 S 920 0.0. 59 sshd
- 1890 tecmint 20 0 5124 1668 S 1416 0.0. 44 bash
- 6698 tecmint 20 0 11600 1668 S 924 0.0. 19 sshd
- 6699 tecmint 20 0 5124 1596 S 1352 0.0. 11 bash
22.tar command
The tar command is used to compress files and folders in Linux. For example, the following command creates a file named archive-name.tar for the/homecatalog.
- # Tar-cvf archive-name.tar/home
To decompress the tar compressed archive file, use the following options.
- # Tar-xvf archive-name.tar
23. grep command
Grep can be used to search for specific strings in a file. Only the tecmint user in the/etc/passwd file is displayed. We can use the-I option to ignore case sensitivity.
- # Grep tecmint/etc/passwd
-
- Tecmint: x: 500: 500:/home/tecmint:/bin/bash
24. find command
The find command is used to search for files, strings, and directories. In the following example, the find command searches for the tecmint word in the "/" partition and returns the output.
- # Find/-name tecmint
-
- /Var/spool/mail/tecmint
- /Home/tecmint
- /Root/home/tecmint
25. lsof command
Lsof means "listing all open files ". The following lsof command lists all files opened by the tecmint user.
- # Lsof-u tecmint
-
- Command pid user fd type device size/OFF NODE NAME
- Sshd 1889 tecmint cwd DIR 253,0 4096 2/
- Sshd 1889 tecmint txt REG 253,0 532336 298069/usr/sbin/sshd
- Sshd 1889 tecmint del reg 412940, 0/lib/libcom_err.so.2.1
- Sshd 1889 tecmint del reg 253,0 393156/lib/ld-2.12.so
- Sshd 1889 tecmint del reg 253,0 298643/usr/lib/libcrypto. so.1.0.0
- Sshd 1889 tecmint del reg 253,0 393173/lib/libnsl-2.12.so
- Sshd 1889 tecmint del reg 253,0 412937/lib/libkrb5support. so.0.1
- Sshd 1889 tecmint del reg 412961, 0/lib/libplc4.so
26. last Command
With the last command, we can observe the user's activities in the system. This command can also be executed as a normal user. It displays complete user information, such as terminal, time, date, system restart or start, and kernel version. This is a practical command for troubleshooting.
- # Last
-
- Tecmint pts/1 192.168.50.1 Tue Sep 18 08:50 still logged in
- Tecmint 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)
- Root pts/1 192.168.50.1 Sun Sep 16-down)
- Root pts/0: 0.0 Sun Sep 16)
- Root tty1: 0 Sun Sep 16-down)
- Reboot system boot 2.6.32-279. el6. I Sun Sep 16)
- Narad pts/2 192.168.50.1 Thu Sep 13-down)
You can use a last with a user name to learn about the activities of a specific user, as shown below.
- # Last tecmint
-
- Tecmint pts/1 192.168.50.1 Tue Sep 18 08:50 still logged in
- Tecmint pts/0 192.168.50.1 Tue Sep 18 07:59 still logged in
- Tecmint pts/1 192.168.50.1 Thu Sep 13-down)
- Tecmint pts/4 192.168.50.1 Wed Sep 12)
27. ps command
The ps command displays information about processes running in the system. The following example shows only the init process.
- # Ps-ef | grep init
-
- Root 1 0 0 07:53? 00:00:04/sbin/init
- Root 7508 6825 0 00:00:00 pts/1 grep init
28. kill command
Run the kill command to terminate the process. Use the ps command to find the process id, as shown below, and then run the kill-9 command to terminate the process.
- # Ps-ef | grep init
- Root 1 0 0 07:53? 00:00:04/sbin/init
- Root 7508 6825 0 00:00:00 pts/1 grep init
-
- # Kill-9 7508
29. rm command
The rm command is used to clear or delete files without prompting confirmation.
- # Rm filename
Use the-I option to confirm the deletion. Using the "-r" and "-f" options will forcibly delete the file and will not be confirmed.
- # Rm-I test.txt
-
- Rm: remove regular file 'test.txt '?
30. mkdir command
The mkdir command is used to create a directory in Linux.
- # Mkdir directoryname
This is a series of easy-to-use and practical basic commands in Linux/Unix operating systems. If you have missed some commands, please leave a message!
Original article title: 30 Useful Linux Commands for System Administrators, Author: Ravi Saive
This article permanently updates the link address: