Find Files Quickly, Using Linux FIND Command

English

Find files quickly, using Linux FIND command.

Using a terminal window to search for files on a specific Linux server can be a bit of a challenge. However there are a few commands ( built-in tools ) like the find command, which helps us find things quickly.

This is good to know, especially for admins and even those that work, supportline for a VAN.

Find files quickly, using Linux FIND command.

1. The FIND command:
A powerful CLI tool for searching and locating files whose names match simple patterns, in a directory or hierarchy. Now using this tool is simple, just provide a starting point like the top of a directory and this is where the search will begin.

Then, you can specify an expression that can be composed of tests, actions, options and operators, which describes how to match files and what to do with the files that were matched.

The FIND command supports multiple options to locate files using attributes, such as date, file type, groups, permissions, users, size and others.

Working example 1 - Finding a file:

find ./Documents -name Darkweb.txt
Press Enter and view the result.

find ./Documents -name Darkweb.txt
./Documents/Darkweb.txt

Working example 2 - Deleting a file:
How to delete a file using the find command, you need to pass the --delete option.

find ./Documents -name Darkweb.txt --delete
Press Enter and view the result.

Working example 3 - Get confirmation before delete file:

find ./Documents -name Darkweb.txt -exec rm -i {} \;
Press Enter and view the result.

Working example 4 - Find a Directory:

find ./Documents -type d -name Documents
Press Enter and view the result.

Working example 5 - How to find files by modification time:

To find files that has been modificated you need to use the -mtime option followed by the number of days to look for. The number can be a positive or negative value. A negative value equates to less then so -1, will find files modified within the last day. Likewise +1 will find files modified more than one day ago.

find ./documents -mtime -1
Press Enter and view the result.

Working example 6 - How to find files modified one day ago:

find ./documents -mtime +1
Press Enter and view the result.

Working example 7 - How to find files by permission:

To find files by permission you need to use the -perm option and pass the value you want to search for.

find ./Documents -perm 777

Working example 8 - How to find files by modification time:

To find files by modification time use the -mtime option, followed by the number of days to look for using a positive or negative value. A negative value equates to less then so -1 will find files modified within the last day. Similarly +1 will find files modified more than one day ago or 30 days, just change the value.

find ./Documents -mtime -1

Working example 9 - How to find and operate on files:

To find and operate on files, use the -exec option. This allows a command to be executed on the files that are found.

find ./Documents -type f -name bar -exec chmod 777 {} \;

Working example 10 - How to search for text within multiple files:

You can combine find command with exec to search for text within multiple files. In the example, the word Linux is searched for.

find ./ -type f -name "*.md" -exec grep 'linux'  {} \;

The Manual

 

Library categories: 

Games For Linux

Windows has always been the preferred platform for gaming, but after STEAM's interest in Linux more game developers are making their games natively available for Linux.

Disclaimer

All information on this website is published in good faith and for general educational purposes and for use in safe testing environments only. While linuxexperten.com strives to make the information on this site as accurate as possible, linuxexperten.com does not warrant its completeness, reliability and accuracy.

We are not responsible for any losses or damages associated with the use of our website. While we strive to provide only links to useful websites, we have no control over the content of these sites and links to other sites do not constitute a recommendation for all content contained on these websites.

 

Site Information

This is a professional review site that receives compensation from the companies whose products reviewed. Each service or product are thoroughly tested and given high marks if considered to be the very best. Independently owned and the opinions expressed here are no one elses.

 

Limited Time Offers

Coming soon...