Summary of common Linux commands

1, Document management

1. ls command – displays the content and attribute information under the specified working directory

Options and parameters:

  • -a: All files are listed together with hidden files (files starting with). Commonly used)
  • -d: List only the directory itself, not the file data in the directory (common)
  • -l: Long data string listing, including file attributes, permissions and other data; (common)
[root@www ~]# ls -al ~

2. cp command – copy files or directories

Options and parameters:

  • -a: Equivalent to - pdr. For pdr, please refer to the following instructions; (common)
  • -i: If the destination file already exists, you will first ask about the progress of the action (commonly used) when overwriting
  • -p: Copy it together with the attributes of the file instead of using the default attributes (commonly used for backup);
  • -r: Recursive continuous replication is used for directory replication behavior; (common)
[root@www ~]# cp [-adfilprsu] source destination
[root@www ~]# cp [options] source1 source2 source3 .... directory

[root@www ~]# cp ~/.bashrc /tmp/bashrc
[root@www ~]# cp -i ~/.bashrc /tmp/bashrc
cp: overwrite `/tmp/bashrc'? n  <==n Not covered, y For coverage

3. mkdir command – create directory

Options and parameters:

  • -m: Permissions for configuration files
  • -p: Recursively create the required directory (including the upper level directory)
mkdir [-mp] Directory name

[root@www tmp]# mkdir -m 711 test2

#Use the mkdir command to create the runoob directory
[root@www ~]# mkdir runoob

4. mv command – move or rename files

Options and parameters:

  • -f: force means to ignore nonexistent files and no warning message will appear;
  • -i: In interactive mode, the user will be asked whether to move before deletion
  • -r: Recursive deletion

5. pwd command – displays the current path

Options and parameters:

  • -P: Show the exact path instead of using the link path.
[root@www ~]# pwd [-P]

6. yum command – RPM based package manager

Automatically search for the fastest image plug-in:
[root@linuxcool ~]# yum install yum-fastestmirror

install yum Graphics plug-in window:
[root@linuxcool ~]# yum install yumex

Clear the software package in the cache directory:
[root@linuxcool ~]# yum clean packages

uninstall/delete vim-common: 
[root@linuxcool ~]# yum remove vim-common.x86_64  

List matches to“ foo*"Available packets:
[root@linuxcool ~]# yum list available 'foo*' 

install yum Graphics window plug-in:
[root@linuxcool ~]# yum install yumex  

7. tar command – archive tool for packaging and backup

Parameter options:

  • -z compress / decompress the file through gzip instruction, preferably * tar.gz
  • -c create a new backup file
  • -F < backup file > specify backup file
  • -x extract files from archive
Will all.jpg Type the file into a file named all.tar Package:
[root@linuxcool ~]# tar -cf all.tar *.jpg

Delete the source file after packaging the file:
[root@linuxcool ~]# tar -cvf linuxcool.tar linuxcool --remove-files

After the file is packaged, the gzip Compression:
[root@linuxcool ~]# tar -zcvf log.tar.gz linuxcool.log

8. tgz command – compresses files into tgz format file

take/root/install.log File compressed to/root/install.log.tgz
[root@linuxcool ~]# tgz /root/install.log.tgz /root/install.log

2, Document editing

9. cat command – displays the contents of the file on the terminal device

To view the contents of a file:
[root@linuxcool ~]# cat filename.txt

View the contents of the file and display the number of lines:
[root@linuxcool ~]# cat -n filename.txt

View the contents of the file, add the line number and output it to another file:
[root@linuxcool ~]# cat -n linuxcool.log > linuxprobe.log 

Empty the contents of the file:
[root@linuxcool ~]# cat /dev/null > /root/filename.txt

Continue to write the contents of the file, encounter EOF End and save after:
[root@linuxcool ~]# cat > filename.txt <<EOF
> Hello, World 
> Linux!

To make a floppy disk device into an image file:
[root@linuxcool ~]# cat /dev/fd0 > fdisk.iso

10. tac command – reverse listing of file contents

[root@linuxcool ~]# cat test.txt 
hello world
hello linuxcool
hello linuxprobe

[root@linuxcool ~]# tac test.txt 
hello linuxprobe
hello linuxcool
hello world

11. echo command – outputs a string or extracts the value of a Shell variable

Output a string:
[root@linuxcool ~]#  echo "" 

Output variable extracted value:
[root@linuxcool ~]# echo $PATH

Escape the content and don't let $The function of extracting variable value of symbol takes effect:
[root@linuxcool ~]# echo \$PATH

Import the string information into the file in combination with the output redirection character:
[root@linuxcool ~]# echo "It is a test" > linuxcool

12. rm command – remove files or directories

Common parameters:

  • -f ignore nonexistent files and no warning message will appear
  • -i before deleting, the user will be asked whether to operate
  • -r/R recursive deletion
  • -v displays the detailed execution process of the instruction
Ask for confirmation one by one before deleting:
[root@linuxcool ~]# rm -i test.txt.bz2 
rm: remove regular file `test.txt.bz2'? 

