Linux -'Find' Knowledge Base - Exercise Bank

1. Find all the files under /home directory with name passwd :

First you have to create a file in the home directory here we created passwd

[root@192 Desktop]# find /home -name passwd -type f

2. Find all the files whose name is shadow in a /etc directory.

[root@192 Desktop]# find /etc -name shadow -type f

3. Find all the files whose name is fstab and contains both capital and small letters in /directory.

In this case we created fstab files with the {} operator

[root@192 Desktop]# find /directory/ -type f -name [A-Za-z]*fstab

4. Find all directories whose name is anaconda-ks.cfg in /directory.

[root@192 Desktop]# find /directory/ -type f -name anaconda-ks.cfg

5. Find all php files in your system and copy them to the /backup directory

[root@192 Desktop]# find /directory/ -type f -name *php -exec cp {} /backup/ \;

6. Find Files With 777 Permissions in system

[root@192 Desktop]# find / -type f -perm 777

7. Find all the SGID bit files whose permissions set to 644.

[root@192 Desktop]# find / -perm 2644 -type f

8. Find all the Sticky Bit set files whose permission are 551.

[root@192 Desktop]# find / -type f -perm 1551

9. Find all SUID set files.

[root@192 Desktop]# find / -type f -perm 4000

10. Find all SGID set files.

[root@192 Desktop]# find / -type f -perm 2000

11. Find all 777 permission files and use chmod command to set permissions to 644.

[root@192 Desktop]# find / -type f -perm 777 -exec chmod 644 {} \;

12. Find all 777 permission directories and use chmod command to set permissions to 755.

[root@192 Desktop]# find /testing/ -type d -perm 777 -exec chmod 755 {} \;

13. To find a single directory called “yp” and remove it.

[root@192 Desktop]# find / -type d -name yp -exec rm -rf {} \;

14. To find and remove multiple files such as .mp3 or .txt, then delete this files using rm command

[root@192 Desktop]# find /file/ -type f -name *.mp3 -exec rm {} \;

15. To find all empty files under /tmp directory

[root@192 Desktop]# find /tmp/ -type f -empty

16. To find all empty directories under /tmp directory

[root@192 Desktop]# find /tmp/ -type d -empty

17. To find all hidden files in /tmp

[root@192 Desktop]# find /tmp/ -type f -name '.*'

18. To find all files that belong to user student under /home directory.

[root@192 Desktop]# find /home/ -type f -user student

19. To find all or single file called student under / directory of owner student

[root@192 Desktop]# find / -type f -user student -name student

20. To find all the files which are modified 50 days back.

[root@192 Desktop]# find / -type f -mtime +50

21. To find all the files which are accessed 63 days back.

[root@192 Desktop]# find / -type f -atime +63

22. To find all the files which are modified more than 50 days back and less than 100 days.

[root@192 Desktop]# find / -type f -mtime +50 -mtime -100

23. To find all the files which are changed in the last 1 hour.

[root@192 Desktop]# find / -type f -cmin -60

24. To find all the files which are modified in the last 1 hour

[root@192 Desktop]# find / -type f -mmin -60

25. To find all the files which are accessed in the last 2 hour.

[root@192 Desktop]# find / -type f -amin -120

26. To find all 50MB files, use.

find / -type f -size 50M

27. To find all the files which are greater than 50MB and less than 100MB.

find / -type f -size +50M -size -100M

28. To find all 100MB files and delete them using one single command.

find / -type f -size 100M -delete

29. Find all .mp3 files with more than 10MB and delete them using one single command.

find / -type f -name "*.mp3" -size +10M -delete

30. Find the files which are owned by (local user) natasha and copy it to /backup directory.

[root@192 Desktop]# find / -type f -user natasha -exec cp {} /backup/ \;