This article describes some useful and common Linux or UNIX commands that are commonly used by Linux system administrators. Instead of a complete list, this article briefly lists the commands that come in handy when needed, starting with an example of how to use these commands.
1.uptime command
In Linux, the uptime command shows how long your system has been running and how many users are currently logged on, plus a load average of 1 minutes, 5 minutes, and 15 minutes.
# uptime 08:16:26 up min, 1 user, load average:0.00, 0.03, 0.22
Check the uptime version
In addition to uptime (uptime) and version (versions), the Uptime command has no other options. If the time is less than 1 days, it only gives information hours:mins this form.
[Email protected] ~]$ uptime-v Procps version 3.2.8
2.w command
This command displays the currently logged on user and their processes, plus the load average. In addition, it shows the login name, TTY name, remote host, logon time, idle time, JCPU, PCPU, commands, and processes.
available Options- H: Does not display the caption. -S: jcpu and PCPU are not displayed. -F: Field information is not displayed. -V: (uppercase V)-Displays the version.
3.users Command
The users command shows the currently logged-on user, which has no additional parameters other than help and version.
# users Tecmint
4.who Command
The WHO command returns only the user name, date, time, and host information; The WHO command is similar to the W command, unlike the W command, who does not export the information that the user performs, it may be useful to look at the difference between the two commands of WHO and W.
# who tecmint pts/0 2010-09-18 07:59 (192.168.50.1)
The WHO command option- B: Displays the last system restart date and time. -R: Displays the current runlevel. -a,–all: Displays all accumulated information.
5.whoami Command
The WhoAmI command outputs the current user's name; You can also use the "Who am I" command to display the current user, if you log in as root user using the sudo command, the "WhoAmI" command returns the root user is the current user, if you want to know specifically which user is logged in, use "Who Am I" Command.
# WhoAmI Tecmint
6.ls Command
The LS command displays a list of files in human readable format.
# ls-l Total dr-xr-xr-x. 2 root root 4096 Sep 08:46 bin Dr-xr-xr-x. 5 root root Sep 8 15:49 boot
Sorts the files according to the last modification time.
# ls-ltr Total 40-rw-r--r--. 1 root root 6546 Sep 18:42 install.log.syslog-rw-r--r--. 1 root root 22435 Sep 18:45 install.log-rw-------. 1 root root 1003 Sep 18:45 anaconda-ks.cfg
7.crontab Command
You can use the crontab command and the-l option to list the current user's scheduled tasks.
# crontab-l * * */bin/ls >/ls.txt
You can use the-e option to edit crontab, in the following example, you will use the VI Editing tool to open the scheduled task, make the necessary changes, press: Wq key to exit, this will automatically save the settings.
# CRONTAB-E
8.less Command
The less command allows you to quickly view the file; You can page 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 nstalling tzdata-2010l-1.el6.noarch Installing Iso-codes-3.16-2.el6.noarch
9.more Command
The more command allows you to quickly view the file and display details as a percentage, you can page 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
Copies files from the source to the destination, preserving the same pattern.
# cp-p FileA Fileb
The system will prompt you before overwriting the file.
# cp-i FileA Fileb
11.MV Command
Rename Filea to Fileb; the-i option will prompt before overwriting, and if the file already exists, it will be required to be confirmed.
# mv-i FileA Fileb
12.cat Command
The cat command is used to view multiple files simultaneously.
# Cat FileA Fileb
If a file cannot be displayed on a screen/page, you can use the Cat command to combine the more and less commands to view the contents of the file.
# Cat Install.log | Less or# cat Install.log |
13.cd command (switch directory)
With the CD command (switch directory), it goes to the Filea directory.
# Cd/filea
14.pwd command (output working directory)
The PWD command returns the current working directory.
# Pwd/root
15.sort Command
Sorts a row of text files in ascending order, and if you use the-r option, it is 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, open a read-only file, press ": Q" to exit the VI window.
# Vi-r/etc/shadows
17.ssh command (Secure Shell)
The SSH command is used to log in to the remote host, for example, the following SSH example uses the user as a narad to connect to the host (192.168.50.2).
# SSH [email protected]
To check the version of SSH, use the option-V (uppercase) to display the version of SSH.
# SSH-VOPENSSH_5.3P1, OpenSSL 1.0.0-fips 2010
18.ftp or SFTP Command
FTP or SFTP commands are used to connect to remote FTP hosts, FTP refers to file transfer protocols, and SFTP is a 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 a remote host.
# FTP > Mput *.txt# ftp > Mget *.txt
19.service Command
The service command invokes the script located at 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 the services named httpd.
# service httpd start#/etc/init.d/httpd start
20.free Command
The free command displays information about idle memory, total memory, and intra-swap, in bytes.
# free Total used free shared buffers cached mem:1030800 735944 29 4856 0 51648 547696-/+ buffers/cache:136600 894200 swap:2064376 0 2064376
The free command with the-t option shows the total memory used and the memory that can be used, 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:30951 76 736096 2359080
21.top Command
The top command shows the processor activity of the system, and also shows the tasks managed by the kernel in real time, which shows the processor and memory used, and if you use the top command with the "u" option, this displays the specific user process details, as follows: Press "O" (uppercase) to sort the way you want, press "Q" To exit the top screen.
# top-u TecmintTop-11:13:11 up 3:19, 2 users,Load average:0.00, 0.00, 0.00 tasks:116 Total, 1 running, 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, 294612kFree, 51760k buffers swap:2064376k total, 0k used, 2064376kfree, 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
22.tar Command
The tar command is used to compress files and folders under Linux; For example, the following command creates a compressed archive for the/home directory with the file name Archive-name.tar.
# TAR-CVF Archive-name.tar/home
To extract the Tar compressed archive file, use the options shown below.
# TAR-XVF Archive-name.tar
23.grep Command
grep searches for a specific string in the file; only the Tecmint user in the/etc/passwd file is displayed. We can use the-I option, ignoring case.
# grep TECMINT/ETC/PASSWD Tecmint:x:500:500::/home/tecmint:/bin/bash
24.find Command
The Find command searches 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 "list all open files"; below, the lsof command lists all files opened by tecmint users.
# 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 253,0 412940/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 253,0 412961/lib/libplc4.so
26.last Command
With the last command, we can observe the activity of the user in the system, which can also be performed as a normal user, which displays complete user information, such as terminal, time, date, system restart or boot, and kernel version, which is a useful command for troubleshooting.
# last tecmint pts/1 192.168.50.1 Tue Sep 08:50 still logged in tecmint pts/0 192.168.50.1 Tue Sep 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 10:40-down (03:53) root pts/0 : 0.0 Sun Sep 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 09:57-14:33 (04:35) Narad pts/2 192.168.50.1 Thu Sep 08:07-down
You can use the last with the user name to understand the activity of a specific user, as shown below.
# last Tecmint tecmint pts/1 192.168.50.1 Tue Sep-08:50 still logged in tecmint pts/0 192.168.50.1 Tue Sep 07:59 still logged in tecmint pts/1 192.168.50.1 Thu Sep 08:07-down (01:15) tecmint pts/4 192.168.50.1 Wed Sep 12 10:12-12:29
27.ps Command
The PS command displays information about the processes running in the system, and 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 11:48 pts/1 00:00:00 grep init
28.kill Command
Use the KILL command to end the process; Use the PS command to find the process ID, as shown below, and then use 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 11:48 pts/1 00:00:00 grep init# kill-9 7508
29.rm Command
The RM command is used to purge or delete files without prompting for confirmation.
# RM FileName
Use the-I option to confirm the deletion before deleting it, and use the "-R" and "-f" options to forcibly delete the file without confirming it.
# rm-i test.txtrm:remove regular file ' Test.txt '?
30.mkdir Command
The mkdir command is used to create directories under Linux.
# mkdir DirectoryName
This is similar to Linux/unix operating system under a series of easy-to-use, and very practical daily basic commands, if we miss out what orders, welcome message exchange!
This article was reproduced from:http://www.linuxprobe.com/most-practical-30-linux-command.html
more Linux Dry Goods visit:http://www.linuxprobe.com/
The most practical 30 Linux commands!