Delete directly without any prompt:
[root@linuxcool ~]# rm -f test.txt.bz2  

Recursively delete the directory and all files under it:
[root@linuxcool ~]# mkdir /data/log
[root@linuxcool ~]# rm -rf /data/log

Delete all files in the current directory:
[root@linuxcool ~]# rm -rf *

Empty all files in the system (caution):
[root@linuxcool ~]# rm -rf /*

13. tail command – view the contents at the end of the file

Display file file Last 10 lines of:
[root@linuxcool ~ ]  tail file

Display file file From line 20 to the end of the file:
[root@linuxcool ~ ]  tail +20 file 

Display file file Last 10 characters of:
[root@linuxcool ~ ]  tail -c 10 file 

Files that change all the time are always displayed in the last 10 lines:
[root@linuxcool ~ ]  tail -f 10 file

14. grep command – powerful text search tool

Support multi file query and wildcard:
[root@linuxcool ~]# grep zwx file_* /etc/hosts
file_4:zwx djfkdjf

15. rgrep command – find the strings that match the conditions in the file

Find the sentence containing in the current directory Hello"String file:

[root@linuxcool ~]# rgrep Hello *  
Displays a description of the template style and example:

[root@linuxcool ~]# rgrep -?  

16. sdiff command – merges differences between files side by side

Compare the differences between the two files:
[root@linuxcool ~]# sdiff -a file1 file2

Ignore case differences:
[root@linuxcool ~]# sdiff -i file1 file2

Ignore any differences caused by blank lines:
[root@linuxcool ~]# sdiff -B file1 file2

17. vi command – text editor

use vi Editor:
[root@linuxcool ~]# vi

Edit the specified file:
[root@linuxcool ~]# vi linuxcool.log

Edit the specified file from line 6:
[root@linuxcool ~]# vi +6 linuxcool.log

Open the specified file in read-only mode:
[root@linuxcool ~]# vi -R linuxcool.log 

18. head command – displays the beginning of the file

Display the contents of the first 3 lines of files:

[root@linuxcool ~]# head -n 3 install.log
Installing libgcc-4.4.7-23.el6.x86_64
warning: libgcc-4.4.7-23.el6.x86_64: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
Installing setup-2.8.14-23.el6.noarch

Displays the file name information and the first two lines of the file:
[root@linuxcool ~]# head -v -n 2 test.txt 
==> test.txt <==
hello world
hello linuxcool

19. look command – query words

query file File with L First line:

[root@linuxcool ~]# cat file 
 Linux is a free unix-type opterating system.  
 This is a linux testfile!  
 Linux test 
[root@linuxcool ~]# look L file
 Linux is a free unix-type opterating system. 

3, Disk management

20. df command – displays disk space usage

Common parameters:

  • -a displays all system files
  • -B < block size > specifies the block size when displayed
  • -h is displayed in an easy to read manner
  • -H is displayed in 1000 bytes
  • -i display index byte information
  • -k specifies that the block size is 1KB
  • -l show only local file systems
Display disk partition usage:

[root@linuxcool ~]# df
 file system                             1K-block    Used     Available used% Mount point
devtmpfs                           1980612       0  1980612    0% /dev
tmpfs                              1994756       0  1994756    0% /dev/shm
tmpfs                              1994756    1040  1993716    1% /run

