Shell Command collection and shell collection

Source: Internet
Author: User
Tags call shell touch command uncompress

Shell Command collection and shell collection

Shell is the interface between the user and the Linux operating system.

C
Cat zdd: View File zdd content
Cat zdd1 zdd2 browse the content of multiple files
Cat-n zdd: view the zdd content of the file and display the row number.

Cd is returned to the starting directory, that is, the directory you just logged on to the system. There is no parameter after cd.
Cd/return to the root directory
Cd .. back to the upper-level directory

Cd-Return to the recently used directory

D
Df-kh view disk Information

Run du-sh foldername to view the folder size.-h indicates that the folder size is displayed in the format of human readable, and-s indicates that the size of each file is accumulated.

H
History displays command history
Hostname: displays the Host Name of the current logon.

L

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

Ls-tl sort by last modification time

Ls-ul is sorted by the last access time

Ls-R recursive reality subdirectory files and folders. This command can be used with grep for convenient search, such as searching file zdd and ls-R in the current directory and subdirectory | grep zdd

Ls-F | grep/only lists Directories

The less split screen displays the file, and you can press the space to view it down, and use the up and down arrows to view it back and forth. Press q to exit.

M

More split screen display file, Press space to view down, do not support playback, press the q key to exit.
Man ls to view the help of the ls command, if there are multiple pages of help
Flip down by Space
B. Page up
Q exit help

O

Od to view the file's ASCII code.

P
Pwd displays the current directory
Ps: list processes of the current user
Ps-ef lists all processes with complete information

