Linux Common commands and parsing

Source: Internet
Author: User
Tags clear screen create directory

Basic Daily Commands

Init 3 (Go to command line page)

Steup (set up network)

PWD (view your current directory)

Date (view current system time)

Example: (date +%y-%m-%d) Displays the current system time in the format of month and day, and (date-s "2018-02-28" 18:20) modifies the time to this time;

(Date +%y-%m-%d--date = "-1 day") Current date-1 days; (date +%y-%m-%d--date = "+2 month") Current date + February; (date +%y-%m-%d--date = "+3 year") Current date + 3 years.

(KWCLOCK-W) After the modification time needs to write to the hardware BIOS can still take effect after the reboot, otherwise after the reboot expires, therefore needs to append this command.

Who (view current online users)

Last (View recent login history)

Example: (last-3) View the last three login history.

shutdown (shut down) Halt (shut down immediately) Note: The shutdown must be done with the root user

Shutdown-h now (shut down immediately), Shutdown-h +10 (shut down after 10 minutes), Shutdown-h 12:00:00 (12-point off), Shutdown-r now (restart immediately).

Clear or shortcut key ctrl+l(clear screen) Ctrl + C or Q (exiting the current process); Ctrl + Z (suspends the process to the background, which is the equivalent of minimizing).

BG Jobid (Let the process continue in the background); FG Jobid (Let the process go back to the foreground).

Echo (print)

Example: (Echo AAA) Print AAA to the console, (a=123) (echo $a) print 124 stored in the A variable to the console.

Directory Operations

LS (view directory information)

Example: (LS/) View folder and file information under the root directory, (LS.) View folder and file information under the current directory; ) View folder and file information in the previous level directory;

(Ls-al) A is a display of hidden files, L is displayed in a more detailed list, and (Ls-l or ll) displays the folder and file information in the current directory in a more detailed list.

CD (Switch working directory)

Example: (CD/) to root directory, (CD/HOME/WXY) to Wxy user directory, (CD ~ or CD) switch to user home directory; (CD-) fallback to last directory

mkdir (Create folder)

For example: (mkdir tools) Create a Tools folder under the current directory, (mkdir-p AAA/BBB/CCC) cascade Create directory, create AAA and create BBB in AAA, create BBB, and create CCC in BBB.

RmDir (delete folder)

For example: (rmdir tools) can delete empty directories, (rm-r tools) Delete the contents of the Tools entire folder, need confirmation, (rm-f tools) force Delete tools, no need to confirm.

MV (Modify folder)MV is essentially mobile, if the selected file name is not in the current directory, then it is modified, if any, is moved.

Example: (MV Wxy Xiyang) Change the folder Wxy to Xiyang, (MV Xiyang wxy) move Xiyang in the current directory to WXY, (MV Xiyang Wxy/xiaobai) move and rename to Xiaobai.

Rename (batch file name modification)

Example: (rename. txt. docx *) changes all txt files in the current directory to docx files.

File operations

1. Create a file

Touch (Create File)

Example: Touch a.txt (Create a text document named a); Touch B.avi (Create an AVI file named B)

2. redirect Files

">", ">>" (Create a file and write, overwrite, append content through the echo Print command like a file)

Using the redirect > feature, a specified output is written to a file, overwriting the original file content, and creating the file if the directive's file does not exist. >> appends the output of one instruction to another file without overwriting the original file.

Example: Echo "abc" >abc.txt (Create Abc.txt document and write content ABC); echo "HHH" >abc.txt (replace Abc.txt document if Abc.txt document already exists); echo " Def ">>abc.txt (Append content def to abc.txt document)

3. Text Editor

VI (Create files and freely edit content)

Example: VI 1.txt (if 1.txt exists, edit this file, if the 1.txt file does not exist, create and edit this file)

The input VI 1.txt command first enters "General mode", which accepts only a variety of command shortcuts, cannot edit content,

