Linux_ Common Commands

Source: Internet
Author: User
Tags create directory parent directory print print save file zip folder

1. ls
displaying directory folders and files
How to use: ls-lt

-a displays all files and folders included in the directory. And.. -A display directory where all files and folders are not included. And.. -l Displays all file and folder details in directory-T by modified time (reversed)-F such as directory after adding/such as executable file plus *-r by file name alphabetical order (reverse)-r display directory under all folders and files (including subfolders)
2. Cat
Output after concatenating the contents of a file
How to use: cat file1 file2 filen
-N number of rows for all outputs ordinal-B the number of non-blank lines on all outputs plus an ordinal-s such as a row of two consecutive lines or more, instead of a blank line
3. chmod
Update folder or file permissions
How to use: chmod a+x * *
Ugoa +-= rwx-c If the modified permissions are different than before, display modified message-V Display modified message-F hidden Error-R traversal set permissions (subfolders)
4. Chown
Update folder owners and groups
How to use: chown-r root:root *
-R Traversal Settings (sub-folders)

5. CP
Locally replicated folders and files
How to use: cp-a source Dest

-a preserves the permissions of the source file and other messages-R traversal copy (subfolder)-F when the target file and the original file name, delete the target file, and then copy
6. Cut
Display the contents of the File Contents n-m column
How to use: cut-c1-6 file
-C Displays the NUM1 to num2 text from the beginning of each line

7. RM
deleting files
How to use: rm-rf file or folder

-I delete the first query to confirm-F even if the file read-only forced deletion, do not need to confirm-r traversal Delete (subfolder)
8. rmdir
Delete a folder
How to use: rmdir folder
-P If the subfolder is empty after it is deleted, delete the folder. Note: The parent directory is deleted until the parent directory is not empty.
9. Unzip
Decrypt
How to use: unzip-p 123456-d path o.zip
-p < password > Zip package password-F overwrite original file-D < path > Specify decompression path-n decompression without overwriting the original file-O without asking, overwrite the original file-u overwrite the original file and unzip the other files in the compressed file into the directory-L  Displays the files contained within the compressed file-t check that the compressed file is correct-Z unzip-z equals to execute zipinfo instruction-j does not process compressed files in the directory path-c file name is case-sensitive-----compress the file names of files in the compressed file to lowercase-s Converts a space in a file name to an underscore-X to extract when the original uid/gid-q execution does not display any information-V execution is displayed with detailed information-C displays the extracted results to the screen, and makes the appropriate conversion to the characters-P is similar to the-c parameter, which displays the extracted results to the screen. But does not perform any conversion-A to text file to make the necessary character conversion-B do not convert the text file to character-x < expression > exclude the specified file in the compression package in the processing-m to send the output to the more program processing

10.&NBSP; zip
Encryption
How to use : zip-q-R d.zip folder/file

-A adjusts the executable auto-unzip file. -B < Working directory > specifies the directory where files are temporarily stored. -C adds a comment to each compressed file. -d deletes the specified file from within the compressed file. The directory name is not established within the-D compressed file. -F The effect of this parameter is similar to specifying the "-u" parameter, but not only updates the existing file, and if some files do not already exist in the compressed file, use this parameter to add it to the compressed file. -F attempt to repair a corrupted compressed file. -G compresses the file after it is appended to the existing compressed file, rather than creating a new compressed file. -H online Help. -I < Template style > only files that match the criteria are compressed. -j saves only the file name and its contents, not any directory names. -J Delete unnecessary data before compressing the file. -K uses the file name in MS-DOS compatible format. -L When compressing a file, replace the LF character with the LF+CR character. -ll the LF+CR character into the LF character when compressing the file. -L displays copyright information. -M compresses the file and joins the compressed file, deletes the original file, and then moves the file to the compressed file. -N < Tail string > does not compress a file with a specific trailing string. -O to compress files that have the most recent change time in the file, set the change time for the compressed file to be the same as the file. -Q does not show the instruction execution process. -R recursively handles all files and subdirectories under the specified directory. -S contains the system and hidden files. -T < date time > set the date of the compressed file to the specified date. -T checks that each file within the backup file is correct. -U replace the newer file into the compressed file. -V Displays the instruction execution process or displays version information. -V Saves the file properties of the VMS operating system. -W in the file name if the version number, this parameter is only valid under the VMS operating system. -X < Template style > exclude eligible files when compressing. -X does not save additional file attributes. -Y saves the symbolic connection directly, not the file that the connection points to, and this parameter is only valid under systems such as UNIX. -Z adds a comment to the compressed file. -$ Save the volume book name of the disk where the first compressed file is located. -< compression Efficiency > Compression efficiency is a value between 1-9.

