Unleash The Power of the Find Command
Unfortunately in Linux, certainly Ubuntu, the default GUI file search is not always useful. With just a small amount of patience you can find files quickly and easily using the command line, and your options for this are really powerful if you want to learn a bit about it.
The easy, quick command is called "locate." To use this command at the terminal you simply type:
This will search for all files and directories with "searchstring" in the name, and -i means the search is not case sensitive (i.e. it will find searchstring, Searchstring, sEaRcHsTrInG, and so on). The results are instantaneous because the system has created a database (also known as an index) to tell you where files are located. The only problem is that newly created or moved files may not be found correctly until the next database update, and you don’t have many options to choose from for your search. (forcing locate to update the database/index is done with $ sudo updatedb, and it doesn’t take a lot of time)
Example:
There is a much more powerful command available to you called "find." You can tell "find" where to look, what criteria to use in its search, and what actions to take once you have found what you are looking for. The syntax for "find" is:
If you don’t add any parameters, find will default to searching the current working directory (or "."), uses no search criteria (defaults to showing all files), and -print (which, despite its name, displays, or "prints," the results on screen) as the only action to take.
Two examples:
This example will find (starting at the root directory, or /, and recursively search subdirectories) all normal files (-type f means normal files, without this it will find normal files + special files + directories) which were modified less than ten minutes ago (-mmin -10), and then display the results for you. This would be useful if you know you edited a file recently but don’t know where you put it, or have to find a log file for a program that crashed. I use sudo here because find does not search files/directories that the current user does not have permissions for, and it will return error messages. However, you should use caution when using sudo.
This will find everything in your home directory (~) with a name, case insensitive (-iname), containing xxx ("*xxx*") and execute (-exec) a move (mv) of the results ({}) to /media/pr0n/ ( \; is required by -exec to show the end of the command to be executed). So all your downloaded porn will be moved to the same place. mv -v displays the results of the move command with (-v)erbose messages. Another warning with -exec, though it is powerful, when used without care you can overwrite your whole home directory or whole disk – so be careful!
For those of you who simply can’t do without a GUI, you can find the program catfish in the repositories – this enables you to run both locate and find from a graphical front-end, but it is very limited in options. Think of it as an equivalent to Windows Search. If you want the full power of find, you’ll need to run it from the command line!
A big thanks to BigWhale (http://www.twm-kd.com/) for helping me find my footing with the find command.

Follow me on Twitter and check out my blog.
iEntry 10th Anniversary
LinuxHaxor
WH
MH
scp -r nixie@linuxhaxor.net:/media/pr0n ~;
Pron lol. Nice tutorial.
The find command is amazingly helpful, it’s also much faster then using ls if you are in a directory with a TON of files or if the system is bogged down.
Some of our servers store each message as it’s own file while the message is in queue, so to find out how many files are in a particular folder I just run this:
find /path/to/the/folder -maxdepth 1 | wc -l
Or if I want to clear out some space real fast I’ll remove log files older then a certain number of days:
find /var/log -type f -mtime +10 -exec rm {} \;
“find ~ -iname “*xxx*” -exec mv -v {} /media/pr0n/ \;” will lose files if they have the same name and if mv is not aliased to “mv -i” (or possibly to “mv -b”), since by default mv does not prompt for overwriting unless the destination file does not have the write permission set.
~/xxxfile1
~/dir/xxxfile1
First ~/xxxfile1 is moved, then ~/dir/xxxfile1 is moved, overwriting the file moved before it.
I prefer slocate and updatedb, or slocate -u.
Can’t teach an old dog new tricks I guess.
Maybe I’ll have more luck teaching my friends with this.
Is it just me or is CLI way faster?
holy fuck sweetheart, are you aware that hitting CTRL-L is far superior to closing your terminal every time you want to demo a new command? im going to assume that you are in fact pr0 and were just showing off your fucking dynamite compiz effects
fyi there are shit loads of ctrl-foo key combos that are helpful, which is why i have to avoid staring at my ctrl key at work lest i get an enormous erection
Some very useful commands there…. aardvarks and blondes, lol.
Any chance of a tutorial on grep?
I know it’s useful, it’s just using it stumps me.
Also, a fun thing to do is to wget a webpage to /dev/audio.
Makes a weird squeaky-crackle sound, just like the old modems.
Thanks for the advice on not having to close the terminal. I just do it because I record the video in clips, not as one segment, so it’s easier to work with when it comes to the editing process. =)
Nice…thanks for the tut. I always have to look up the find man page.
LOVE your theme. Can you give some details on how you customized it? Love the ‘poofing’ of the menu and shell when you pick an item to launch.
Everything you wanted to know about my setup, and more:
http://nixiepixel.com/blog/blog7.php/nixie-pixel-faq
Thanks Nixie, now how about the grep command?
thanks its very good information for us ı like it
thanks. but i’d like to know somethingabout grep command.
I came back to Linux/Ubuntu after a 2 year hiatus. I’ve always found finding folders frustrating on Ubuntu (“f”s, they come easily with this subject), so learning the find command was very helpful, thank you. I test nightly builds of Firefox and used find to discover all the mozilla/firefox directories on my system (much more of them than on windows) but was surprised to see what I thought were previously deleted folders hidden in /root/.local/share/Trash. After some Googling, I’ve learned that Trash and delete are 2 seperate things on Linux, but I’m still confised. Would those files stay there indefinitely if I didn’t actually delete them? What’s the best way to find hidden cruft in Ubunt? Hope I get a response. Nice website, bookmarked. Off to learn about catfish, good luck with the soul search, been doing that quite a bit lately.
Woah, just saw your installing themes video on youTube, and I don’t get why your extracting and using terminal. What’s wrong with just downloading the *tar.gz, then System>Preferences>Appearance>Theme>Install…??? After that you can delete the original download.
Hello Nixie,
Just wanted to throw in my .02 cents worth.
Catfish is light weight program but uses or or more back ends.
The back end programs to index your data. Some people don’t want
the contents of their PDF’s, CHM’s, TXT files indexed. There is an
application that is a front end to the find command; its called:
“searchmonkey”. Things that people may or may not like about it:
1) It doesn’t index the contents of your files (good thing IHMO)
2) It’s light weight and doesn’t require any back ends.
3) There are no services running in the background.
4) Can use complex regex searches.
It’s in your Ubuntu / Debian repo’s.
PS: If you use Ubuntu or Gnome; there is another tool called:
gnome-search-tool
Should be part of a Gnome install I think…
Regards
you have such a lovely voice ;)
Very good video
Congratulations
BrAzil ˜!
I truly enjoyed reading it. Waiting for some more great articles like this from you in the coming days
Hi Nixie you seem to know a lot about this maybe you can help me with my problem.
I accidentally uninstalled python 2.6 from my ubuntu 9.10 and all my graphic interface disappeared and some programs functionality because of dependencies.
So I investigated how to reinstall python with the “aptitude” command line but I still don’t find the command line to connect my 3G Internet modem Please tell me you can help me! Thank you
G00d Job Nixie
http://www.s3curity-art.com
Welcom
Regards
Doesn’t nautilus have a pretty good search also, although I will admit this terminal way is way more powerful, cheers
Anyway, can’t find any article on this blog. How to search for your articles about the Acer Aspire One?
An interesting approach to the topic, but I disagree.