R
Rm-rf zdd: Delete the directory zdd and its subdirectories, even if the directory is not empty
Rm-rf zdd/* Delete all contents under the zdd directory, but do not delete zdd itself
Rm-rf * deletes all files in the current directory, including the files added to the sub-files and their files.-r indicates recursion, and-f indicates force deletion without asking.
Rmdir zdd Delete empty directory zdd
Mkdir zdd create directory zdd

S
Set to view Defined variables
Log on to the hostname Using ssh hostname.

T
Tar [option] file or dir
Tar-xvf zdd.tar decompress zdd.tar. After decompression, the zdd folder is generated, which contains the decompressed file x, which indicates decompression, v indicates output decompression information, and f indicates operations on common files.
Tar-cvf tmp.tar tmp pack the tmp.tar folder into tmp.tar
Tar-rvf tmp.tar zzz: add the file zzz to tmp.tar.

Type xxx: view the path of xxx. What is the difference between it and which?

Touch command
Touch [acm]-t time file
This command is used to modify the file time, a-access time, m-modification time c-do not create if file not exists
If no time is specified, the current system time is used. If the file does not exist and-c is not specified, a new file is created. You can use this method to quickly create a file. The time format is as follows:
[[CC] YY] MMDDhhmm [. SS]
Touch abc if the file abc exists, the update time is the current time; otherwise, it is created.
Touch abc-a-t
Touch-m-t 201101230621 abc

W
Who checks who has logged on to the system

Who am I view my account information

Which ls to view the path of the ls program.

Z
Zip Compression
Zip [options] dest_files source
Zip-r9 ~ /Zdd/home/zdd/* compresses all the files in the/home/zdd directory and puts them in the current directory named zdd. -R indicates recursive processing of files in folders, and 9 indicates the maximum compression rate.

Unzip
Unzip-d ~ /Zdd zdd.zip: Decompress zdd.zip to the zdd directory under the current directory.-d indicates that the directory to be extracted is specified.

Gzip compression/Decompression
Gzip-d error_log.gz uncompress error_log.gz, and -dump uncompress. After uncompress, error_log.gz no longer exists.

Others
Flip the page on the terminal (Putty window is also acceptable)
Shift + PageUp
Shift + PageDown

1,Ls:SimilarDosUnderDirCommand

The most common parameters of ls include-a-l-F.

Ls-

Linux Files. files starting with ls are regarded as hidden files and cannot be seen only by using ls commands. In addition to displaying common file names, ls-a can also display hidden files.

Ls-l

This parameter displays more detailed file information.

Ls-F

This parameter is used to add symbols of the file type after a file. For example, * Indicates executable,/indicates directory, and @ indicates link file, this is because the-F parameter is used. But now, basically all Linux releases have built-in the-F parameter for ls. That is to say, we can see all kinds of resolution symbols without entering this parameter.

 

2,Cd:Used to switch the current working directory of a user

Cd aaa enters the aaa directory

If the directory is not specified after the cd command, the current user's home directory will be switched.

Cd ~ Switch to the home Directory of the current user without specifying a directory after cd.

After the cd-command is followed by a minus sign, it is returned to the directory before the switch.

Cd .. return to the upper-level directory under the current directory

 

3,Pwd: Displays the current working directory of a user.

 

4,MkdirAndRmdir

Midir: create directory rmdir: delete directory

Both commands support the-p parameter. For the mkdir command, if the parent directory of the specified path does not exist, the mkdir command is created together. For the rmdir command, all levels of directories in the specified path are deleted. If the folder contains content, you cannot use the rmdir command.

As follows:

Mkdir-p 1/2/3

Rmdir-p 1/2/3

 

5,Cp: Copy command

Copy a file to another directory: cp 1.txt ../test2

Copy a file to the local directory and rename it: cp 1.txt 2.txt

Copy a folder and change it to B: cp-r a B

 

 

6Mv: Mobile Command

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

Rename a file in this directory: mv 1.txt 2.txt

Upload a file to another directory and rename it: mv 1.txt ../test1/2.txt

 

7, Rm command

The rm command is used to delete files. Similar to the del/erase command in dos, the common parameters of the rm command include-I,-r, and-f.

-I: before deleting a file, the system will first ask for confirmation. After you press enter, the file will be deleted. Note that files deleted in linux cannot be recovered. Therefore, be cautious when deleting files.

-R: This parameter supports directory deletion, which is similar to the rmdir command.

-F: opposite to the-I parameter.-f indicates force deletion.

 

8, Du, df command

The du command displays the disk space occupied by the current directory, and the df command displays the remaining disk space.

 

If the du command does not add any parameters, the system returns the usage of the entire disk. If a directory is added to the disk, the usage of the directory is used on the disk.

Du-hs specifies the directory to view 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. The-k and-m parameters are similar, indicating the display unit. One is k bytes and the other is MB, -h indicates human-readable, which is a user-friendly display mode.

 

9,CatCommand

The cat command is used to display or link common ascii text files. Cat is short for concatenate, similar to the type command under dos. The usage is as follows:

Cat file1: Display file1 File Content

Cat file1 file2 displays file1 and file2 in sequence

Cat file1 file2> file3 combines the content of file1 and file2, and then "Redirect (>)" to the file3 file.

">" Is the right redirection character, indicating that the result of the command on the left is used as the input of the command on the right. Note: if the file on the right is an existing file, its original content will be cleared, the left-side command output content. If you want to write data in append mode, use the ">" redirection character instead.

If no file is specified on the left, such as cat> file1, after the input is complete, press [Ctrl] + [c] or [Ctrl] + [d] to write the user's input content to file1.

 

10,EchoCommand

The frequency of Using echo commands is not less than ls and cat, especially in shell script writing.

Syntax: Echo [-ne] [String]

Function: Echo sends the input string to the standard output. The output string is separated by blank characters and a line break is added at the end.

Parameters:

-N: the last line break when the string is displayed

-E supports escape characters in the following formats.-E does not support escape characters in the following formats.

/A sends an alert;

/B. Delete the previous character;

/C does not end with a line break;

/F line feed, but the cursor remains at the original position;

/N wrap and move the cursor to the beginning of the line;

/R move the cursor to the beginning of the line without line breaks;

/T Insert the tab;

/V is the same as/f;

// Insert/character;

/Nnn inserts the ASCII characters represented by nnn (octal;

 

Example:

Oracle @ hjtest :~ /Hgd> echo "123" "456"

123 456

Oracle @ hjtest :~ /Hgd> echo "123/n456"

123/n456

Oracle @ hjtest :~ /Hgd> echo-e "123/n456"

123

456

Oracle @ hjtest :~ /Hgd> echo-E "123/n456"

123/n456

Oracle @ hjtest :~ /Hgd> echo-E "123 // 456"

123 // 456

Oracle @ hjtest :~ /Hgd> echo-e "123 // 456"

123/456

Oracle @ hjtest :~ /Hgd & gt; echo-e "123/100456"

123 @ 456

 

Notes:

In bash used in Linux, single quotation marks ('') and double quotation marks are different. single quotation marks ignore all escape characters. Double quotation marks do not ignore the following special characters:

Dollar signs ($), Back quotes ('), Backslashes (/), Excalmatory mark (!)

Example:

Oracle @ hjtest: ~> Echo "'test '"

-Bash: TEST: command not found

Oracle @ hjtest: ~> Echo ''test''

'Test'

Oracle @ hjtest: ~> Echo "$ TEST"

Oracle @ hjtest: ~> Echo '$ Test'

$ TEST

Oracle @ hjtest: ~> Echo "// TEST"

/TEST

Oracle @ hjtest: ~> Echo '// Test'

// TEST

Oracle @ hjtest: ~> Echo "Hello! "

Echo "Hello"

Hello

Oracle @ hjtest: ~> Echo 'Hello! '

Hello!

 

11,More,Less,Clear

N more, less command

These two commands are used to view files. If a file is too long to display more than one screen, you can only view the last content using the cat command. You can view the content by page using the more and less commands. The more command pauses the display of the object content that exceeds one page by page. The next page is displayed only after you press the button. In addition to more functions, less can also use the direction keys to scroll up or down the file for more convenient reading.

LessCommon Action commands:

The enter key moves down a row;

Y: move one row up;

The Space key scrolls down a screen;

B. Scroll up the screen;

D. Scroll down the half screen;

H less help;

U moves to the ocean half screen;

W specifies the row to be displayed, which is displayed from the next row of the specified number. For example, if the row is 6, the row is displayed from the second row;

G jumps to the first line;

G to the last line;

P n % jumps to n %, for example, 10%, that is, it is displayed starting from 10% of the entire file content;

/Pattern: Search for pattern. For example,/MAIL indicates searching for MAIL words in files;

V call the vi editor;

Q: Exit less

! Command to call SHELL, you can run commands; for example! Ls displays all files in the current directory of the current column;

N clear command

The clear command is used to clear the current screen without any parameters. It is the same as the cls command in dos.

 

12,Head,Tail

The n head and tail commands are used to view text files. The difference is that the head displays n lines of the file header and the tail displays n lines of the file. By default, n is 10 lines. You can specify the number of rows in the-n mode, for example:

Head-100 file and tail-100 file indicate the content of the first 100 lines and the last 100 lines respectively.

The n tail-f command allows you to view new content in the file in real time.

 

13,WcCommand

This command is used to count the number of bytes, number of words, and number of lines in a specified file. The options of this command are as follows:

-L number of statistics rows

-W words

-C: count the number of bytes.

These options can be used in combination. The order and number of output columns are not affected by the order and number of options. It is always displayed in the following order and each item has at most one column.

Number of lines, number of words, number of bytes, and file name

If there is no file name in the command line, no file name appears in the output.

For example:

Oracle @ hjtest: ~> Wc 1.txt 2.txt

460 1679 16353 1.txt

300 1095 10665 2.txt

760 2774 27018 total usage

Oracle @ hjtest: ~> Wc-l 1.txt

460 1.txt

The default parameter is-lcw, that is, the execution result of wc file1 file2 is the same as that above.

 

14,GrepCommand

Grep is the abbreviation of (global search regular expression (RE) and print out the line. It is used to search and print the rows containing the specified mode from the file, it is a powerful text search tool that supports searching text using regular expressions. Grep works like this. it searches for string templates in one or more files. If the template contains spaces, it must be referenced by "". All strings after the template are treated as file names. The search result is sent to the screen without affecting the content of the original file.

 

Grep can be used in shell scripts because grep returns a status value to indicate the search status. If the template search is successful, 0 is returned. If the search is unsuccessful, 1 is returned, if the searched file does not exist, 2 is returned. We can use these return values to automate text processing.

Example:

$ Ls-l | grep '^'

Filter the ls-l output content in the MPs queue and display only the rows starting with.

$ Grep 'test' d *

Display all the lines containing test in files starting with d.

$ Grep 'test' aa bb cc

The row Matching test is displayed in the aa, bb, and cc files.

$ Grep '[a-z]/{5/} 'aa

Display All rows of a string that contains at least five consecutive lowercase characters.

$ Grep 'w/(es/) t. */1 'aa

If west is matched, es is stored in the memory, marked as 1, and any characters (. *). These characters are followed by another es (/1). If they are found, the row is displayed. If you use egrep or grep-E, you do not need to escape the "/" number and write it as 'W (es) t. */1.

 

15,Man,LogoutCommand

ManCommand

Man is the abbreviation of manual, which is equivalent to the online Help of Unix/Linux. Every system command and call has a very detailed description, and most of them are in English. For example, man ls is used to view the instructions for using the ls command. In general, there is another way to view help, such as ls-help, which is supported by most commands.

 

LogoutCommand

This command is used to exit the system, which corresponds to the login command.

 

16, Pipelines andXargs
MPs queue:  

The pipeline operator "|" provided by Linux is used to separate the two commands. The output of the command on the left of the pipeline operator is used as the input of the command on the right of the pipeline operator. The continuous use of pipelines means that the output of the first command will be used as the input of the second command, and the output of the second command will be used as the input of the Third Command, and so on.

Note: The command input on the left of the pipeline serves as the command input on the right of the pipeline (the command input is certain), not a parameter. Not all commands support pipelines.

Example: ls | grep a check the file or folder named a in the current directory

 

Xargs:

Most Linux commands generate output: file list, string list, and so on. But what if I want to use another command and use the output of the previous command as a parameter? For example, the file command displays the file type (Executable file, ascii text, etc.); you can process the output so that it only displays the file name, currently, you want to pass these names to the ls-l command to view timestamps. The xargs command is used to complete this task.
Note: The find command passes the matching file to the xargs command, while the xargs command only obtains a part of the file at a time, instead of all, unlike the-exec option. In this way, it can first process the first part of the obtained files, then the next batch, and continue like this

 

Example:

1. Search for the memory information dumping file (core dump) in the entire system, and save the result to the/tmp/core. log file:

$ Find/-name "core"-print | xargs echo "">/tmp/core. log

2. When there are too many files in a directory, using the rm * command directly will cause the package to be too long. You can delete all the files as follows:

$ Ls | xargs rm

 

 

17,BasenameAndDirname

Basename is used to view the name of a file without a path, and dirname is used to view the file path. We can test the effect to see it:

> Basename/home/hj/1.txt

1. txt

> Dirname/home/hj/1.txt

/Home/hj

> Basename 1.txt

1. txt

> Dirname 1.txt

.

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.