Monday, December 4, 2017

UNIX Find A File Command – nixCraft

UNIX Find A File Command – nixCraft


The syntax is:

find /dir/to/search -name "file-to-search"
find /dir/to/search -name "file-to-search" -print
find /dir/to/search -name "file-to-search" -ls
find /dir/to/search -name "regex" -print

Examples – find command

To find all perl (*.pl) files in current directory:

$ find . -name '*.pl'


The . represent the current directory and the -name option specifies
all pl (perl) files. The quotes avoid the shell expansion and it is
necessary when you want to use wild card based search (without quotes
the shell would replace *.pl with the list of files in the current

To list only files and avoid all directories

The following command will only list files and will exclude directories, special files, pipes, symbolic links etc:

$ find . -type f -name '*.pl'

No comments: