HomeLinux35 Sensible Examples of Linux Discover Command

35 Sensible Examples of Linux Discover Command


The Linux discover command is among the most essential and regularly used command-line utilities in Unix-like working techniques. The discover command is used to seek for and find a listing of information and directories primarily based on the circumstances you specify, matching the arguments.

The discover command supplies a wide selection of choices, permitting customers to leverage it in numerous circumstances. It empowers people to seek for information primarily based on a large number of standards, together with permissions, customers, teams, file varieties, dates, sizes, and numerous different parameters.

On this article, we’ll current you with 35 of essentially the most generally used examples of Discover Instructions in Linux. We have now divided this part into 5 components, overlaying the utilization of the discover command from primary to superior ranges.

Half I – Fundamental Discover Instructions for Discovering Information with Names

In the case of discovering information with particular names, the discover command provides a variety of choices to streamline the method. Listed below are some primary discover instructions for finding information primarily based on their names.

1. Discover Information Utilizing Identify in Present Listing

Discover all of the information whose identify is tecmint.txt in a present working listing.

# discover . -name tecmint.txt

./tecmint.txt

2. Discover Information Below Dwelling Listing

Discover all of the information beneath /residence listing with the identify tecmint.txt.

# discover /residence -name tecmint.txt

/residence/tecmint.txt

3. Discover Information Utilizing Identify and Ignoring Case

Discover all of the information whose identify is tecmint.txt and incorporates each capital and small letters in /residence listing.

# discover /residence -iname tecmint.txt

./tecmint.txt
./Tecmint.txt

4. Discover Directories Utilizing Identify

Discover all directories whose identify is Tecmint in / listing.

# discover / -type d -name Tecmint

/Tecmint

5. Discover PHP Information Utilizing Identify

Discover all php information whose identify is tecmint.php in a present working listing.

# discover . -type f -name tecmint.php

./tecmint.php

6. Discover all PHP Information within the Listing

Discover all php information in a listing.

# discover . -type f -name "*.php"

./tecmint.php
./login.php
./index.php

Half II – Discover Information Primarily based on their Permissions

Listed below are some examples of discover instructions for locating information primarily based on their permissions.

7. Discover Information With 777 Permissions

Discover all of the information whose permissions are 777.

# discover . -type f -perm 0777 -print

8. Discover Information With out 777 Permissions

Discover all of the information with out permission 777.

# discover / -type f ! -perm 777

9. Discover SGID Information with 644 Permissions

Discover all of the SGID bit information whose permissions are set to 644.

# discover / -perm 2644

10. Discover Sticky Bit Information with 551 Permissions

Discover all of the Sticky Bit set information whose permission is 551.

# discover / -perm 1551

11. Discover SUID Information

Discover all SUID set information.

# discover / -perm /u=s

12. Discover SGID Information

Discover all SGID set information.

# discover / -perm /g=s

13. Discover Learn-Solely Information

Discover all Learn-Solely information.

# discover / -perm /u=r

14. Discover Executable Information

Discover all Executable information.

# discover / -perm /a=x

15. Discover Information with 777 Permissions and Chmod to 644

Discover all 777 permission information and use the chmod command to set permissions to 644.

# discover / -type f -perm 0777 -print -exec chmod 644 {} ;

16. Discover Directories with 777 Permissions and Chmod to 755

Discover all 777 permission directories and use the chmod command to set permissions to 755.

# discover / -type d -perm 777 -print -exec chmod 755 {} ;

17. Discover and Take away Single File

To discover a single file referred to as tecmint.txt and take away it.

# discover . -type f -name "tecmint.txt" -exec rm -f {} ;

18. Discover and take away A number of File

To seek out and take away a number of information similar to .mp3 or .txt, then use.

# discover . -type f -name "*.txt" -exec rm -f {} ;

OR

# discover . -type f -name "*.mp3" -exec rm -f {} ;

[ You might also like: 4 Useful Tools to Find and Delete Duplicate Files in Linux ]

19. Discover all Empty Information

To seek out all empty information beneath a sure path.

# discover /tmp -type f -empty

20. Discover all Empty Directories

To file all empty directories beneath a sure path.

# discover /tmp -type d -empty

21. File all Hidden Information

To seek out all hidden information, use the under command.

# discover /tmp -type f -name ".*"

Half III – Search Information Primarily based On House owners and Teams

Listed below are some examples of discover instructions for locating information primarily based on homeowners and teams:

22. Discover Single File Primarily based on Person

To seek out all or single information referred to as tecmint.txt beneath / root listing of proprietor root.

# discover / -user root -name tecmint.txt

23. Discover all Information Primarily based on Person

To seek out all information that belong to person Tecmint beneath /residence listing.

# discover /residence -user tecmint

24. Discover all Information Primarily based on Group

To seek out all information that belong to the group Developer beneath /residence listing.

# discover /residence -group developer

25. Discover Specific Information of Person

To seek out all .txt information of person Tecmint beneath /residence listing.

# discover /residence -user tecmint -iname "*.txt"

Half IV – Discover Information and Directories Primarily based on Date and Time

Listed below are some examples of discover instructions for finding information and directories primarily based on date and time.

26. Discover Final 50 Days Modified Information

To seek out all of the information that are modified 50 days again.

# discover / -mtime 50

27. Discover Final 50 Days Accessed Information

To seek out all of the information that are accessed 50 days again.

# discover / -atime 50

28. Discover Final 50-100 Days Modified Information

To seek out all of the information that are modified greater than 50 days again and fewer than 100 days.

# discover / -mtime +50 –mtime -100

29. Discover Modified Information in Final 1 Hour

To seek out all of the information that are modified within the final 1 hour.

# discover / -cmin -60

30. Discover Modified Information in Final 1 Hour

To seek out all of the information that are modified within the final 1 hour.

# discover / -mmin -60

31. Discover Accessed Information in Final 1 Hour

To seek out all of the information that are accessed within the final 1 hour.

# discover / -amin -60

Half V – Discover Information and Directories Primarily based on Dimension

Listed below are some examples of discover instructions for finding information and directories primarily based on dimension.

32. Discover 50MB Information

To seek out all 50MB information, use.

# discover / -size 50M

33. Discover Dimension between 50MB – 100MB

To seek out all of the information that are higher than 50MB and fewer than 100MB.

# discover / -size +50M -size -100M

34. Discover and Delete 100MB Information

To seek out all 100MB information and delete them utilizing one single command.

# discover / -type f -size +100M -exec rm -f {} ;

35. Discover Particular Information and Delete

Discover all .mp3 information with greater than 10MB and delete them utilizing one single command.

# discover / -type f -name *.mp3 -size +10M -exec rm {} ;

That’s it, We’re ending this publish right here, In our subsequent article, we’ll talk about different Linux instructions in-depth with sensible examples. Tell us your opinions on this text utilizing our remark part.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments