Shell Common Commands

Source: Internet
Author: User
Tags diff git commands

Previous words

The front-end engineer may not be able to use shell commands. But when you learn git, there are a lot of things that you need to do with a shell command in addition to GIT commands. Therefore, the shell command needs to learn and summarize the system, this article will detail the shell common commands

Special characters

Special characters have special meanings to the shell and do not use them as normal characters. Some special characters are used for regular expression matching

' "' [] () $ < > {} #/\! ~

whitespace characters

Although return, SPACE, and tab are not special characters, they have special meanings for the shell

The return key is typically used to end the command line and start the execution of the command

The Space key and the TAB key are used as separators on the command line

Escape character

To use special characters as normal characters, you can escape references to them

[note] the slash (/) cannot be escaped, it always represents the delimiter in the pathname

You can escape special characters by adding a backslash (\) before a special character. To escape two or more special characters consecutively, you must precede each character with a backslash (\)

Another way to escape special characters is to use single quotation marks to enclose them (' * * '), or to enclose special and ordinary characters in a pair of single quotation marks

Catalog related

Show directory path

"PWD" Displays the current directory

Switch directories

"CD" Switch to another working directory, the parameter direction is the directory pathname to be specified as the new working directory

CD [Options] [direction]

If you don't take any parameters, or use the tilde (~), switch to the home directory

Use a hyphen (-) to switch to the previous working directory

Use a double period (..) To return to the top level directory in the current directory

Create a Directory

"MkDir" creates a directory that cannot be created if a directory with the same name already exists

mkdir [option] Directory-list

Delete Directory

"RmDir" Deletes the directory, if it is not an empty directory, it cannot be deleted successfully

RmDir directory-list

File related

Show All Files

"LS" is similar to the dir command under DOS for displaying information about one or more files

By default, LS lists the file's information in alphabetical order by filename

ls [options] [file-list]

Options have a number of choices, common options are as follows

Ls–a displays all files, including hidden files ls–f add a symbol representing the file type after the file. * indicates executable,/-t displays the file in the order of the last modified time

When file-list contains a directory, LS will display the contents of that directory

ls mygit display files in the Mygit directory LS g* Displays all files beginning with the G letter

Show file contents

"Cat" displays the contents of a text file, similar to the type command under DOS

Cat [Options] [direction]
> file3 the contents of File1,file2, then redirects (>) to File3 file

> is the right redirect, which means that the left command result is the input to the right command. If the file on the right is an existing file, the original content will be emptied and the left command output. 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]+[d], the user's input will be written file1

deleting files

"RM" Delete file, similar to Del/erase command under DOS

RM [Options] File-list

Options have a number of choices, common options are as follows

rm–i System before deleting the file will be asked to confirm that after the user reply Y or y, the file will be really deleted rm–r recursively delete the contents of the specified directory, including all subdirectories and directories themselves rm–f and -i parameters,-V Displays the filename of each file that was deleted

Copying files

"CP" Copy File

CP [Options] source-file destination-FILECP [options] source-file-list destination-directory

Use the CP command to generate a copy of a file

You can also copy one or more files to a directory using the CP command

Cp-r recursively replicates directory hierarchies that contain normal files

Move or rename a file

"MV" To rename or move files

New-FILENAMEMV [options] Existing-file-list DIRECTIONMV [options] Existingnew- Direction

Use the MV command to rename a file

Use the MV command to move a file to another directory

Use the MV command to move a file to another directory and rename

You can also move a directory using the MV command

New file

"Touch" creates a new file, or changes the file's access and modification times

touch [Options] File-list

Touch is used to create a new file when a file with the same name does not exist

Touch is used to modify file access and modification times when a file of the same name exists

File Advanced

Compare files

"CMP" compares two files per byte, and if two files are the same, CMP does not display anything; otherwise, CMP will show the number of bytes and line numbers in the 1th different place

CMP [options] file1 [File2 [SKIP1 [SKIP2]]

Show different

"diff" shows the difference of two text files by line. By default, you can edit one of the files in the diff display to make it the same as another file

diff [Options] file1 file2diff [options] file1 Directorydiff [options] directory File2diff [options] Directory1 Directory2

File1 and File2 are the path names of ordinary text files to compare for diff. When File2 is replaced by the directory parameter, diff looks for a file with the same name as file1 in the directory directory; Similarly, when File1 is replaced by directory, diff will look for a file with the same name as File2 in the directory directory When you specify two directory parameters, diff compares two files under the Directory1 directory with the same simple file name as the Directory2 directory

1C1 indicates that the 1th line of the a.txt is changed to be the same as the first row of the B.txt

Statistics

"WC" shows the number of rows, words, and bytes

WC [Options] [file-list]

Shell Common Commands

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.