Tutorial by Examples

To find files/directories with a specific name, relative to pwd: $ find . -name "myFile.txt" ./myFile.txt To find files/directories with a specific extension, use a wildcard: $ find . -name "*.txt" ./myFile.txt ./myFile2.txt To find files/directories matching one of ma...
To find files, use the -type f flag $ find . -type f To find directories, use the -type d flag $ find . -type d To find block devices, use the -type b flag $ find /dev -type b To find symlinks, use the -type l flag $ find . -type l
Sometimes we will need to run commands against a lot of files. This can be done using xargs. find . -type d -print | xargs -r chmod 770 The above command will recursively find all directories (-type d) relative to . (which is your current working directory), and execute chmod 770 on them. The -...
On an ext filesystem, each file has a stored Access, Modification, and (Status) Change time associated with it - to view this information you can use stat myFile.txt; using flags within find, we can search for files that were modified within a certain time range. To find files that have been modifi...
To find all the files of a certain extension within the current path you can use the following find syntax. It works by making use of bash's built-in glob construct to match all the names having the .extension. find /directory/to/search -maxdepth 1 -type f -name "*.extension" To find ...
Find files larger than 15MB: find -type f -size +15M Find files less than 12KB: find -type f -size -12k Find files exactly of 12KB size: find -type f -size 12k Or find -type f -size 12288c Or find -type f -size 24b Or find -type f -size 24 General format: find [options] -siz...
The -path parameter allows to specify a pattern to match the path of the result. The pattern can match also the name itself. To find only files containing log anywhere in their path (folder or name): find . -type f -path '*log*' To find only files within a folder called log (on any level): fin...

Page 1 of 1