Skip to main content
Video Man Pages

find — Video Man Page

By April 11, 2013September 12th, 2022No Comments

If you too, still haven’t found what you are looking for then perhaps you need to brush up on your Linux command line skills and review the options for find. That’s enough of the gags so let’s get straight into it and look at what we can use find for:

find -type f

The Linux command find will search my current directory and below for files. First we need to choose which directory to search, in this case it is left blank so we will use the current directory. We can also use the type argument to search for links, directories, block devices etc.

The results that we get back are many as we are searching the current directory and all sub directories. The limit the search to the current directory we can add in the maxdepth 1 option:

find -maxdepth 1 -type f

Now we see less as we look only in the current directory. Adding additional options will also reduce the search results if we use the default ANDing. Here we look for executable files:

find -maxdepth 1 -type f -executable

Next we look at a system administration issue we may find after users have been deleted. The command userdel will delete the home directory and mail files of the user, but it is will not search the file-system for other files left behind. You may want to keep these files but you may also not want to. It is simple to delete with find:

sudo find / -uid 1001 -delete

Here we look for files owned by the USER ID 1001 and delete them. To extend this past we delete. We can use the -exec option which then acts as a mini for loop. In the next example we move all the txt files into the txt directory:

find -maxdepth 1 -name “*.txt” -exec mv {} ./txt/ ;

Enjoy the video…