Linux Find command and it's usage with example.

Linux Find command and it's usage with example.

Find Command in Linux :

The Linux Find Command is used to search and locate list of files and directories in Linux File system. You can find files on behalf of users, permissions, groups, date, size, file type and other possible criterias.

Examples of Find commands :

1. Find Files Using Name of file in Current Directory
-----
# find . -name hoststud.txt
-----

2. Find Files Under Home Directory
-----
# find /home -name hoststud.txt
-----

3. Find Files Using Name and Ignoring Case
-----
# find /home -iname hoststud.txt
-----

4. Find Directories Using Name
-----
# find / -type d -name hoststud
-----

5. Find PHP Files Using Name
-----
# find . -type f -name hoststud.php
------

6. Find all PHP Files in Directory
------
# find . -type f -name "*.php"
------

7. Find Files With 777 Permissions
------
# find . -type f -perm 0777 -print
------

8. Find Files Without 777 Permissions
------
# find / -type f ! -perm 777
------

9. Find SGID Files with 644 Permissions
-------
# find / -perm 2644
-------

10. Find Sticky Bit Files with 551 Permissions
-------
# find / -perm 1551
-------

11. Find SUID Files
-------
# find / -perm /u=s
-------

12. Find SGID Files
-------
# find / -perm /g=s
-------

13. Find Read Only Files
-------
# find / -perm /u=r
-------

14. Find Executable Files
-------
# find / -perm /a=x
-------

15. Find Files with 777 Permissions and Chmod to 644
-------
# find / -type f -perm 0777 -print -exec chmod 644 {} \;
-------

16. Find Directories with 777 Permissions and Chmod to 755
-------
# find / -type d -perm 777 -print -exec chmod 755 {} \;
-------

17. Find and remove single File
-------
# find . -type f -name "hoststud.txt" -exec rm -f {} \;
-------

18. Find and remove Multiple File
-------
# find . -type f -name "*.pdf" -exec rm -f {} \;
-------

19. Find all Empty Files
-------
# find /tmp -type f -empty
-------

20. Find all Empty Directories
-------
# find /tmp -type d -empty
-------

21. File all Hidden Files
-------
# find /tmp -type f -name ".*"
-------

22. Find Single File Based on User
-------
# find / -user root -name hoststud.txt
-------

23. Find all Files Based on User
-------
# find /home -user hoststud
-------

24. Find all Files Based on Group
-------
# find /home -group root
-------

25. Find Particular Files of User
-------
# find /home -user hoststud -iname "*.png"
-------

26. Find Last 5 Days Modified Files
-------
# find / -mtime 5
-------

27. Find Last 7 Days Accessed Files
-------
# find / -atime 7
-------

28. Find Last 1-10 Days Modified Files
-------
# find / -mtime +1 –mtime -10
-------

29. Find Changed Files in Last Half an Hour
-------
# find / -cmin -30
-------

30. Find Modified Files in Last 5 Hour
-------
# find / -mmin -300
-------

31. Find Accessed Files in Last 2 Hour
-------
# find / -amin -120
-------

32. Find 10MB Files
-------
# find / -size 10M
-------

33. Find Size between 5MB – 10MB
-------
# find / -size +5M -size -10M
-------

34. Find and Delete 10MB Files
-------
# find / -size +10M -exec rm -rf {} \;
-------

35. Find Specific Files and Delete
-------
# find / -type f -name *.xyz -size +5M -exec rm {} \;
-------
Author
bhawanisingh
Views
1,627
First release
Last update
Rating
0.00 star(s) 0 ratings
Top