Created
February 22, 2019 14:04
-
-
Save Sakib37/acba8d937951b7f761ac8ca3604ba53e to your computer and use it in GitHub Desktop.
useful find commands in Linux
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################################################################ | |
How To Use Find and Locate to Search for Files on a Linux | |
################################################################################ | |
Source : www.digitalocean.com/community/tutorials/how-to-use-find-and-locate-to-search-for-files-on-a-linux-vps | |
======= | |
BY NAME: | |
======== | |
find -iname "FILENAME" # 'iname' is to ignore case sensitivity | |
find -not -name "FILENAME_TO_AVOID" # Find all files expecpting a particular file | |
or | |
find \! -name "FILENAME_TO_AVOID" | |
======= | |
BY TYPE: | |
======== | |
find -type type_descriptor FILENAME | |
Some most common descriptors: | |
f: regular file | |
d: directory | |
l: symbolic link | |
c: character devices | |
b: block devices | |
======= | |
BY SIZE: | |
======== | |
find / -size 50c # File size 50 bytes in root direcotry | |
find / -size +70M # File size more than 70 MB in root directory | |
find / -size -10G # File size less than 10 GB in root directory | |
These are some popular options: | |
c: bytes | |
k: Kilobytes | |
M: Megabytes | |
G: Gigabytes | |
b: 512-byte blocks | |
======= | |
BY TIME: | |
========= | |
-atime Access Time: Last time a file was read or written to. | |
-mtime Modification Time: Last time the contents of the file were modified. | |
-ctime Change Time: Last time the file's inode meta-data was changed. | |
find / -mtime 1 # Files modified 1 day ago | |
find / -atime -1 # Files accessed less than 1 day ago | |
find / -ctime +3 # Files changed more than 3 days ago | |
find / -mmin -1 ************ 'mmin' to specify minutes instead of days | |
find / -newer FILENAME ************ Newer files after FILENAME | |
======= | |
BY OWNER: | |
========= | |
find / -user syslog # Files owned by user syslog | |
find / -group shadow # Files owned by grop shadow | |
============== | |
BY PERMISSION: | |
============== | |
find / -perm 644 # Files that have permission 644 | |
find / -perm -644 # Files that have at least 644 permission | |
========= | |
BY DEPTH: | |
========= | |
Maximum depth of the search under the top-level search directory: | |
find -maxdepth num -name query | |
Minimum depth of the search under the top-level search directory: | |
find -mindepth num -name query | |
====================================== | |
Executing and Combining Find Commands: | |
====================================== | |
find find_parameters -exec command_and_params {} \; | |
find . -type d -perm 755 -exec chmod 700 {} \; # Find and change directory permission | |
================================================================================================================ | |
To chain different results together, you can use the "-and" or "-or" commands. The "-and" is assumed if omitted: | |
================================================================================================================ | |
find . -name file1 -or -name file2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment