30 Linux practical commands required by the system administrator

Source: Internet
Author: User
Tags file transfer protocol ssh example

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.

  1. # Uptime
  2. 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.

  1. [Tecmint @ tecmint ~] $ Uptime-V
  2. 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.

  1. # W
  2.  
  3. 08:27:44 up 34 min, 1 user, load average: 0.00, 0.00, 0.08
  4. User tty from login @ IDLE JCPU PCPU WHAT
  5. 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.

  1. # Users
  2. 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.

  1. # Who
  2. Tecmint pts/0 2012-09-18 07:59 (192.168.50.1)
  1. # W
  2.  
  3. 08:43:58 up 50 min, 1 user, load average: 0.64, 0.18, 0.06
  4. User tty from login @ IDLE JCPU PCPU WHAT
  5. 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.

  1. # Whoami
  2. Tecmint

6. ls command

The ls command displays the list of objects in human readable format.

  1. # Ls-l
  2.  
  3. Total 114
  4. Dr-xr-x. 2 root 4096 Sep 18 08:46 bin
  5. Dr-xr-x. 5 root 1024 Sep 8 :49 boot

Sort files by the last modification time.

  1. # Ls-ltr
  2.  
  3. Total 40
  4. -Rw-r --. 1 root 6546 Sep 17 install. log. syslog
  5. -Rw-r --. 1 root 22435 Sep 17 18:45 install. log
  6. -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.

  1. # Crontab-l
  2. 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.

  1. # 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.

  1. # Less install. log
  2.  
  3. Installing setup-2.8.14-10.el6.noarch
  4. Warning: setup-2.8.14-10.el6.noarch: Header V3 RSA/SHA256 Signature, key ID c105b9de: NOKEY
  5. Installing filesystem-2.4.30-2.1.el6.i686
  6. Installing ca-certificates-2010.63-3.el6.noarch
  7. Installing xml-common-0.6.3-32.el6.noarch
  8. Installing tzdata-2010l-1.el6.noarch
  9. 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.

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

10. cp command

Copy the file from the source to the destination and retain the same mode.

  1. # Cp-p fileA fileB

The system will prompt you before overwriting the file.

  1. # 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.

  1. # Mv-I fileA fileB

12. cat command

The cat command is used to view multiple files at the same time.

  1. # 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.

  1. # Cat install. log | less
  2.  
  3. # Cat install. log | more

13. cd command (Change directory)

With the cd command (Change directory), it will enter the fileA directory.

  1. # Cd/fileA

14. pwd command (output working directory)

The pwd command returns the current working directory.

  1. # Pwd
  2.  
  3. /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.

  1. # Sort fileA.txt
  2.  
  3. # 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.

  1. # 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 ).

  1. # Ssh narad@192.168.50.2

To check the ssh version, use option-V (uppercase) to display the ssh version.

  1. # Ssh-V
  2.  
  3. 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 ).

  1. # Ftp 192.168.50.2
  2.  
  3. # 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.

  1. # Ftp> mput *. txt
  2.  
  3. # 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.

  1. # Service httpd start
  2.  
  3. OR
  4.  
  5. #/Etc/init. d/httpd start

 

20. free command

The free command displays information about idle memory, total memory, and swap, in bytes.

  1. # Free
  2.  
  3. Total used free shared buffers cached
  4. Mem: 1030800 735944 294856 0 51648 547696
  5. -/+ Buffers/cache: 136600 894200
  6. Swap: 2064376 0 2064376

The free command using the-t option shows the total memory used and available memory, in bytes.

  1. # Free-t
  2. Total used free shared buffers cached
  3. Mem: 1030800 736096 294704 0 51720 547704
  4. -/+ Buffers/cache: 136672 894128
  5. Swap: 2064376 0 2064376
  6. 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.

  1. # Top-u tecmint
  2.  
  3. Top-11:13:11 up, 2 users, load average: 0.00, 0.00, 0.00
  4. Task: 116 total, 1 running, 115 sleeping, 0 stopped, 0 zombie
  5. 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
  6. Mem: 1030800 k total, 736188 k used, 294612 k free, 51760 k buffers
  7. Swap: 2064376 k total, 0 k used, 2064376 k free, 547704 k cached
  8.  
  9. Pid user pr ni virt res shr s % CPU % mem time + COMMAND
  10. 1889 tecmint 20 0 11468 1648 S 920 0.0. 59 sshd
  11. 1890 tecmint 20 0 5124 1668 S 1416 0.0. 44 bash
  12. 6698 tecmint 20 0 11600 1668 S 924 0.0. 19 sshd
  13. 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.

  1. # Tar-cvf archive-name.tar/home

To decompress the tar compressed archive file, use the following options.

  1. # 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.

  1. # Grep tecmint/etc/passwd
  2.  
  3. 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.

  1. # Find/-name tecmint
  2.  
  3. /Var/spool/mail/tecmint
  4. /Home/tecmint
  5. /Root/home/tecmint

25. lsof command

Lsof means "listing all open files ". The following lsof command lists all files opened by the tecmint user.

  1. # Lsof-u tecmint
  2.  
  3. Command pid user fd type device size/OFF NODE NAME
  4. Sshd 1889 tecmint cwd DIR 253,0 4096 2/
  5. Sshd 1889 tecmint txt REG 253,0 532336 298069/usr/sbin/sshd
  6. Sshd 1889 tecmint del reg 412940, 0/lib/libcom_err.so.2.1
  7. Sshd 1889 tecmint del reg 253,0 393156/lib/ld-2.12.so
  8. Sshd 1889 tecmint del reg 253,0 298643/usr/lib/libcrypto. so.1.0.0
  9. Sshd 1889 tecmint del reg 253,0 393173/lib/libnsl-2.12.so
  10. Sshd 1889 tecmint del reg 253,0 412937/lib/libkrb5support. so.0.1
  11. 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.

  1. # Last
  2.  
  3. Tecmint pts/1 192.168.50.1 Tue Sep 18 08:50 still logged in
  4. Tecmint pts/0 192.168.50.1 Tue Sep 18 07:59 still logged in
  5. Reboot system boot 2.6.32-279. el6. I Tue Sep 18)
  6. Root pts/1 192.168.50.1 Sun Sep 16-down)
  7. Root pts/0: 0.0 Sun Sep 16)
  8. Root tty1: 0 Sun Sep 16-down)
  9. Reboot system boot 2.6.32-279. el6. I Sun Sep 16)
  10. 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.

  1. # Last tecmint
  2.  
  3. Tecmint pts/1 192.168.50.1 Tue Sep 18 08:50 still logged in
  4. Tecmint pts/0 192.168.50.1 Tue Sep 18 07:59 still logged in
  5. Tecmint pts/1 192.168.50.1 Thu Sep 13-down)
  6. 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.

  1. # Ps-ef | grep init
  2.  
  3. Root 1 0 0 07:53? 00:00:04/sbin/init
  4. 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.

  1. # Ps-ef | grep init
  2. Root 1 0 0 07:53? 00:00:04/sbin/init
  3. Root 7508 6825 0 00:00:00 pts/1 grep init
  4.  
  5. # Kill-9 7508

29. rm command

The rm command is used to clear or delete files without prompting confirmation.

  1. # 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.

  1. # Rm-I test.txt
  2.  
  3. Rm: remove regular file 'test.txt '?

30. mkdir command

The mkdir command is used to create a directory in Linux.

  1. # 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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.