One. Find

Find files and folders
How to use: find Path-mtime 3-type f-exec ls-lt {} \;
-atime N Last access time n days ago-mtime n Last update time n days ago-name name name contains-user user username contains-newer otherfile than a file new-type type F: File D: Directory!  Not-a and-o or-print Print file name-mount do not search for other problems the directory of the system-maxdepth N Maximum number of layers to search for directory-mindepth n search for the contents of the directory before the directory itself is searched-depth The file or directory is empty-exec command {} \; Execute commands-ok command {} \;   Execute the command, each execution requires user confirmation
. grep
The
How to use: grep-c "string" file1 file2
-C displays only the number of matching rows-I case-insensitive----only displays the file name-H does not display the prefix filename-v display unmatched number of rows-E extended mode (using regular)-n displays the number of rows matching rows in the file-x prints only the rows that match the row-ax displays the matching rows before the Y-line-cz Match rows before and after Row Z
SCP
Remotely replicating folders and files
How to use:
SCP LocalFile [Email Protected]:remotefolder
SCP [Email Protected]:remotefile localfolder
Scp-r Localfolder [Email protected]:remotefolder
scp-r [email protected]:remotefolder localfolder

-r copy directory and all subdirectory sub-files (traversal)
DF du
DF View File system capacity
Du viewing folders and file sizes
How to use:
Du-h--max-depth=1 Folder
Df-h

-h displays dimensions in a more readable way (for example: 1K 234M 2G)--max-depth=n N Query Depth
. Ln
Create a file or folder link
How to use:
Ln-s source file/source folder destination file
Ln-s/home/fdipzone/demo Link creates a folder link in the current directory links to/home/fdipzone/demo
Note: In the Linux/unix file system, there is a so-called link, we can consider it as the alias of the file, and the link can be divided into two types: Hard link and soft link (symbolic link), hard link means that a file can have multiple names, The soft-link approach is to produce a special file with the content of the file pointing to the location of another file. Hard links exist in the same file system, while soft links can span different file systems.
LN Source Dist is the generation of a link (dist) to the source, and the use of a hard or soft link is determined by the parameter.
Whether a hard link or a soft link will not copy the original file, it will only occupy a very small amount of disk space.
-F: The link will first delete the file with the Dist file-D: Allow the System Manager to hard-link their own directory-I: When deleting the file with the dist file with the first query-N: In the soft link, the dist as a generic file-s: Soft link (symbolic lin K)-V: Displays its file name before the link-B: Files that will be overwritten or deleted at the end of the link are backed up by the-s SUFFIX: Add the backed up file with SUFFIX's tail-V method: Specify how the Backup--help: Display Auxiliary description--version: Display version This
Locate .
Locate allows users to quickly search the file system for specific files. The method is to set up a database that includes all the file names and paths within the system, and then simply query the database when looking for it, rather than actually going deep into the file system. In the general distribution, the database is set up in the Contab to be executed automatically.
How to use:
Locate filename
Locate [-Q] [-d] [--database=]
Locate [-R] [--regexp=]
Locate [-QV] [-O] [--output=]
Locate [-E] [-f] <[-l] [-c] <[-u] [-u]>
Locate [-VH] [--version] [--help]

