File search, find and compare

File search, find and compare

File Search command find

find file search command. The basic model is find [search] [Filters], such as find /etc -name *init*Find your etc directory under the file name containing the init file? Represents a single character, * represents any character, then if the matching conditions without wildcards, the search results in the file name only init. -iname representatives not case-sensitive;

-size filters can be added in size, find /etc -size +204800expressed in the lookup file larger than 100MB etc directory, that is greater than +, - means less than, equal symbol is not added before the number indicates, the number of unit data block is equal to 0.5K;

After -user add username, you can find the owner, -uid can locate the account file with the account id for the user's files, -gid find the corresponding group ID of the file.

Search system does not belong to anyone file: find / -nouserWhen a user creates some documents, then the user is deleted after the system will be left part of such a document. -nogroup can not find a group of files.

Find -amin represents access time (access), - cmin represents the time to find the file attribute modification (change), - mmin represents the contents of the file modification time to find (modify), as find /etc -cmin -5expressed modification time of the file attributes within 5 minutes to search etc directory, before time can also be a plus or minus sign.

-a is tied for screening, -o condition can be satisfied by a filter, which is placed between two filter criteria, such as find /etc -size +163840 -a -size -204800representation size of the lookup files between the two;

-type can find based on file type, file types are f, d, l and the like;

-inum can inode lookup, you can find all the hard-linked files a file with this command.

-perm followed by a number that can find digital rights file, the former case Digital Plus - means find any rights include permission corresponding to the digital document (e.g., search -rwxr - r--, when the file is -rwxr-xr- x will be found out), the former digital plus / means that when any part of the digital rights can, will be to find out (such as search -rwxr-xr-x, when the file is -rw ------ - will be seized)

-exec or -ok can execute commands on the search results, such as:

find . -name *init* -exec ls -l {} /;

Find the file name represents the complex requirements of the current directory, and then displays the results file details, the last three characters are fixed. -ok and -exec difference is that -ok further inquiries.

find . -inum 31531 -exec rm {} /;

Representation of the search results to delete.

Result of the execution format braces find command executed on behalf of, and /; or; Representative semicolon, a terminator command, and the command -exec braces to find this to be performed after that.

View files updated within 24 hours:find / mtime 0

Locate the file is newer than the one file:find /etc -newer /etc/passwd

File Search command locate

locate also file search command, directly behind plus the file name indicates locate the file containing the name of the command to find very fast, because linux pre-establishment of a database record of the file information, locate it is to find the file by searching the library of this database in /var/lib/mlocate/mlocate.db. The disadvantage is that the new file is not included into the database, this time with the locate command is finding out, but you can refresh the database with updatedb manually, but if the file in tmp (temporary directory), even if the refresh through the command can not be found. locate -i option can be added at this time to find is not case-sensitive.

Locate the file associated with the passwd, listing only five:locate -l 5 passwd

Find the file contents grep

grep to check for file content, such as grep winner /etc/inittabindicating whether or not the file winner search string, and the character string displayed rows. -i can not case-sensitive search. -v can filter out some of the results, such as:

grep -v ^# /etc/inittab

He expressed to filter out line beginning with #, only the other lines.

Remove all of the lines do not have root:last | grep -v 'root'

grep command is actually analyzing each line, will meet the requirements of the line out.

Contrast command file

Comparison of file differences in two directories:diff -r 目录1 目录2

diff cmp command and the contrast between the two files, in units of the former compared to the latter units of bytes comparison.

you can use the patch command with the diff, diff command to make the old document to the new document patch, patch command can upgrade to the old document to the new document, you can restore the original version of the document.

Guess you like

Origin www.cnblogs.com/shizhuoping/p/12535590.html