I summed up the common Linux command , It's convenient for you Linux Use . Here's the format , You can skip it now , I'll check again until I have any questions .

$ Command line prompt

bold To express an order

Italics Said parameters

    filename, file1, file2  All file names . Sometimes the file name has a suffix , such as file.zip

    command  Command name

    dir  Folder name

    string  character string

    username  user name

    groupname  Group name

    regex  Regular expressions

    path  route

    device  Device name

    partition  Section name

    IP IP Address

    domain  domain name

    ID  Remote users ID

    host  Host name , It can be for IP Address or domain name

    var  Variable name

    value  A variable's value

 

Order help

$man command

Query command command Description document

    $man -k keyword

    Search keywords

$info command

More detailed documentation

$whatis command

Brief description

$which command

command Of binary File path

$whereis command

All... In the search path command

 

It's just command (binary file) For example . such as man It can also be used to query system functions 、 Configuration files, etc .

 

user

$finger username

Show users username Information about

$who

Display the current login user

    $who am I

    An interesting usage

$write username

Send a message to the user ( use EOF End input )

$su

Become root user

$sudo command

With root User identity execution

$passwd

Change password

 

SHELL (BASH)

$history

Show in the current shell Order history

$alias

Show all command nicknames

    $alias new_command='command'

    Will command command Don't call it new_command

$env

Show all environment variables

    $export var=value

     Set the environment variable var by value   

 

$expr 1 + 1

Calculation 1+1

 

file system

$du -sh dir

Folder size , -h A human readable unit , -s Show only summary

$find . -name filename

Starting from the current path , Look down for the file filename

$locate string

The search includes string The path of

    $updatedb

    And find Different ,locate It's not a real-time search . You need to update the database , To get the latest information .

$ln -s filename path

File for filename stay path Location creates soft links

$pwd

Show current path

    $cd path

    Change the current working path to path

    $cd -

    Change the current path to the previous path

 

file

$touch filename

If the file doesn't exist , Create a blank file ; If the file exists , Update file read and modify time .

$rm filename

Delete file

$cp file1 file2

Copy file1 by file2

$ls -l path

Display files and file related information

$mkdir dir

establish dir Folder

    $mkdir -p path

    Recursively create paths path All the folders on

    $rmdir dir

    Delete dir Folder ,dir Must be an empty folder .

    $rm -r dir

    Delete dir Folder , And all the files it contains

$file filename

file filename Type description of

$chown username:groupname filename

Change the ownership of the file to owner, Own group as group

$chmod 755 filename

Change file permissions to 755: owner r+w+x, group: r+x, others: r+x

 

$od -c filename

With ASCII Character display file

 

According to documents

$cat filename

Display file
    $cat file1 file2

    Connection display file1 and file2

$head -1 filename

Show the first line of the file

$tail -5 filename

Display the last five lines of the file

$diff file1 file2

Show file1 and file2 The difference between

$sort filename

Sort the lines in the file , And display

    $sort -f filename

    Sorting time , Regardless of case

    $sort -u filename

    Sort , And remove the duplicate lines

$uniq filename

Display file filename Lines that do not repeat in ( Same content , But not adjacent lines , It's not a repetition )

$wc filename

Count the characters in the file 、 Words and lines

    $wc -l filename

    Count the number of lines in the file

 

Text

$echo string

Show string

$echo string | cut -c5-7

Intercept the second part of the text 5 To the first 7 Column

$echo string | grep regex

Display contains regular expressions regex The line of

$echo string | grep -o regex

The display is regular regrex Substring of

 

Time and date

$date

Current date time

    $date +"%Y-%m-%d_%T"

    With YYYY-MM-DD_HH:MM:SS The date time is displayed in the format of ( The format can be referred to $man date)

    $date --date="1999-01-03 05:30:00" 100 days

    Show from 1900-01-03 05:30:00 backward 100 The date and time of the day

$sleep 300 

Sleep 300 second

 

process

$top

Show progress information , And update in real time

$ps

Show the current shell Under the process of

    $ps -lu username

    Show users username The process of

    $ps -ajx

    Show all processes in a more complete format

$kill PID

Kill PID process (PID by Process ID)

    $kill %job

    Kill job Work (job by job number)

$lsof -u username

user username The file opened by the process

$dmesg

Display system log

$time a.out

test a.out Running time of

 

Hardware

$uname -a

Display system information

$df -lh

Displays the usage of all hard disks

$mount

Display all hard disk partition mount

    $mount partition path

    Hang on partition To path path

    $umount partition

    uninstall partition

$sudo fdisk -l

Show all partitions

    $sudo fdisk device

    by device( such as /dev/sdc) Create a partition table . Enter and choose n, p, w

    $sudo mkfs -t ext3 partition

    format partition patition( such as /dev/sdc1)

    modify  /etc/fstab, To mount partitions automatically . Add rows :

    /dev/sdc1  path(mount point) ext3 defaults 0 0

$arch

Display Architecture

$cat /proc/cpuinfo

Show CPU Information

$cat /proc/meminfo

Display memory information

$free

Display memory usage

$pagesize

Display memory page size ( With KByte In units of )

 

The Internet

$ifconfig

Displays the network interface and the corresponding IP Address .ifconfig Can be used to set the network interface

    $ifup eth0

    function eth0 Interface

    $ifdown eth0

    close eth0 Interface

$iwconfig

Show the wireless network interface

$route

Show routing table .route It can also be used to modify routing tables

$netstat

Displays the current network connection status

$ping IP

send out ping Package to address IP

$traceroute IP

Probe to address IP The routing path of

$dhclient

towards DHCP Host send DHCP request , In order to obtain IP Addresses and other settings .

$host domain

DNS Inquire about , Looking for domain names domain Corresponding IP

    $host IP

     reverse DNS Inquire about

$wget url

Use wget download url Pointed resources

    $wget -m url 

    Image download

 

SSH Login and file transfer

$ssh ID@host

ssh Log in to the remote server host,ID Username .

$sftp ID@host

Login server host,ID Username .sftp After landing , You can use the following command to further operate :

    get filename    # Download the file

    put filename    # Upload files

    ls              # List host All files on the current path

    cd              # stay host Change current path on

    lls             # List all files with the current path on the local host

    lcd             # Change the current path on the local host

$scp localpath ID@host:path

Will local localpath The file pointed to is uploaded to the remote host path route

    $scp -r ID@site:path localpath

    With ssh agreement , Traverse Download path The entire file system under the path , To the local localpath

 

Compression and archiving

$zip file.zip file1 file2

take file1 and file2 Compress to file.zip

$unzip file.zip

decompression file.zip

 

$gzip -c filename > file.gz

Will file filename Compress to file.gz

$gunzip file.gz

decompression file.gz file

 

$tar -cf file.tar file1 file2

establish tar file

    $tar -zcvf file.tar file1 file2

    establish tar file , And compress

    $tar -xf file.tar

    Release tar file

    $tar -zxf file.tar.gz

    Decompress and release tar file

 

Print

$lpr filename

Print documents

$lpstat

Shows the status of all printers