Locate Chdrv: Find all the files called Chdrv
Locate-n a.out: Look for all files called a.out, but show only 100
Locate-u: Building a database
-u-u The database is created,-U is started by the root directory, and-u can specify where to start. -E will be excluded from the scope of the search. -L if it is 1. The security mode is started. In safe mode, the user does not see files that the permissions cannot see. This slows down because the locate must get access to the file in the actual file system. -F excludes specific file systems, for example, we have no reason to put the files in the proc file system in the database. -Q Quiet mode, no error message is displayed. -N displays at most x outputs. -R uses the normal arithmetic to do the searching condition. -o Specifies the name of the data inventory. -d Specifies the path of the repository-H displays the secondary message-V shows more messages-V displays the version message of the program
. WC
How to use: WC [option] file1 file2
Wc-l file
Can be combined with WC-LCW file1 file2
-C Count Bytes-l count Rows-W count words
wget .
How to use: wget [Options] [URL]
Wget-o Test.zip Http://www.fdipzone.com/test.zip
Start:-V,--version displays the version of wget after exiting-H,--help print syntax help-B,--background after boot into the background to execute-E,--execute=command execute '. WGETRC ' Format command, WGETRC format see/ETC/WGETRC or ~/.wgetrcwget The default is to use the-e robots.txt parameter to bypass this restriction record and input file according to the Robots=off of the site:-O,-- Output-file=file writes the record to the file-A,--append-output=file appends the record to the file-D,--debug print debug output-Q,--quiet quiet mode (no output)-V,-- Verbose verbose mode (this is the default setting)-NV,--non-verbose turn off verbose mode, but not quiet mode-I,--input-file=file download urls-f that appears in file files,--force-html Treats the input file as an HTML file for-B,--base=url the URL as the relative link prefix that appears in the file specified by the-f-i parameter--sslcertfile=file the optional client certificate--sslcertkey=keyfile Optional client certificate keyfile--egd-file=file Specifies the file name of the EGD socket:--bind-address=address Specifies the local use address (host name or IP, used when there are multiple IPs or names locally)-T,-- Tries=number sets the maximum number of attempts to link (0 means no limit).-O--output-document=file write the document to the file-nc,--no-clobber do not overwrite the existing file or use. #前缀-C,-- Continue then download the files that are not downloaded--progress=type set the process bar flag-N,--timestamping do not re-download the file unless newer than the local file-S,--server-response the response of the print server--spider Do not download anything-T,--timeout=seconds sets the number of seconds for the response timeout of-W,--wait=seconds the interval between two attempts SECONDS seconds--waitretry=seconds between relink wait 1 ... Seconds sec--random-waIt waits 0 between downloads ... 2*wait sec-Y,--proxy=on/off turn Agent-Q on or off,--quota=number set the download capacity limit--limit-rate=rate limit download output directory:-nd--no-directories do not create directory-X, --force-directories Force Create directory-NH,--no-host-directories do not create host directory-P,--directory-prefix=prefix save file to directory prefix/...-- Cut-dirs=number Ignore number Layer remote directory HTTP option:--http-user=user set HTTP User name User.--http-passwd=pass set HTTP password for pass.-c,--cache= On/off Allow/disallow server-side data caching (generally allowed).-E,--html-extension Save all text/html documents with an. html extension--ignore-length Ignore ' Content-length ' header domain--header=string insert a string in headers String--proxy-user=user set the agent's user name to User--proxy-passwd=pass set the password for the agent Pass--referer=url include ' Referer:url ' header-s in HTTP requests,--save-headers save HTTP header to file-U,--user-agent=agent set agent name as Agent instead of wget/ Version.--no-http-keep-alive Close the HTTP activity link (forever link).--cookies=off do not use Cookies.--load-cookies=file from the file before starting the session Load Cookie--save-cookies=file in file after the session ends, save the cookies to the file FTP option:-NR,--dont-remove-listing do not remove '. Listing ' file-G,-- Glob=on/off the globbing mechanism for opening or closing filenames--passive-ftp use passive transfer mode (default).--active-ftp using active transfer Mode--RETR-symlinks the link to the file (instead of the directory) recursively in the recursive download:-r,--recursive recursive download--cautious with!-l,--level=number maximum recursion depth (INF or 0 for Infinity).--delete-after After now the local delete file-K, the--convert-links conversion non-relative links to the relative link-K,--backup-converted before the file X is converted, back to X.orig-m,--mirror equivalent to-r-n-l INF-NR. -P,--page-requisites download shows all images of HTML files in the recursive download contains and does not contain (Accept/reject):-A,--accept=list semicolon-delimited list of accepted extensions-R,--reject=list Semicolon-delimited list of non-accepted extensions-D,--domains=list semicolon-delimited list of accepted domains--exclude-domains=list semicolon-delimited list of non-accepted domains--follow-ftp Trace FTP links in HTML documents--follow-tags=list semicolon-delimited list of tracked HTML tags-g,--ignore-tags=list semicolon-delimited list of ignored HTML tags-h,--span-hosts When recursion goes to the external host-L,--relative only tracks the relative link-I,--include-directories=list allows the list of directories-X,--exclude-directories=list is not included in the list of directories-NP,- -no-parent don't go back to the parent directory
. Tar
How to use: tar [-cxtzjvfppn] files and directories
TAR-XZVF test.tar.gz
-C: Create a compressed file parameter directive (the meaning of Create);-X: Unlocks a compressed file parameter directive! -T: View the files inside the Tarfile! In particular, in the release of the parameters, c/x/t can only exist one! Cannot exist at the same time! Because it is not possible to compress and decompress simultaneously. -Z: Do you have the properties of gzip at the same time? i.e. do I need gzip compression? -j: Do you have bzip2 properties at the same time? i.e. is it necessary to compress with bzip2? -V: Files are displayed during compression! This is commonly used, but is not recommended for use in the background execution process! -F: Use the file name, please note, after F to immediately answer the file name Oh!   Don't add any more arguments! For example, using "TAR-ZCVFP tfile sfile" is the wrong way to write "TAR-ZCVPF tfile sfile" to-P: Using the original file's original properties (properties will not change according to the user)-P: You can use absolute path to compress! -N: Newer than next date (YYYY/MM/DD) will be packaged in the new file! --exclude file: In the process of compression, do not package file!

