The latest Linux command list

PHP中文网
Release: 2017-06-20 10:50:48
Original
2269 people have browsed it

Self-service command: ls --help man ls info ls

File attributes: ls -al Displays the file/directory owner, group, and other people’s writing and reading in the current directory Execution permission Number of files under the file or directory Owner Group Content size (byte) Last modification date File/directory name Note: For directories, if you don’t have x permissions, you will not be able to enter the directory [Show other directories] Files under: ls -al /, means displaying files in the root directory]

Change group permissions: chgrp eg>chgrp users -R test.txt [-R means recursive continuous update , the users group should exist in /etc/group】

Change owner:chown eg>chown [-R] account name[: group name] file or directory [account name in In /etc/passwd, the cp copy command will copy the attribute permissions of the file or directory together. In this case, you need to change the permissions]

Change the file permissions:chmod eg>chmod [-R ] 777 file or directory, or chmod u=rwx, go=rx file or directory, or chmod a+w [rwx corresponds to the number 421 respectively, a+w means providing read permission to everyone]

Create a new directory : mkdir [-p creates a multi-layer directory, -m modifies directory attributes eg: mkdir -m 755 test]

Create a new blank file: touch [Create a new hidden file , add .] before the file name [Modify the file date eg touch -d "2 days ago" file name. Or touch -t 201706091111 File name】

Delete file: rm [If there is - before the file name, you should use rm ./test to delete it]

Delete directory:rmdir [-p] [Delete empty directories, delete directories with content: rm -r]

Move files: mv [Frequent name changes]

Copy files or directories: cp [-s copies as a shortcut, -p often makes a backup and copies attributes instead of default attributes, -a copies all attributes, -u only when the two files are different Copy]

Current directory: . or ./ [When executing a shell script, ./run.sh is usually used to specify the run file in the directory. 】

Previous directory: .. or ../

Previous working directory: -

The current user’s home directory: ~ [~root, indicating the account’s home directory]

Display the current directory: pwd [For linked files, Using pwd -P, you can locate the actual directory structure]

Get the file name of the path: basename File path

Get the directory name of the path: dirnameDirectory path

View file content:

 cat: Display starting from the first line -n ​​displays the line number including blank lines, -b displays lines excluding blank lines No.

tac: Display

starting from the last line nl: Output the line number when displaying, do not display the blank line number, -b can Display the line number of the blank line, [nl can design the line number eg:nl -b a -n rz -w 3 test, the line number is displayed as 001,002...]

 more: Display page by page, space key to turn down one page, enter key to turn down one line, / string to be searched, q to exit the display, b to turn up the page, :f to display the file name and the number of displayed lines

 less: Display page by page and can turn pages forward. Pageup turns up, pagedown turns down, space bar turns down, /string searches down,? The string searches upward, n searches for the next one, N searches for the next one in reverse direction, g goes to the first line, G goes to the last line, q exits less

 head: only look at the first few lines -n is followed by a number, indicating how many lines to display

tail: only look at the last few lines, often used to view continuously updated logs, -n is followed by a number, indicating how many lines are displayed, -f continues to display , press Ctrl+c to stop

 od: Read in binary form Read files or binary files in data format, -t followed by data type [a default character output, c uses ASCII Output, d decimal, o octal, x hexadecimal, f floating point number】

 egDisplay lines 11 to 20 of the test file

head -n 20 test | tail -n 10 [|Pipeline: the previous output will be displayed after the following command] eg echo pwd | od -t oCc, output pwd in octal ASCII code

File type:

 -: Ordinary files: read files through cat, but data format files (such as some login log files) should be read with last

 d: Directory

 l:Shortcut Key

Devices and installation files

b: Block device (such as hard disk)

c: Character device (such as keyboard and mouse)

s: Data Interface file

p: Data transfer file

File extension:

.sh shell script language

.Z,.tar,.tar.gz ,.zip,.tgz Compressed files

Default permissions for files and directories:

 umask: Check the permissions of the current user when creating a new file or directory. For example, 0022 corresponds to u=rwx g=rx o-rx [nmask -S will get this result]. For new files, it corresponds to u=rwx g=rx o-rx. The default permissions are -rw-r--r--[x permissions are removed by default for files, and the default permissions found by the current user are 022, that is, the read permissions for groups and others are removed to 2]. For new directories, the corresponding The default permission is drwxr-xr-x [The directory has x permission by default, and the read permission of 2 is also removed]

Hidden attributes of the file or directory:

 chattr: +/-a +/-i [+i can prevent a file from being changed and can only be set by the root user, +a can only add content to the file and cannot change the original content]

 lsattr: Display hidden attributes of files or directories

View file type:file File name

Command and file search command:

 which:Search command location

  whereis:Look for files in a specific directory, -l lists the directories that can be searched, -b looks for binary files

 locate: Use Linux built-in database search -i: ignore case, -c outputs the number of files found, -l outputs a few lines, such as -l 5, -r connects to regular expressions [locate searches for /var/lib/mlocate]

 find: Search the hard disk directly [very slow], you can use the * wildcard, find [path] [operation] [status] eg find / -mtime 0 [Find files that have been changed within the current day] find / -mtime +1 [Find files that have been changed greater than or equal to one day ago] find / -mtime -1 [Find files that have been changed less than or equal to 1 day ago] ], find /home -user username [Find files of a certain user under a certain path] find -size [+/-] size [Find files that match the size], find -name analysisTeleInfo -exec ls -l {} \ ;[Find with additional actions, find -name analysisTeleInfo will output the path where the file is located, and then exec execute the path with ls -l (aliases are not supported)]

eg: There are two developers, in different groups, and now they want to develop a project together. It is required that everyone in the project has development rights, but others cannot enter and view

First add a new group: groupadd project

Add these two developers to the group: useradd -G project name1 useradd -G project name2

Establish the development environment of the project: mkdir /svn/ahome

Change the group where the environment is located: chgrp project /svn/ahome

Change the permissions of the environment: chmod 770 /svn/ahome [Error: Even if permissions are assigned in this way, when name1 enters the working directory, the newly created file It belongs to your own group, not the group where the project belongs. Guess, the permissions should be 2770, which means giving the SGID permission to the working directory. In this way, the newly created files of name1 and name2 are named after their working group and have joint development permissions. . Supplementary SUID, indicating that when the file is accessed by another person who has execution rights but cannot access, the file owner can temporarily have the permissions of the file owner]

Linux file system type: EXT2, which is an index type The file system, window is now basically NTFS

Linux compression command:

 *.Z compress program compression

 *.zip zip program compression

 *. gz gzip program compression (commonly used)

The source file will be deleted after compression. If the original file is a text file, you can use zcat/zmore/zless to read it. Decompress: gzip -d *.gz, search for compressed files Keyword string in: zgrep -n 'String' *.gz, -c outputs compressed data to the screen

*.bz2 bzip2 program compression (commonly used, is an upgrade of gzip, -k retains the source file)

*.xz xz program compression (commonly used, -k retains the source file), you can view the capacity of the compressed file before and after compression,

*.tar tar program packaging, no compression (commonly used)

Compression: tar -jpcv -f filename.tar.bz2 file/directory

Query: tar -jtv -f filename.tar.bz2

Decompression: tar - jxv -f filename.tar.bz2 [-C decompression directory]

*.tar.gz tar program packaging, compressed by gzip

*.tar.bz2 tar program packaged, bzip2 Compression

*.tar.xz tar program packaging, xz compression

eg: Backup data updated after a certain time

tar -jcv - f ./filename.tar.bz2 . --newer-mtime='2017/06/13' . Indicates that the files changed after 20170613000000 time in the current directory are packed and compressed into filename.tar.bz2 file

Backup If you do not want to back up a certain file or directory, use --exclude=directory (wildcard * available)

Backup tool: dd if='input_file' of='output_file' bs='block_size' count='number ',eg:dd if=/test of=/test2.back

Backup tool: cpio -ovcB > file/device backup

   cpio -ivcdu < file/device restore

    cpio -ivct < file/device View


vi Editor:

Use vi to create or open a file: vi filename [It is possible that vi needs to bring an absolute path, such as user/vi filename]

Enter editing mode: press i /o /a, etc.

Exit editing: esc

Save file: wq [Force save: wq! 】, do not save: q

Frequently used operations for opening files in vi: hjkl represents the up, down, left and right keys respectively. You can also use the direction keys, combined with numbers, to move the cursor in multiple rows or columns at one time. eg 3++k moves three places to the left. , PgDn moves down one page, PgUp moves up one page, 0/home moves to the first column of the column, $/end moves to the last column, gg moves to the first line of the file, G moves to the last line of the file, / character Search string downwards,? Search string upwards, bring n to mean search all the time, N search in reverse direction, :1,$s/string1/string2/g, replace string1 with string2 in full text, :1,$s/ String 1/String 2/gc Full text query replacement, :n1,n2s/String 1/String 2/g Replace the string between your line and n2 line, X deletes the character before the cursor, x deletes the character after the cursor characters, nx deletes multiple characters in a row, dd deletes the entire line, ndd deletes the cursor down by n lines, yy copies the line where the cursor is, nyy copies the cursor down multiple lines, p pastes the copied data on the line next to the cursor, and P is Paste the previous line, u to repeat the previous action, Ctrl+r to redo the previous action, . to repeat the previous action

vi to enter common editing operations: i /I position at the current cursor/the line, r /R Enters the replacement mode, r replaces the character at the cursor once, R replaces multiple times

Common operations of leaving after vi editing: :w to write the file, :q to leave (cannot leave when there are changes),: q! force to leave, :wq leave after saving, ZZ leave without changing, save the changes and leave, :w filename save as filename, :r filename append the data in filename to the back of the cursor, :n1,n2 w filename will n1 line Go to line n2 and store it in filename, :set nu displays the line number, :set nonu cancels the line number

Check whether the current vi is vim: alias will appear alias vi='vim', [command alias: alias, cancel the aliasunalias]

vi single selection and block selection: after opening the file with vi, v character selection, V line selection, ctrl+v block selection, You can complete the selection by combining up, down, left and right, y to copy the selection, p to paste the selection, d to delete the selection

vi multi-file editing: vi test.txt test2.txt Open multiple files at the same time, copy 4 lines from test.txt (4yy), then: n, press enter, edit test2.txt, p paste, :file to view the file currently opened by vi, :n edit the next file, :N edit the previous file

 vi multi-window View: gg to the first line of the file, then :sp, G to the last line of the file. At this time, the file will display two windows, the upper is the data at the end of the file, and the lower is the data at the beginning of the file. :sp filename means adding one to the current window. filename window, Ctrl+w+↑ to enter the previous window

Vi auto-completion function: ctrl+x + ctrl+n Select the string in the current file as the prompt message

   ctrl+x + ctrl+f Use the current file name as the prompt information

    ctrl+x + ctrl+o Use the file extension syntax as the prompt information. For example, html.html file, style="b" Press ctrl+x + A lot of prompt messages will appear when ctrl+o

Environment settings in vi: You can create a new ~/.vimrc environment settings file, set backspace=2 "use backspace to delete, set autoindent to automatically indent, set nu to display lines No., syntax on syntax check color display

Chinese encoding issues: 1. Linux default language, 2. File encoding, 3. The startup terminal interface must be unified

Enter and line feed under window and Linux Symbol problem: Windows uses \n\r (line feed and carriage return) to end a line, and Linux uses \n to end a line. Therefore, when converting from window to linux, the carriage return \r may be displayed as a ^M symbol. When converting from linux to window, it will be displayed as ^M. For one line, you need to use dos2nuix or nuix2dos to convert


bash: Bourne Again SHell is referred to as bash.

bash shell: 1. Command storage function, you can browse the entered commands up and down

       2. Install bash-completion to complete the options/parameters when using the tab key

3. command Alias ​​lm = 'LS -AL'

## 4. The front desk and backstage command settings

## 5. Scripts programmatic script

## 6. eg ls -l /usr/bin/X*

Check whether the command is a bash shell built-in command: type ls is not, type cd is

Command line break /enter 

Quick editing instructions: ctrl+u to delete the entire command string forward with the cursor, ctrl+k to delete backward, ctrl+a to move the cursor to the beginning of the command string, ctrl+e to move the cursor to the end of the command string

shell

Variable:

Variable setting and modification name=Myname

Regulations: There cannot be spaces on both sides of =, and there cannot be spaces in the content [you can use "can save variables", 'cannot save variables, display in character form'], and the variable name cannot start with a number.

Usage: Use escape characters / to represent special characters such as $, `, spaces, and use back-quotes to include instructions in the content eg name=`ls -l` echo $name, the variable content is increased: "$ name" directly connects to the newly added content, or ${name} directly connects to the newly added content, use this variable as an environment variable: export name, cancel the variable: unset name

 eg: Personalized working directory

Set your commonly used working directory as the variable work: work="servser/analysis", and then add personalized settings in the ~/.bashrc file: work="servser/analysis" export work. Next time you log in to the system, You can use cd $work to directly enter the working directory

. To access variables, echo $name or ${name}

. Environment variables: nuv or export View all environment variables

      set                                 accommodate and custom variables

and generate a random number between 0 and 9: declare -i number=$RANDOM* 10/32768; echo $number

  ? Variable, only related to the previous command. If the previous command is executed successfully, echo $? outputs 0, otherwise the error code is output

  locale Check the default language under Linux, -a Check the supported languages ​​​​under Linux

Reading and declaration of variables:

-t Connect the waiting time in seconds                              

declare  

or    typeset   List all variables and contents    declare -a variable Define variables as array types , -i variable is an integer type, -x changes the variable to an environment variable, -r sets the variable to read-only and cannot be unset, +x cancels the environment variable setting, array setting: var[index]=content

ulimit

Limit files and programs ulimit [-SHacdfltu] quota [unit is k], -a View the current user's restrictions

Historical commands:

history

List all the command history in the current memory, then n to check the last n commands, -c to clear the history commands, -w to update the record file! number executes the number-th instruction,! ! Execute the previous command,! al Execute the latest command starting with al

Linux boot interface settings: cat /etc/issue, boot prompt: /etc/motd file

Read the environment configuration file :

source

Configuration file name or . File name Terminal environment settings: The text interface terminal under Linux is tty1~tty6

#stty

: -a lists all setting tty contents, intr interrupts, quit exits, erase deletes backwards, kill deletes the command Ctrl+u, eof ends the input, start restarts the output Ctrl+q of the program, stop stops screen output Ctrl+s, susp gives a timed stop, and you can change these terminal commands in combination with keystrokes.  

set

: Set the terminal input and output environment. When set -u uses undefined variables, an error message is displayed Pass matching and special symbols:

 * 0 to multiple characters

 ? There must be a

 [abcd] Any one of abcd

 [0-9] Any one between 0-9

 [^abc] Any one of non-abc

# ~User home directory

 $ Get the variable

 & work control character, change the command to work in the background

 ! Non-

in logical operations / Directory symbol

 >, >> Data flow redirection, indicating substitution, accumulation

  Garbage under Linux Recycle Bin: /dev/null The data imported into this file will be automatically cleared

 2>&1 or &>! Direct the correct output and error output to a file at the same time

 Data writing: eg cat > test

   Write 123 on the keyboard, press ctrl+d to end the writing, and then cat test has the content just entered

  cat > test < ;< "return" Automatically ends input when input to return

  eg: Output echo "message" as standard error

   Echo "message" 2>/dev/null 1>&2

Force the cache data to be updated to the disk: sync

Command execution judgment:;, &&, ||

 ; eg sync; shutdown -h now Force synchronization of data before shutting down

Command 1 && Command 2 is executed correctly in the front ($?=0), and then executed later.

 Command 1 || Command 2 is executed correctly, 2 is not executed, the previous error is executed, execute 2

eg: Command 1 && Command 2 || Command 3 is often used for judgment, that is, Command 1 Execute command 2 successfully, otherwise execute command 3

Pipeline command:

eg: ls -al /etc | less will output before the pipeline (error output will not be processed ) as the input of the command after the pipeline

Interception command: cut, grep (in line units)

  eg: echo $PATH | cut - d ":" -f 5 Take the fifth one separated by : in the path variable, take multiple, -f 3,5

   Export | cut -c 12- Take the 12th variable among the variables printed by export Content after characters

     last | cut -d " " -f 1 Get the user name in the recent login situation

   eg: grep [-acinv] [- -color=auto] 'String to search' filename

     -a searches the binary file as a text file, -c counts the number of searches, -i ignores case, -n displays the line number , -v reverse search, --color=auto plus color display

Sorting command: sort, wc, uniq

Sort: -f ignores case, -b ignores preceding spaces, -M sorts by month, -n sorts by numbers, -r sorts in reverse, -u only one row appears in the same data after sorting, -t Separator, -k which interval to sort

Uniq: deduplication, -i ignore case, -c count

wc: -l displays the number of file columns, -w displays the number of words, -m displays the number of characters. Direct wc displays these three

in sequence.

The above is the detailed content of The latest Linux command list. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template