Linux Common Command Collection

Source: Internet
Author: User

" *.txt " " *.pdf " \)-print

Regular find all txt and PDF files in root directory Find/-regex ". *\ (\.txt|\.pdf\) $"

  

Find all non-txt text found. ! -name "*.txt"-print

  

Make search depth Find ~-maxdepth 1-type F

  

Search by Type: Find. -type d-print  //List all directories only
-type f File/L Symbolic link
Search by Time:-atime access Time (in days, minutes units is-amin, similar to the following)-mtime modification time (content modified)-ctime change time (metadata or permission changes) all files visited in the last 7 days: find.-atime 7-type F-P Rint

 
Search by Size: W-word k M g look for files larger than 2k find. -type f-size +2k

  

Find by permission: Find. -type f-perm 644-print//Find all files with executable permissions

 

Search by User: Find. -type f-user weber-print//Find the files owned by the user Weber

  

Delete all SWP files in the current directory: Find. -type f-name "*.SWP"-delete

  

Perform the action (powerful exec) find. -type f-user root-exec chown Weber {} \; Change ownership in the current directory to Weber
{} is a special string, for each matching file, {} will be replaced with the corresponding filename;

  

 

Eg: Copy all the found files to another directory: find. -type f-mtime +10-name "*.txt"-exec cp {} old \;

  

Grep-o output only matched lines of text vs-v output no matching lines of text the number of times the text is contained in the-C statistic file
    • Grep-c "text" filename
-N Prints matching line numbers
-I ignore case when searching
-L print File name only
    • Recursive search of text in a multilevel directory (the programmer searches for code favorites):

grep "Class". -r-n

    • Match multiple patterns

Grep-e "Class"-E "vitural" file

  

Convert multi-line output to single-line output cat file.txt| Xargs\n is a delimiter between multiline text converts a single line to multiple lines of output cat Single.txt | Xargs-n 3-n: Specifies the number of fields to display per row-D defines the delimiter (the delimiter for multiple lines by default is \ n)-n specifies that the output is multiple lines-I {} Specifies the replacement string, which is replaced when the xargs extension is used for the command to execute when multiple arguments are required for the cat file.txt | Xargs-i {}./command.sh-p {}-1 Number of statistical program lines (-0: specified as input delimiter) find source_dir/-type f-name "*.cpp"-print0 |xargs-0 wc-l

  

Eliminate duplicate rows sort Unsort.txt | Uniq count the number of times each line appears in a file sort Unsort.txt | Uniq-c Find duplicate rows sort Unsort.txt | Uniq-d

  

TR Delete character cat file | Tr-d ' 0-9 '//delete all numbers Cat file | Tr-c ' 0-9 '//Get all the numbers in the file cat file | Tr-d-C ' 0-9 \ n '  //Remove duplicate characters from non-numeric data tr-s compressed text; most commonly used to compress extra spaces cat file | tr-s "

 

    • Cut usage cut range N-nth field to end-M 1th field for M n-m N to M field cut take Unit-B in bytes-C with the character of-F to intercept the 2nd and 4th columns of a file in a field (using delimiters): cut-f2,4 filen Ame go to all columns except column 3rd: cut-f3--complement filename-d Specify delimiter: cat-f2-d ";" Filenamecut-c1-5 file//print first to 5th character cut-c-2 file//Print First 2 characters

  

 

The two text is stitched together by columns, the default delimiter is a tab, you can specify the delimiter with-D paste file1 file21 colin2 Book

  

Wc-l File//Count rows wc-w File//statistic number of words wc-c file//statistic characters

  

First replace the seg ' s/text/replace_text/' file   //replace the first match of each line with the text globally replaced by the SEG ' s/text/replace_text/g ' file by default, after the output is replaced by the content, Use-i:seg-i ' s/text/repalce_text/g ' file if you need to replace the original files directly

To remove a blank line:

Sed '/^$/d ' file

  

Linux Common Command Collection

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.