Linux Shell text processing command summary

  

We all know that Linux can be operated with a variety of commands, there are quite a few commands for text processing, the following small series will be a summary of the Shell text processing tools in Linux, so that You have an understanding.

Under the Linux operating habits unlike windows can still be operated with a window, which is composed of many different command, this article will introduce the use of Shell under Linux text processing most commonly used tools: find , grep, xargs, sort, uniq, tr, cut, paste, wc, sed, awk

The examples and parameters provided are the most common and useful;

I am on shell scripts The principle of use is to write a single line of commands, try not to exceed 2 lines;

If you have more complex task requirements, consider python;

find file search (see System Home Linux) Find command common usage summary)

• Find txt and pdf files

The code is as follows:

find . \\( -name “*.txt” -o -name “*.pdf” \\) -print

• Regular way to find .txt and pdf

Codes are as follows:

find . -regex “.*\\(\\.txt| \\.pdf\\)$”

-iregex: Ignore case-sensitive regulars

•negative parameters

find all non-txt text

code As follows:

find. ! -name “*.txt” -print

•Specify search depth

Print out the current directory file (depth is 1)

The code is as follows:

find . -maxdepth 1 -type f

Custom Search

•Search by Type:

The code is as follows:

find . -type d -print //List all directories only

-type f File /l Symbolic link

•Search by time:

-atime Access time (unit It is day, the minute unit is -amin, the following is similar)

-mtime modification time (content is modified)

-ctime change time (metadata or permission change)

All files that have been accessed in the last 7 days:

The code is as follows:

find . -atime 7 -type f -print

•Search by size:

wword k MG

Find files larger than 2k

The code is as follows:

find . -type f -size +2k

Find by permission:

The code is as follows:

find . -type f -perm 644 -print //Find all files with executable permissions

Find by user:

The code is as follows:

find . -type f -user weber -print//Find files owned by user weber

Follow-up actions after finding

•Delete:

Delete all current directories Swp file:

The code is as follows:

find . -type f -name “*.swp” -delete
Previous1234567Next page Total 7 pages

Copyright © Windows knowledge All Rights Reserved