Shell Command Collection

Source: Internet
Author: User
Tags create directory echo command parent directory readable touch command word wrap disk usage

C
Cat Zdd Browse the contents of a ZDD file
Cat Zdd1 Zdd2 Browsing the contents of multiple files
Cat-n ZDD Browse the contents of a file Zdd and display line numbers

CD back to the start directory, that is, just logged into the system directory, CD behind no parameters
CD/back to the root directory
Cd.. Return to the top level directory

CD-Return to the most recently used directory

D
Df-kh Viewing disk information

Du-sh FolderName View the folder size,-H indicates the size of the display in human readable format,-s means the size of each file is accumulated.

H
History Show Command Chronicle
Hostname Displays the host name of the current login

L

Ls-al lists complete information for all files, one file per line

Ls-tl sort by last modified time

Ls-ul sort by last access time

Ls-r files and folders in the recursive reality subdirectory, this command can be easily implemented with grep, such as locating files in the current directory and subdirectories Zdd,ls-r | grep ZDD

Ls-f | grep/List Directory only

Less split screen displays the file, press the space down, and use the up and down arrows to look back and forth. Press the Q key to exit.

M

More split screen display file, press space down to view, do not support back to see, press the Q key to exit.
Man ls to view the help of LS command if help has multiple pages
Space PAGE Down
b PAGE Up
Q Exit Help

O

OD View the ASCII encoding of the file.

P
PWD Displays the current directory
PS Lists the current user's processes
PS-EF list all processes with full information

