Search for files in linux

There are two commands useful to perform the find operation in linux

Find

This command searches for a file within the root file system (it is recursive)

​# find / -name named.conf

Alternatively we can be more specific if we know under which directory such file might be located at

​# find /usr -name named.conf

Find file that are less or greater than a given size

less than 4096 bytes

# find . -type f -size -4096c

Greater than 4096 bytes

# find . -type f -size +4096c

Find files with a given permission

# find . -type f -perm 774

Find files with a given permission for the user

# find . -type f -perm -u+rwx

Find file with a given string

# find . -type f -exec grep -l "word" {} +

Find file given a criteria and then copy it to a given destination

# find /path/to/search/ -type f -name "filename" | xargs cp -t /target/path/

Replace string within a location, this will replace "old" string with "new" string, within every file recuresively under the current location

# find . -type f -exec sed -i 's/old/new/g' {} +

Locate

This command also searches files, however it is more common to find this command on RHEL based linux distributions

# locate myFile.txt