Press the "I" key to enter the edit mode from the general mode, this mode, the type is the file content,

When the edit is complete, press ESC to exit edit mode and return to normal mode.

Then press ":" Key, enter the bottom line command mode, enter "WQ" command, carriage return.

Common shortcut keys in the editor (used in general mode)

A after the cursor one begins inserting

A in the last insert of the line

I insert at the front of the line

GG jumps directly to the first line of the file

G jump directly to the last line of the file

DD Delete a row

3DD Delete three rows

YY Copy a row

3yy copy three rows

P Paste

U fallback

V Enter the character selection mode, select Done, press Y to copy, press p to paste

Ctrl + V into block selection mode, select Done, press Y to copy, press p to paste

Shift+v Enter row selection mode, select Done, press Y to copy, press p to paste

Display line number: (: Set Nu)

Hidden line number: (: Set Nonu)

Find and Replace in editor (entered in command mode in the bottom line)

Find keyword: (:/a) find a in the file, and navigate to the first found place, press N to navigate to the next matching position (press N to navigate to the previous).

Replace keyword (: s/aaa/bbb) to find the first AAA of the line on which the cursor is located, replace with BBB, (:%S/AAA/BBB) to find all the AAA in the file, and replace it with BBB.

3. Copy/delete/move

CP, RM, MV

Example: (CP 1.doc/home/wxy) copies the 1.doc files in the current directory to the/home/wxy directory, and (CP 1.doc/home/wxy/2.doc) copies the 1.doc files in the current directory to the/home/ Rename the Wxy directory to 2.doc.

(rm 1.doc), (Rm-r 1.doc) need to confirm whether to delete, (rm-f 1.doc) directly delete, do not need to confirm.

(MV 1.doc/home) move 1.doc in the current directory to the/home directory

4. View the contents of a file

Cat

Example: (cat install.log) output the file contents to the console at once.

Commands for paging through files

More

Example: (more Install.log) You can flip a page, scroll down one (space), page up (b), exit (Q).

Less

Example: (less install.log) can flip a page, scroll down one (space), page up (b), flip a line (↑), scroll down one line (↓), Search for keywords (/keywod), jump to the end of the file (G), skip to the first line of the file (GG), exit less (q).

Tail

(tail-10 install.log) View 10 lines at the end of a file

(Tail +10 install.log) view file 10--> last line

(Tail-f Install.log) The unique inode number of the small F trace file, even if the file is renamed, or to track the original inode representation of the file

(tail-f install.log) Large F Follow the file name to track

(haed-10 install.log) View 10 lines of the file header

5. Packaging compression

Compress gzip

Example: (gzip a.txt) Compress a.txt, (gzip-d a.txt.gz) unzip the compressed file

Compression bzip2

Example: (bzip2 a.txt) a.txt compression; (bzip2-d a.txt a.bz2) unzip the compressed file

Package TAR-CVF(c for Create, V for Show progress, F for a package), unpack TAR-XVF (X for solution of a package), append (R for)

Example: (TAR-CVF test.tar 1.txt 2.txt AAA) package 1.txt, 2.txt, AAA into the Test.tar folder;

(TAR-XVF Test.tar) will Test.tar folder 1.txt, 2.txt, AAA unpacking;

(TAR-RVF Test.tar 3.txt) appends 2.txt to the Test.tar folder.

Package and Compress TAR-ZCVF

Example: (TAR-ZCVF test.tar.gz 1.txt 2.txt AAA) package 1.txt, 2.txt, AAA into the Test.tar folder, and compression;

(TAR-ZXVF test.tar.gz) test.tar.gz folder 1.txt, 2.txt, AAA decompression, (tar-zxvf test.tar.gz-c/usr) extract files from test.tar.gz to USR

Viewing the contents of a compressed package

Example: (TAR-ZTVF test.tar.gz) view content in test.tar.gz

Linux Common commands and parsing

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.