R
RM-RF zdd Delete the directory Zdd and its subdirectories, even if the directory is not empty
RM-RF zdd/* Delete all content under directory ZDD, but do not delete zdd itself
RM-RF * Delete all the files in the current directory, including the sub-file plus the file,-R for recursion,-F for forced deletion, do not ask.
RmDir zdd Delete Empty directory Zdd
mkdir zdd Creating a directory Zdd

S
Set View defined variables
SSH hostname Login to hostname

T
tar [option] File or dir
TAR-XVF Zdd.tar will Zdd.tar decompression, extract will generate Zdd folder, which contains the extracted files X means decompression, v means the output decompression information, f means the operation of ordinary files
TAR-CVF Tmp.tar TMP Packages the folder TMP into Tmp.tar
TAR-RVF Tmp.tar zzz Appends the file zzz to the Tmp.tar

Type XXX to view the path where xxx is located. What's the difference from Which?

Touch command
Touch [ACM]-T time file
This command is used to modify the file time, a-access times, m-modification c-do not the Create if file not exists
If you do not specify a time, the current system time is used, and if the file does not exist and the-C is not specified, a new file is created. You can use this method to quickly create a file. The format of time is as follows
[[Cc]yy] mmddhhmm[. SS]
Touch ABC if file ABC exists, then update its time to the current time, otherwise create it
Touch Abc-a-T
TOUCH-M-T 201101230621 ABC

W
Who see who has logged into the system

Who am I view my account information

Which LS to see the path where the LS program is located.

Z
Zip compression
Zip [options] Dest_files source
ZIP-R9 ~/zdd/home/zdd/* compresses all files under directory/home/zdd and puts them in the current directory named ZDD. -R represents a recursive processing of files in a folder, and 9 represents the maximum compression rate.

Unzip decompression
unzip-d ~/zdd Zdd.zip extracts the zdd.zip into the ZDD directory under the current directory, and-D indicates the directory to be unzipped.

Gzip Compression/Decompression
Gzip-d error_log.gz will error_log.gz decompression,-D for decompression, after decompression error_log.gz will no longer exist.


Other
Turn the page on the Terminal (Putty window can also)
Page UP Shift+pageup
Page DOWN Shift+pagedown

---------------------------------------------explain------------------------------

1 , ls: similar to the dir command under DOS

LS The most commonly used parameters are three:-a-l-F.

Ls–a

Files on Linux are treated as hidden files by the system, and only the LS command is not visible to them, and the hidden file is displayed with Ls-a in addition to the generic file name.

Ls–l

This parameter displays more detailed file information.

Ls–f

Using this parameter means adding more symbols for the file type after the file, such as * for the executable,/for the directory, and @ for the Nexus file, because the-f parameter is used. But now basically all Linux distributions of LS have built-in the-f parameter, that is, we can see a variety of resolution symbols without entering this parameter.

2 , CD: used to switch user's current working directory

CD AAA into AAA directory

Do not specify a directory after the CD command, will switch to the current user's home directory

CD ~ function with CD after not specifying directory, switch to current user's home directory

CD-command followed by a minus sign, it will be returned to the pre-switch directory

Cd.. Return to the top level directory in the current directory

3 , pwd : Used to display the user's current working directory

4 , mkdir and the rmdir

Midir: Create directory rmdir: Delete directory

Two commands support the-p parameter, and for the mkdir command, if the parent directory of the specified path does not exist, it is created, for the rmdir command to delete all hierarchical directories of the specified path, if there is content in the folder, you cannot use the rmdir command

As follows:

Mkdir-p 1/2/3

Rmdir-p 1/2/3

5 , CP : Copy command

Copy one file to another directory: CP 1.txt.. /test2

Copy a file to this directory and rename it: CP 1.txt 2.txt

Copy a folder A and rename it to b:cp-r a B

6 , MV: Move command

Move one file to another directory: MV 1.txt. /test1

Renaming a file in this directory: MV 1.txt 2.txt

Make sure one file is renamed to another directory: MV 1.txt. /test1/2.txt

7 , RM command

The RM command is used to delete a file, similar to the Del/erase command under DOS, with three parameters commonly used by RM commands:-i,-r,-f.

–i: The system will ask for confirmation before deleting the file, and the file will be deleted after the user returns. It is important to note that files deleted under Linux cannot be recovered and must be carefully confirmed before deletion.

–R: This parameter supports directory deletion and features similar to RMDIR commands.

–f: Instead of the-I parameter,-f means force delete

8 , du, df command

The du command can display the disk space occupied by the current directory, and the DF command can display the current disk's remaining space.

If the du command does not add any parameters, then the entire disk usage is returned, and if the directory is appended to it, the directory is used on disk.

DU-HS the specified directory to see the total size of the specified directory

Du-hs./* View the size of all folders and files in the current directory

Both commands support the-K,-M and-h parameters, which are similar to-K and-M, both representing display units, one for the K-byte and one for megabytes, and-H for Human-readable, which is a friendly, readable display.

9 , Cat Command

The function of the cat command is to display or link to a generic ASCII text file. Cat is a shorthand for concatenate, similar to the Type command under DOS. Use the following:

Cat file1 display file1 file contents

Cat file1 file2 Display the contents of File1,file2 in turn

Cat file1 file2 > File3 Combine the contents of File1, File2, and then redirect (>) to file3 files.

The ">" is the right redirect, indicating that the left command result is the input to the right command, note: If the file on the right is an existing file, the original content will be emptied, and the output of the left command can be changed. If you want to write in append mode, use the >> redirect instead.

If the ">" left no file specified, such as: Cat >file1, will wait for user input, after the input is completed and then press [Ctrl]+[c] or [ctrl]+[d], the user's input will be written to File1.

Ten , Echo Command

The echo command is used less often than LS and cat, especially in shell scripting.

syntax : echo [-ne][string]

function : Echo will send the input string to standard output, the output string is separated by white space characters, and at the end with a newline character.

Parameters :

-N Displays the string when the last word wrap

-E supports escape characters in the following format, and-E does not support escape characters in the following format

/A warns the sound of the alarm;

/b deletes the previous character;

/C finally does not add the line break symbol;

/F Wraps But the cursor remains in its original position;

/n Wraps and the cursor moves to the beginning of the line;

/r cursor moves to the beginning of the line, but does not wrap;

/t Insert tab;

/V same AS/F;

Insert/character;

/NNN inserts the ASCII character represented by the NNN (octal);

Example :

[Email protected]:~/hgd> echo "123" "456"

123 456

[Email protected]:~/hgd> echo "123/n456"

123/n456

[Email protected]:~/hgd> echo-e "123/n456"

123

456

[Email protected]:~/hgd> echo-e "123/n456"

123/n456

[Email protected]:~/hgd> echo-e "123///456"

123//456

[Email protected]:~/hgd> echo-e "123///456"

123/456

[Email protected]:~/hgd> echo-e "123/100456"

[Email protected]

Precautions:

Under the bash used by Linux, single quotes ' and double quotes are distinguished, single quotes Ignore all escapes, and double quotes do not omit the following special characters:

Dollar signs ($), back quotes ('), backslashes (/), Excalmatory mark (!)

Examples are as follows:

[Email protected]:~> echo "' TEST '"

-bash:test:command not found

[Email protected]:~> echo ' TEST '

' TEST '

[Email protected]:~> echo "$TEST"

[Email protected]:~> echo ' $TEST '

$TEST

[Email protected]:~> echo "//test"

/test

[Email protected]:~> echo '//test '

TEST

[Email protected]:~> echo "hello!"

echo "Hello"

Hello

[Email protected]:~> echo ' hello! '

Hello!

One , More , Less , Clear

N more,less Command

These two commands are used to view the file, and if a file is too long to display more than one screen, only the last content can be seen with the cat command, and the more and less two commands are paginated. The more command allows more than one page of the content of the file to pause the display, the user button before continuing to display the next page. and less in addition to more features, you can also use the arrow keys to scroll up or down the file, more convenient to browse and read.

Less common action commands for :

The ENTER key moves down one line;

Y move up one line;

The space bar scrolls down one screen;

b scroll up one screen;

D scroll down half screen;

H less's help;

U move up the half screen;

W can specify which line to start displaying, which is displayed from the next line of the specified number, for example, 6, which is displayed from line 7th;

G jumps to the first line;

G jumps to the last line;

P n% jumps to n%, such as 10%, which means that it starts at 10% of the entire file content;

/pattern searches for pattern, such as/mail, to search for mail words in a file;

V Call VI Editor;

Q Exit Less

!command Call the shell, you can run the command, such as!ls display the current column in the current directory of all files;

N Clear Command

The clear command is used to clear the current screen, without any parameters, and with the same functionality as CLS commands under DOS.

A , Head , Tail

The n head and tail commands are used to view the text file, except that the head displays the first n rows of the file, tail displays the end n rows of the file, and the default n is 10 rows. You can specify the number of rows by the-n method, such as:

head-100 file and tail-100 files indicate the contents of the header 100 lines and the end 100 lines respectively.

N tail-f command to see what's new in real time.

- , WC Command

This command is used to count the number of bytes, words, and lines in the specified file. The command options have the following meanings:

-L count rows

-W Count Count

-C Statistics byte number

These options can be used in combination. The order and number of output columns are not affected by the order and number of options. Always appear in the following order and at most one column per item.

Number of rows, words, bytes, filenames

If there is no file name in the command line, the file name does not appear in the output.

For example:

[Email protected]:~> WC 1.txt 2.txt

460 1679 16353 1.txt

1095 10665 2.txt

760 2774 27018 Total dosage

[Email protected]:~> wc-l 1.txt

460 1.txt

The default parameter is-LCW, which means that the WC file1 file2 command performs the same as above.

- , grep Command

grep is (global search regular expression (RE) and print out of the line abbreviation, used to search from the file surface containing the specified pattern of lines and print out, it is a powerful text search tool, support the use of regular expressions to search for text. grep works in such a way that it searches for a string template in one or more files. If the template includes spaces, it must be referred to, and all strings after the template are treated as filenames. The search results are sent to the screen without affecting the contents of the original file.

grep can be used for Shell scripting, because grep describes the status of the search by returning a status value, or 0 if the template search succeeds, or 1 if the search is unsuccessful, or 2 if the searched file does not exist. We can use these return values to do some automated text processing work.

Example :

$ ls-l | grep ' ^a '

Filters the contents of the Ls-l output through a pipeline, displaying only the lines that begin with a.

$ grep ' test ' d*

Displays all rows that contain test in a file that begins with D.

$ grep ' test ' AA bb cc

Displays the line that matches test in the aa,bb,cc file.

$ grep ' [a-z]/{5/} ' AA

Displays all rows that contain a string of at least 5 consecutive lowercase characters for each string.

$ Grep ' w/(es/) T.*/1 ' AA