21. fdisk command - disk partition

Common parameters:

  • -b specify the size of each partition
  • -l list the partition table status of the specified peripheral devices
  • -s outputs the specified partition size to standard output in blocks
  • -The parameter list of "u collocation" - l "will replace the number of cylinders with the number of partitions to represent the starting address of each partition
  • -v display version information
View all partitions:
[root@linuxcool ~]# fdisk -l

Select partition disk:
[root@linuxcool ~]# fdisk /dev/sdb

Create an extended partition on the current disk:
[root@linuxcool ~]# fdisk /ext

Do not check the disk surface to speed up the partition operation:
[root@linuxcool ~]# fdisk /actok

4, System management

22. RPM command - RPM package manager

Direct installation package:

[root@linuxcool ~]# rpm -ivh packge.rpm 
Ignore the error message and force the installation:

[root@linuxcool ~]# rpm --force -ivh package.rpm
 List all installed packages:

[root@linuxcool ~]# rpm -qa
 query rpm Where files in the package are installed:

[root@linuxcool ~]# rpm -ql ls
 uninstall rpm Package:

[root@linuxcool ~]# rpm -e package.rpm 
Upgrade package:

[root@linuxcool ~]# rpm -U file.rpm

23. Find command – find and search files

Common parameters:

  • -Name find by name
  • -Size find by size
  • -user find by attribute
  • -Type find by type
  • -iname ignores case
use-name Parameter view/etc All under the directory.conf End profile:

[root@linuxcool ~]# find /etc -name "*.conf

use-size Parameter view/etc Greater than 1 under directory M File:

[root@linuxcool ~]# find /etc -size +1M

Find all files in the current user's home directory:

[root@linuxcool ~]# find $HOME -print

List all files and folders in the current directory and subdirectories:

[root@linuxcool ~]# find .

24. uname command - displays system information

Display system hostname, kernel version number CPU Type and other information:

[root@linuxcool ~]# uname -a
Linux linuxcool 3.10.0-123.el7.x86_64 #1 SMP Mon May 5 11:16:57 EDT 2014 x86_64 x86_64 x86_64 GNU/Linux

Display system hostname only:

[root@linuxcool ~]# uname -n

Displays the kernel version of the current system :

[root@linuxcool ~]# uname -r

Displays the hardware architecture of the current system:

[root@linuxcool ~]# uname -i

5, Network communication

25. ssh command - secure connection to the client

Log in to the remote server:

[root@linuxcool ~]# ssh

use test User connection to remote server:

[root@linuxcool ~]# ssh -l test

To view a list of partitions:

[root@linuxcool ~]# ssh /sbin/fdisk -l

Mandatory use ssh Protocol version 1:

[root@linuxcool ~]# ssh -1
Enable the connection forwarding function of authentication agent:

[root@linuxcool ~]# ssh -A

26. netstat command - displays the network status

Display detailed network status:

[root@linuxcool ~]# netstat -a

Display registered residence UDP Connection status:

[root@linuxcool ~]# netstat -nu

display UDP Port number usage:

[root@linuxcool ~]# netstat -apu 
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address  Foreign Address  State  PID/Program name    
udp        0      0*      4000/dhclient       
udp        0      0 localhost:323 *      3725/chronyd        
udp6       0      0 localhost:323           [::]:*         3725/chronyd 

Display network card list:

[root@linuxcool ~]# netstat -i 
Kernel Interface table 
eth0 1500   0  181864   0      0       0     141278   0     0     0    BMRU 
lo   16436  0   3362    0      0       0     3362     0     0     0    LRU

27. ping command - test the network connectivity between hosts

Detection and linuxcool Website connectivity:

[root@linuxcool ~]# ping
 continuity ping4 Times:

[root@linuxcool ~]# ping -c 4 
Set the number of times to 4 and the time interval to 3 seconds:

[root@linuxcool ~]# ping -c 4 -i 3
 utilize ping Command to get the name of the specified web site IP Address:

[root@linuxcool ~]# ping -c 1 | grep from | cut -d " " -f 4

28. ifconfig command - displays or sets network devices

Display network device information:

[root@linuxcool ~]# ifconfig

Start and close the specified network card:

[root@linuxcool ~]# ifconfig eth0 down
[root@linuxcool ~]# ifconfig eth0 up 

Configure and delete network cards IPv6 Address:

[root@linuxcool ~]# ifconfig eth0 add 33ffe:3240:800:1005::2/64
[root@linuxcool ~]# ifconfig eth0 del 33ffe:3240:800:1005::2/64

use ifconfig modify MAC Address:

[root@linuxcool ~]# ifconfig eth0 down
[root@linuxcool ~]# ifconfig eth0 hw ether 00:AA:BB:CC:DD:EE
[root@linuxcool ~]# ifconfig eth0 up
[root@linuxcool ~]# ifconfig eth1 hw ether 00:1D:1C:1D:1E 
[root@linuxcool ~]# ifconfig eth1 up

to configure IP Address:

[root@linuxcool ~]# ifconfig eth0 
[root@linuxcool ~]# ifconfig eth0 netmask
[root@linuxcool ~]# ifconfig eth0 netmask broadcast

6, File transfer

29. tftp command - upload and download files

Connect to remote server″: 

[root@linuxcool ~]# tftp 
Remote download file File:

tftp> get file                            
getting from to /dir  
Recived 168236 bytes in 1.5 seconds[112157 bit/s] 
sign out tftp: 

tftp> quit     

30. ftp who command - displays ftp session information

Query current login FTP Users of the server:

[root@linuxcool ~]# ftpwho

In detailed mode, query the current login FTP Users of the server:

[root@linuxcool ~]# ftpwho -v

Display help information:

[root@linuxcool ~]# ftpwho -h

7, Equipment management

31. Mount command - file system mount

View version:

[root@linuxcool ~]# mount -V

Start all mounts:

[root@linuxcool ~]# mount -a

mount  /dev/cdrom reach /mnt: 

[root@linuxcool ~]# mount /dev/cdrom /mnt

mount  nfs Format file system:

[root@linuxcool ~]# mount -t nfs /123 /mnt  

Mount the first partition of the first disk to/etc catalog:

[root@linuxcool ~]# mount -t ext4 -o loop,default /dev/sda1 /etc

8, Backup compression

32. zip command – compressed file

take /home/html/ All files and folders in this directory are packaged as files in the current directory 

[root@linuxcool ~]# zip -q -r /home/html

Compressed file Delete files from a.c: 

[root@linuxcool ~]# zip -dv a.c 

hold/home Under the directory mydata Directory compressed to 

[root@linuxcool ~]# zip -r mydata 

hold/home Under the directory abc Folders and 123.txt Compress into 

[root@linuxcool ~]# zip -r abc 123.txt 

take logs Catalog packaged as 

[root@linuxcool ~]# zip -r ./logs 

33. Unzip command – unzip the zip file

hold/home Under the directory Unzip to mydatabak In the directory:

[root@linuxcool ~]# unzip -d mydatabak 

hold/home Under the directory Extract directly to/home In the directory:

[root@linuxcool ~]# unzip 

hold/home Under the directory,, At the same time, unzip to/home In the directory:

[root@linuxcool ~]# unzip abc\*.zip 

verification/home Under the directory Completeness:

[root@linuxcool ~]# unzip -t  

34. gzip command – compress and unzip files

hold rancher-v2.2.0 Each file in the directory is compressed into.gz File:

[root@linuxcool ~]# gzip *
Unzip each compressed file in the above example and list the detailed information:

[root@linuxcool ~]# gzip -dv *
Extract the directory recursively:

[root@linuxcool ~]# gzip -dr rancher.gz

35. zipinfo command - view compressed file information

Display compressed file information:

[root@linuxcool ~]# zipinfo 
Archive:  486 bytes  3 files
-rw-r--r-- 2.3 unx    0 bx stor 24-May-10 18:54 a.c
-rw-r--r-- 2.3 unx    0 bx stor 24-May-10 18:54 b.c
-rw-r--r-- 2.3 unx    0 bx stor 24-May-10 18:54 c.c
3 files, 0 bytes uncompressed, 0 bytes compressed: 0.0%

Displays information for each file in the compressed file:

