Linux: Finding files using linux find command
This article will guide how to find files using linux find command under linux operating system. see below find command syntax:
find <search path> <file name> <action>
where,
search path is defind searching path.
file name is the file name that you want to find in searching path.
action is the operation you want to do for finded file in searching path
Find Command Examples
1. find files and print their full name
If you want to find out all “*.txt” files in /root directory,type:
find /root -name "*.txt"
outputs:
[root@devops ~]# find /root -name "*.txt" /root/.subversion/README.txt /root/foo.txt
If you want to find smb.conf file location located under /etc/ directory, type:
find /etc -name smb.conf
outputs:
[root@devops ~]# find /etc/ -name smb.conf /etc/samba/smb.conf
2. Finding files by modification time
If you want to find files that modified within a specified time, such as accessed more that 7 days, type:
find . -type f -atime +7
find files that accessed file less than 7 days, type:
find . -type f -atime -y
find files that modified file more than 7 days, type:
find . -type f -mtime +7
find files that modified file less that 7 days, type:
find . -type f -mtime -7
Find all set suer id files
type:
find . -type f -perm +u=s
Find all set group id files
type:
find . -type f -perm +g=s
Finding all large files
if you want to find all files that size is more than 10MB, type:
find . -type f -size +10M
outputs:
[root@devops ~]# find / -type f -size +10M /boot/initramfs-0-rescue-d028c143166f4a4aab2318b32b9b35d5.img /boot/initramfs-3.10.0-123.el7.x86_64.img /boot/initramfs-3.10.0-123.el7.x86_64kdump.img /dev/shm/pulse-shm-2603296743 /dev/shm/pulse-shm-4152478638 /dev/shm/pulse-shm-2492214053 /dev/shm/pulse-shm-2108041840 /dev/shm/pulse-shm-1715249868 /dev/shm/pulse-shm-972989635 /dev/shm/pulse-shm-3767301141 /proc/kcore