If West is matched, es is stored in memory, labeled 1, and then searched for any character (. *) followed by another ES (/1), which is found to display the line. If you use Egrep or GREP-E, do not use the "/" number to escape, directly written as ' W (es) T.*/1 ' on it.

the , Mans , Logout Command

Mans Command

Man is the abbreviation of manual, the equivalent of Unix/linux online Help, each system command and invocation have a very detailed description, most of them are in English. such as: Man LS is to view the use of the LS command instructions, there is generally another way to see help, such as: Ls–help, this way most of the commands are supported.

Logout Command

This command exits the system and corresponds to the login command.

- , pipelines, and Xargs
Pipeline:  

Using the pipe symbol "|" provided by Linux Separates the two commands, and the output from the left command of the pipe character is entered as the command to the right of the pipe. Continuous use of the pipe means that the output of the first command will be entered as the second command, and the output of the second command will be entered as the third command, and so on.

Note: The input of the pipeline left command is the input to the right command of the pipeline (the input of the command is certain), not the parameter, and not all of the commands support the pipeline

Example: LS | grep a view the file or folder with a name in the current directory

Xargs :

Most Linux commands produce output: A list of files, a list of strings, and so on. But what if you want to use one of the other commands and take the output of the previous command as a parameter? For example, the file command displays the types of files (executables, ASCII text, and so on); You can process the output so that it shows only the file name, and you now want to pass these names to the Ls-l command to see the timestamp. The Xargs command is used to do the work.
Note: The find command passes the matched file to the Xargs command, and the Xargs command takes only a subset of the files at a time instead of all, unlike the-exec option. So it can process the first part of the file, then the next batch, and so on.

Example:

1. Find the Memory information dump file (core dump) throughout the system and save the results to the/tmp/core.log file:

$ find/-name "core"-print | Xargs echo "" >/tmp/core.log

2, when a directory file too much, directly with the RM * command will be too long, the following method can be deleted all

$ls | Xargs RM

- , basename and the dirname

BaseName is used to view the file without the name of the path, dirname is used to view the file path, using the effect of our test to know:

> Basename/home/hj/1.txt

1.txt

> Dirname/home/hj/1.txt

/home/hj

> basename 1.txt

1.txt

> DirName 1.txt

.

18. The set command without any parameters will show all the variables of the shell

Shell Command Collection

Related Article

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.