- Linux Shell Scripting Cookbook(Third Edition)
- Clif Flynt Sarath Lakshman Shantanu Tushar
- 124字
- 2021-07-09 19:46:14
Searching based on file type
Unix-like operating systems treat every object as a file. There are different kinds of file, such as regular files, directory, character devices, block devices, symlinks, hardlinks, sockets, FIFO, and so on.
The find command filters the file search with the -type option. Using -type, we can tell the find command to match only files of a specified type.
List only directories including descendants:
$ find . -type d -print
It is hard to list directories and files separately. But find helps to do it. List only regular files as follows:
$ find . -type f -print
List only symbolic links as follows:
$ find . -type l -print
The following table shows the types and arguments find recognizes: