Find basics of linux commands

Find command

Purpose: To find files / directories that meet the conditions
1) In which directories to search
2) The content

Format:
find directory name option search condition

Let's take a practical example:
first of all, there is a computer, the host and the monitor / keyboard are necessary, the mouse is better, it is good to start ...
1) find / home / book / linux / dira / -name "test1.txt"
parsing command Meaning:
a) / home / book / linux / dira / indicates the search path
b) -name indicates to search for the file by name
c) "test1.txt" indicates that the search name is test1. txt file.

book@www.100ask.org:~/linux/dira$ find /home/book/linux/dira/ -name "test1.txt"
/home/book/linux/dira/test1.txt
/home/book/linux/dira/dirb/test1.txt

Similarly:
1>
find / home / book / linux / dira / -name “* .txt” to
find all files ending with “.txt” under the specified directory, where the asterisk is a wildcard.

book@www.100ask.org:~/linux/dira$ find /home/book/linux/dira/ -name "*.txt"
/home/book/linux/dira/test1.txt
/home/book/linux/dira/test2.txt
/home/book/linux/dira/dirb/test1.txt
/home/book/linux/dira/dirb/test2.txt

2> 查找目录
 find /home/book/linux/ -name "dira"
 查找指定目录下面是否存在dira这个目录,“dira”是目录名。
book@www.100ask.org:~/linux/dira$ find /home/book/linux/ -name "dira"
/home/book/linux/dira

Note:
1) If no search directory is specified, it is the current directory.
find. -name “ .txt”
where “.” represents the current path
find -name “
.txt”
is the same function as above. If the location of the specified directory is the default, the default is the current directory.

book@www.100ask.org:~/linux/dira$ find . -name "*.txt"
./test1.txt
./test2.txt
./dirb/test1.txt
./dirb/test2.txt
book@www.100ask.org:~/linux/dira$ find -name "*.txt"
./test1.txt
./test2.txt
./dirb/test1.txt
./dirb/test2.txt

2) Find also has some advanced usages, such as finding files that have changed within (or before) the last few days (or several hours).
find / home -mtime -2
find files that have changed within two days under the / home directory

book@www.100ask.org:~/linux/dira$ find /home/ -mtime -2
/home/book
/home/book/.cache/upstart
/home/book/.cache/upstart/unity7.log
/home/book/.cache/upstart/unity-panel-service.log
/home/book/.cache/upstart/gpg-agent.log
/home/book/.bash_history
/home/book/.Xauthority
/home/book/.xsession-errors
/home/book/python
/home/book/python/L9
/home/book/python/L9/aliens.py
/home/book/python/L9/favorite_languages.py
/home/book/python/L9/many_users.py
/home/book/python/L9/pizza.py
/home/book/python/L9/new peopel.py
/home/book/python/L8
/home/book/python/L8/favorite_languages.py
/home/book/python/L8/user.py
/home/book/python/L8/alien.py
/home/book/python/L8/new peopel.py
/home/book/linux
/home/book/linux/dira
/home/book/linux/dira/test1.txt
/home/book/linux/dira/test2.txt
/home/book/linux/dira/dirb
/home/book/linux/dira/dirb/test1.txt
/home/book/linux/dira/dirb/test2.txt
/home/book/.gnupg
/home/book/.gconf

Published 53 original articles · praised 16 · visits 2213

Guess you like

Origin blog.csdn.net/m0_37757533/article/details/105350687