tail .
How to use:tail [-FQVCN] File
Tail-f Test.log

Note that-F is the abbreviation for--follow[=how], and you can read the characters at the end of the file and print them.
[=how] has two wording, =descriptor and =name default use descriptor, if you track the file is moved or renamed, you want to continue tail, you can use this option.
However, if you tail a log file, the file is likely to be deleted or overwritten, after the file is overwritten, the tail-f command will be invalidated, which requires the use of the TAIL-F command
-F is--follow=name-retry abbreviation,--follow=name is to follow the file name, you can periodically go to reopen the file to check if the file is deleted and re-established by other programs,-retry this parameter, to ensure that the file can continue to be tracked after re-establishment.

--follow=descriptor Example
1.sh

#!/bin/bash while:d o    echo $ (date +%y-%m-%d '%h:%m:%s) >> ' 1.log '    sleep 1done exit 0
2.sh
#!/bin/bash while:d o    echo $ (date +%y-%m-%d '%h:%m:%s) >> ' 2.log '    sleep 1done exit 0
1. Execute in Window 1./1.sh
2. Execute tail- F 1.log in Window 2, you will see the output
3. Abort 1.sh
4. Perform MV 1.log 2.log renaming

5. Execute./2.sh you will then see that the tail of window 2 will output 2.log of content.


--follow=name Example

1. Execute in Window 1./1.sh
2. Execute tail- F 1.log in Window 2, you will see the output
3. Execute RM 1.log, when tail no longer outputs any content

With tail- f 1.log, the tail will continue to output 1.log content when 1.log is created after RM 1.log is executed . because./1.sh is loop-executed and is created when 1.log does not exist


Shuf .

Function: Outputs the input lines to the standard output in a random order.

How to use:

Shuf [Options] ... [File]shuf-e [options] ... [Parameter]...shuf-i lo-hi [options] ...
Main parameters:

-E,--echo                 each parameter as input line-I,--input-range=lo-hi    treats each number of LO to HI as the input row-N,--head-count= the number of rows to      output the specified number of rows-O,--output = File          Outputs the result to the specified file instead of the standard output     --random-source= file   gets the random bit-Z from the specified file,--zero-terminated      ends the row at 0 instead of the new line     --help                 Display this help message and exit     --version              display version information and exit

Example:

1. Output test.txt in random order to standard output

Shuf test.txt
2. Randomly fetching a line from the Test.txt

Shuf-n 1 Test.txt
3. Output test.txt in random order to Test1.txt

Shuf Test.txt-o Test1.txt

Linux_ Common Commands

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.