[root@linuxcool ~]# zipinfo -v 

Only the compressed package size and number of files are displayed:

[root@linuxcool ~]# zipinfo -h             
Zip file size: 907 bytes, number of entries: 3

9, Other commands

36. History command – display and manipulate history command

Show the last 10 commands:

[root@linuxcool ~]# history 10  

Write the login command to the history file:

[root@linuxcool ~]# history -w

37. Real time display of process commands

Display process information:

[root@linuxcool ~]# top

Display complete process information:

[root@linuxcool ~]# top -c

Display program information in batch mode:

[root@linuxcool ~]# top -b

38. free command - displays the system memory

Display memory usage:

[root@linuxcool ~]# free 

use MB Display memory usage:

[root@linuxcool ~]# free -m

use KB Display memory usage:

[root@linuxcool ~]# free -K

Display memory usage information in the form of sum:

[root@linuxcool ~]# free -t 

Periodically query memory usage:

[root@linuxcool ~]# free -s 10

39. vmstat command - displays the virtual memory status

Show active inner pages:

[root@linuxcool ~]# vmstat -a

Displays the total number of processes created since startup:

[root@linuxcool ~]# vmstat -f

40. mpstat command - displays the changed CPU data and performs monitoring

first CPU: 

[root@linuxcool ~]# mpstat -P 1

Perform monitoring all CPU: 

[root@linuxcool ~]# mpstat -P ALL 

41. iostat command – monitor the usage of system input and output devices and CPU

Report every two seconds:

[root@linuxcool ~]# iostat -d 2

Report every 2 seconds for 6 times:

[root@linuxcool ~]# iostat -d 2 6

42. Clear command - clear screen

43. printf command - shell output

[root@linuxcool ~]# printf "Hello, Shell\n" 
Hello, Shell 

44. watch command – execute the command periodically

Repeat execution uptime Command:

[root@linuxcool ~]# watch uptime

Highlight changes in the number of network links every second:

[root@linuxcool ~]# watch -n 1 -d netstat -ant

Output the average load of the system every 10 seconds:

[root@linuxcool ~]# watch -n 10 'cat /proc/loadavg'

Monitoring disk inode and block Number changes:

[root@linuxcool ~]# watch -n 1 "df -i;df"

45. Date command - displays the date and time

ant@ubuntu:~$ date
Thu Mar 10 04:02:41 PST 2022

46. export command - system settings

List all current environment variables:

[root@linuxcool ~]# export -p

Define environment variables:

[root@linuxcool ~]# export MYENV 

Define environment variable assignment:

[root@linuxcool ~]# export MYENV=7


47. chgrp command - change the file group

Parameter options:

-R: Recursively change the file group.

chgrp [-R] Group name file name

48. chown command – change the file owner or the file group at the same time

chown [–R] Owner name file name
chown [-R] Owner name: the name of the owner group and the file name

[root@www ~]# chown bin install.log

49. chmod command – change 9 attributes of the file

chmod [-R] xyz File or directory

[root@www ~]# chmod 777 .bashrc

50. rmdir command - delete empty directory

Options and parameters:

  • -p: From this directory, delete multi-level empty directories at one time
[root@www tmp]# rmdir weiixn/

51. cd command - switch directory

#Use the absolute path to switch to the runoob directory
[root@www ~]# cd /root/runoob/

#Switch to the runoob directory using a relative path
[root@www ~]# cd ./runoob/

#root directory
[root@www runoob]# cd ~

#Upper level directory
[root@www ~]# cd ..

52. Tree command – list the contents of the directory in a tree view

Show only n Layer directory( n (in numbers):

[root@linuxcool ~]# tree -L 2

Sort by the change time of files and directories:

 [root@linuxcool ~]# tree -t
Sort in reverse order:

[root@linuxcool ~]# tree -r

Before each file or directory, the complete relative path is displayed:

[root@linuxcool ~]# tree -f

Show directory only:

[root@linuxcool ~]# tree -d

Show all files and directories:

[root@linuxcool ~]# tree -a

Keywords: Linux Operation & Maintenance Operating System server

Added by campsoup1988 on Thu, 10 Mar 2022 14:20:20 +0200