Simple understanding of the Linux find command is not enough, we also need to know how to use it, the following small series from the find example to introduce the use of find, I hope that Beginners can help.
Let's start with a simple example to start.
$ find /-name test
. /backup/modules/field/modules/test
$
“Find the file named ’test’ in the root directory, this command will let the system find all files. Includes mounted file devices. This can take a while, especially to find a network shared hard drive. However, we can tell by the parameter -mount that the system ignores the mounted device:
$ find /-mount -name test
The find command has the following format:
find [path ] [options] [tests] [actions]
[path]
Paths; should not be difficult to understand. Here you can use absolute paths, and you can use relative paths quickly.
[options]
Parameters; more commonly used parameters:
-depth: first find subdirectories and then view current directory -follow: trace find connection file -maxdepths N : Subdirectory Recursion Maximum Depth - mount(or -xdev): Ignore Mounted Files
[tests]
Conditional Matching;
-atime -N/N/+ N: The last time the file was accessed in N days/N days/N days ago -mtime -N/N/+N: The last time the file was modified in N days/N days/N days ago-name pattern: and pattern Matching files (including directories) -newer f1 ! F2: newer file than file f1, older than file f2 -type b/d/c/p/l/f: file type: block device/directory/character device/pipe/link/file-user username: The owner of the file is username
We can connect the matching conditions by the following operators:
-not (!): Direction matching -and (-a): and -or ( -o): or
We can also merge some matching symbols in parentheses. For example,
\\(-newer -o -name ‘*test’ \\)
Now take a slightly more complicated example, look for files that have been accessed or modified that day, file names Contains & rsquo;python’, and the file owner is ’anthony’:
# find /\\( -atime -1 -or -mtime -1 \\) -and -name ‘*python*&rsquo ; -and -user ‘anthony’
/home/anthony/svn_code/subversion-1.7.2/subversion/bindings/swig/python
/home/anthony/svn_code/subversion- 1.7.2/subversion/bindings/ctypes-python
/home/anthony/python
/home/anthony/python/Python-3.2.2/build/temp.linux-x86_64- 3.2/home/anthony/python
/home/anthony/python/Python-3.2.2/Tools/unicode/python-mappings
/home/anthony/.local/lib/python3 .2
#
[actions]
Operation;
-exec command: Execute the command, as described later. -ok command: Same as -exec, which requires user permission in addition to command execution. -print: Print file name -ls: List file details
Now give an example -exec command
anthony@z:~$ find -mtime -1 -type f -exec ls - l {} \\;
-rw-r--r-- 1 anthony anthony 0 Apr 5 12:04 . /search/search.txt
-rw------- 1 anthony anthony 22997 Apr 5 12:04 . /.viminfo
-rw------- 1 anthony anthony 125 Apr 5 14:25 . /.lesshst
anthony@z:~$
Simply put, -exec or -ok, pass the queried file as a parameter to the subsequent command execution, and the position of the parameter is used. {}Identification, ie in the command, “{}” replaced with the file name found by find, and finally ”\\;” indicates the terminator.
The above is the introduction of the Linux find command. Learning the find command from the example will be much better than reading the theoretical knowledge. For beginners, it is necessary to see more examples.
Linux system operation, many people are practical Golang development language, in o
When compiling in the Linux environment, sometimes ld/;/usr/bin/ld:cannot find -lxx
There are many commands for system monitoring in Linux system operation. (See the s
On Linux systems, the XDMCP service allows Linux to connect to xwindows clients via a protocol. Of c
How to use ftp command under Linux
How to install and set up Samba service
How to disable the silent request of Firefox under Linux
How to solve the problem of multi-line display of wget download progress bar in CentOS
How to configure the zabbix alarm function of Linux system?
BackTrack5 uses the hard drive installation steps
Getting Started with Arch Linux
How Linux Expands Disks under VMware
How CentOS uses FPM to make RPM packages
Usage summary of chkconfig command under Linux
Computer talks Win10 control panel will be canceled?
How to solve the win7 sound card driver installation failure error code 0EX0000100
Why reinstall the system! How to reinstall the system? (a)
How to get gadgets online @Win8
Win10 system to help explain the introduction of the magnetic paste Get Started how to use?
How to install Windows 8 and Windows Server 2012 dual system
Microsoft: Windows 10 strives to improve the touch experience