Linux Common Commands Summary

Source: Internet
Author: User
Tags aliases bz2 memory usage disk usage

Linux Common Commands Summary

1. Display date and time: Date

Can modify the display date format, such as: Date +%y/%m/%d%h:%mà2016/12/25 17:05 (%Y: Year;%m: month;%d: day;%h:24 hour system;%m: Min.)

Date–d parameters can add: Today/yesterday/tomorrow to display today, yesterday, tomorrow's date

2. Display Calendar: Cal (this month's monthly calendar is displayed by default)

Cal 2001 displays a 2001 year calendar; Cal 10 2001 can display a month calendar in detail

3. Calculator: BC

4, Tab: Used in the command after the completion of commands, use the directory or file after the name of the files to fill

5. Shutdown/Restart command

Shutdown–h now: Shut down immediately

Shutdown–h +10 ' The system would shutdown ': Shut down and give hints after 10 minutes

Shutdown–h 22:20: Determine actual shutdown

Shutdown–r Now: Restart immediately

Shutdown–r +10 ' The system would reboot ': Restart after 10 minutes and send messages to all online users

Other common commands: reboot: System restart; Poweroff: System shutdown; Init 0: System shutdown

6, File system simple operation

DF: List The overall disk usage of the file system (–h in a convenient-to-read format)

Du: List all file sizes in the current directory (–s, show only the size of this directory)

7. User Management

(1) User

New User: Useradd [–u UID] [–g Settings Group] [–c description] [–d Settings Home directory (if you do not set the default in/home directory)];

Set Password: passwd username (password has been set to change the password, ordinary users can modify their own password, the root user can change the password of everyone);

Modify user information: Usermod the directive option is similar to Useradd and can be modified by the corresponding option;

Delete User: Userdel username (username–r username: deleted together with User home directory)

(2) Group

New group: Groupadd groupname

Create group password: gpasswd groupname

Modify Group: Groupmod groupname

Delete Group: Groupdel groupname

(3) Query user information

Finger Username: Query A user related account attributes;

Finger: Query login user and login time on current system

ID: Query your own ID information

ID Username: Querying for a user ID information

W, who: Query the current system is logged on users

(4) User identity switch

SU: direct identity switch without changing environment variables

su–: Switch user identity while reloading user's environment variables, complete switch to new user's environment

Exit: Current User exits

sudo command: Get superuser privileges to execute command (use sudo instruction to set value in/etc/sudoers file, add username all= (All))

8. Directory/File operation

(1) directory switch CD:. current directory;. Previous directory;-Previous working directory; ~ Current user's home directory

(2) PWD: Displays the current path

(3) mkdir: Create a new directory (MKDIR–P/HOME/AAA/BBB/CCC a multi-level directory at a time)

(4) RmDir: Delete an empty directory (RMDIR–P/HOME/AAA/BBB/CCC delete multiple empty directories at once)

(5) RM–R/HOME/AAA: Delete multiple layers of non-empty directories, recursively delete

(6) View catalog contents Ls:–a display all files, including hidden files (files named after.); –l Long data string display, including file attributes and permissions information; –d list only directories, directory internal files are not listed;

(7) Copy operation cp– option source destination

–i: If the destination file already exists in the copy, ask whether to overwrite

–f: Force copy, do not ask

–s: Copy as Soft link (shortcut), point to target file, cannot open if target file is deleted

–l: Copy as Hard link

–r: Recursive replication

(8) Move/rename mv– option source destination

(9) Modify operation permissions chmod, including file owner O, file with Group G, other people rights u, all a

chmod 740 FileName: Digitally modified, read-4, write-2, execute-1

chmod u+x FileName: Modified by letter, read-R, write-W, execute-X, add permission with "+", remove permission with "–"

Chmod–r u+x dirname\*: All file modification permissions in the directory

(10) Modify the file owner Chown; Modify the owning group of the file Chgrp

(11) Create an empty document touch

(12) View the contents of the document: command file name

Cat: Displays the contents of the document starting at the first line; TAC: Starting from the last line (adding line numbers when the option-n is displayed)

MORE: Page by page, back page; Less: one page, one page, flip ahead

Head–n N: see only the first n rows; tail–n N: Only look at the last n rows; tail–f: Dynamically View the contents of a file

(13) Find files

Which command: Find the execution file, which displays the location of the document where the Find command is located

Whereis Filename/dirname: Shows where a file or directory is located

Locate Filename/dirname:–i can be ignored case –r can be connected to the regular, after you can enter part of the document name for fuzzy query

Find [PATH] [option] [action]:–name Query file name (available regular, fuzzy query); –size indicates file size; –type indicates file type; –perm indicates file permissions; –exec command {}\; Additional actions to be made

9, Compression and packaging

(1) gzip [–cdtv#] FileName: Build a compressed file with the suffix *.gz

–C: outputting compressed data to the screen

–d: Decompression

–t: Checking for compressed file consistency

–v: Displays the compression ratio information for the source document and the compressed document

–#: Compression level, 1 fastest, 9 slowest, default-6

(2) bzip2 [–cdkzv#] FileName: Creating a compressed file with the suffix *.bz2

–k: Preserves source files, does not delete original documents

–z: Compression parameters

–d: Extracting parameters

(3) Packaging and compressing tar

TAR–JCVF filename.tar.bz2 (destination) filename/dirname (source): Compressed in bzip2 mode

TAR–ZCVF filename.tar.gz (destination) filename/dirname (source): Compressed in gzip

TAR–JTVF filename.tar.bz2: Querying Compressed files

TAR–JXVF filename.tar.bz2–c to extract directory: Decompression (bzip2 mode compression)

TAR–ZXVF filename.tar.gz–c to extract directory: Unzip (gzip compression)

10, VI Editor

(1) General mode: VI Open after the direct entry mode, in this mode can move the cursor up and down, you can delete characters, dd delete positive line, yy copy, p paste processing document content;

X: Delete one character backwards; x: delete one character forward;

DD: Delete the current line; NDD: Deletes the current row down n rows; d1g: Deletes the cursor to the first line; DG: Deletes the cursor to the last line;

YY: Copy the current line; Nyy: Copy the current down n line; y1g: Copy cursor to the first line; YG: Copy cursor to last row

P: Paste

U: Undo the previous action, that is, cancel the operation

Ctrl+r: Repeat the previous action (also available as a decimal point operation)

(2) Edit mode: In general mode, press [I, I, O, O, A, a] to enter, press the ESC key to exit the mode;

H: Move one character to the left; J: Move down one character; K: move one character up; L: Move one character to the right;

0: Move to the beginning of the current line; $: Move to the end of the current line line

(3) Command mode: In general mode, enter [:,? ,/] into the command mode, you can query, character substitution, set line number and other operations;

/word: Cursor down query word;?word: Cursor up query word;n: Repeat the previous search action, search down; N: Repeat the previous search action, search upward;

: n1,n2s/word1/word2/g: Find word1 between line N1 and N2, and replace with Word2;

: 1, $s/word1/word2/g: look for word1 between line 1th and last line, and replace with Word2;

Set Nu: Display line number; Set Nonu: Suppress line number

N1,N2 w FileName: Stores the contents of N1 to N2 rows into the filename document

Wq save exit; q! do not save forced exit; wq! Force Save exit

11. Variable-related commands

ENV: View environment variables in the current shell environment;

Set: Displays all variables, including environment variables;

Export: Custom variable to environment variable;

echo $ variable Name: Displays variable contents;

Read variable name: Assign keyboard input to variable

Source profile Name: After modifying the configuration file, execute the source command after setting to take effect

12. Command Aliases Alias

Displays all current command aliases; alias xxx= ' comand ': set command alias; Unalias XXX: Cancels command aliases; works only in the current shell

13. Historical Order History

Displays all the history commands in memory, default to 1000, and historical N: Shows the most recent n executed commands;! N (Command number) executes the nth instruction in history

14. Wildcards and special characters

(1) wildcard characters

*: matches 0 to infinity any number of characters;

?: Match 1 To infinity of any number of characters;

[]: Match any character in parentheses, such as [ABCD] refers to a character in the matching ABCD;

[-]: matches all characters in the range of numbers or letters in parentheses, such as [0-9] refers to all numbers that match 0 to 9;

[^]: the first character in parentheses is a ^ to reverse, such as [^ABC] refers to non-A, B, c of other characters;

(2) Special symbols

#: Comment Information

\: Restore special characters as general characters

|: Pipeline Command

: Redirect (overlay);>> heavy-weighted orientation

"": double quotes with variable substitution function

Cmd;cmd: Multiple commands can be entered consecutively with a semicolon interval

CMD1 && cmd2:cmd1 Correct, execute CMD2;CMD1 error, do not execute CMD2

cmd1 | | Cmd2:cmd1 correct, do not perform CMD2;CMD1 error, execute CMD2

15. Pipeline Command

(1) Data interception: Cut, general usage [cmd | cut–d ' delimiter ' –f N]: Intercepts the output of the previous command with a delimiter and displays the nth field

(2) Line interception: grep, general usage [cmd | grep–a/c/i/n/v ' search string '] or [grep–a/c/i/n/v ' search string ' filename]: Find a string from a command result, or look up a string from a file to display an entire row

(3) Sort: sort,–r reverse sort; –u the same data displays only one row, –t the delimiter, and –k the interval separated by a delimiter to sort between intervals

(4) Count: Wc,–l display the number of lines; –w display word count, English word; –m display characters

(5) Tee filename: Generally used between two pipelines [cmd1 | tee filename| CMD2], the output of the previous command is entered into the specified file, and output to the screen using the following command

16. Scheduled Task crontab

(1) crontab command

Crontab–e: Enter vi edit screen to edit crontab work content,: Wq save exit;

Crontab–l: View the working contents of the set crontab;

Crontab–r: Delete all the crontab work;

(2) Timing settings

The five time periods were: 0-59 minutes, 0-23 hours, 1-31 days, 1-December, 0-7 weeks (0, 7 for Sunday);

* Asterisk: Represents any moment, such as: [* * * * * cmd];

, comma: Represents the separation time period, for example: 3 points per day, 6 points two point-in-time execution instruction [0 3,6 * * * cmd];

– minus: Represents a period of time, such as: daily from 3 o'clock to 6 two time range execution instruction [0 3-6 * * * cmd];

/n slash: Represents every n time unit, such as: Execute [*/5 * * * * cmd] every 5 minutes;

(3) System timing Task settings:/etc/crontab file add crontab directive

17. Program-related commands

(1) View all program data of the system: PS aux

(2) View your bash-related programs only: Ps–l

(3) Dynamic viewing program changes: Top–d 2 (Refresh every 2 seconds)

(4) Termination procedure: Kill PID (The PID of the PS aux query program can be used first)

(5) Termination procedure: Killall [–iei] cmd name (followed by full instruction name)

18. View system resources

Free to view memory usage; Uname–a View system basic information, uptime display system on how long, NETSAT–TLNP display system has been listening to network connection and its PID

19. Software Installation Yum

(1) Format: [option] [Query work items] [related parameters]

(2) –y: Automatically provide yes corresponding

(3) Search: Search for a software

(4) List/info: Lists all software names and versions currently managed by Yum

(5) Install: installation; Update upgrade; remove Delete

Linux Common Commands Summary

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.