linux find file command

In the Linux system, finding files is not as intuitive as in Windows. Generally, the find command is used to help find it, which is not so convenient, but the function of this command is relatively powerful.

 

Function description
find command finds files in the file system

Command format
find [path ...] [option] [-exec | -ok | -print]

The parameter
path of the find command The path of the directory searched by the find command.
The -exec find command executes a shell command for each matching file found. The command format is "-exec command {} /;".
        Note that there is a space between "{}" and "/;", and the last ";" "Don't forget either.
-ok and -exec have the same effect, but ask the user for confirmation before executing the command, which is more secure to execute the command.
-print Print found files to standard output.

 

Command option
-name Find files by file name.
-perm Find files by file permissions.
-user Find files by file owner.
-group Find files by group they belong to.
-mtime -n +n Find the file according to the change time of the file, -n means the file change time is within n days from now, +n means the file change time is n days ago.
              The find command also has the -atime and -ctime options, which are similar to the -mtime option.
-nogroup Find files with no valid group, that is, the group to which the file belongs does not exist in /etc/groups.
-nouser Find files with no valid owner, that is, the owner of the file does not exist in /etc/passwd.
-newer file1 ! -newer file2 Find files with a change time newer than file11 but older than file22.
-type Find files of a certain type, such as:
    b - block device files.
    d - directory.
    c - character device file.
    p - the pipe file.
    l - Symbolically linked file.
    f - normal file.
-size n: [c] Find files with a file length of n blocks, with c, it means the file length is in bytes.
-depth When looking for files, first look for files in the current directory and then in their subdirectories.
-fstype Find files located in a certain type of file system. These file system types can usually be found in the configuration file /etc/fstab,
                which contains information about the file system in this system.
-mount Do not cross filesystem mount points when looking for files.
-follow If the find command encounters a symbolic link file, follow to the file pointed to by the link.
-cpio Use the cpio command on matching files to back them up to a tape device.

In addition, the following three differences:
  -amin n finds the files accessed in the last N minutes in the
 system -atime n finds the files accessed in the last n*24 hours in the
 system -cmin n finds the files whose status was changed in the last N minutes in the system
 - ctime n Find files in the system whose file status has been changed in the last n*24 hours
  -mmin n Find files in the system whose file data has been changed in the last N minutes
 -mtime n Find files in the system whose file data has been changed in the last n*24 hours

 

Specific usage examples:
find / -name filename Find files by file name in the root directory
find / -name '*aaa*' Find some files with the name aaa
in the root directory find / -size 1000c Find partial sizes in the root directory Find/ -size +1000c for 1000 byte files
find/ -size +1000c Find files larger than 1000 bytes in the root directory
find / -amin -10 # Find files accessed in the last 10 minutes in the system
find / -atime -2 # Find the last file in the system Files accessed in 48 hours
find / -empty # Find files or folders that are empty in the system
find / -group cat # Find files that belong to groupcat in the system
find / -mmin -5 # Find the last 5 minutes in the system Modified files
find / -mtime -1 #Find files modified in the system in the last 24 hours
find / -nouser #Find files belonging to invalid users in the system
find / -user fred #Find this one belonging to FRED in the system user's files
find /tmp -size +10000000c -and -mtime +2 mixed conditional find
find / -user fred -or -user george
find / -name "httpd.conf" -ls find and display properties of a file

 

 

 

CP command

Format: CP [options] source file or directory destination file or directory

Option description:
        -b with the same name, back up the original file 
  -f force to overwrite the file with the same name 
  -r Recursively retain the original directory structure and copy the file 

例:
cp -r /home/test /tmp

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326459579&siteId=291194637