iEntry 10th Anniversary LinuxHaxor WH MH

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:

$ locate -i searchstring

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:

$ locate -i kdenlive.desktop


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:

$ find <where to start searching> <search criteria> <actions to take>

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:

$ sudo find / -type f -mmin -10

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.

$ find ~ -iname "*xxx*" -exec mv -v {} /media/pr0n/ \;

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.


  • AnonymousNo Gravatar

    July 14th, 2009 09:07

    scp -r nixie@linuxhaxor.net:/media/pr0n ~;

  • ScottNo Gravatar

    July 14th, 2009 09:08

    Pron lol. Nice tutorial.

  • AndrewLNo Gravatar

    July 14th, 2009 17:23

    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 {} \;

  • e0No Gravatar

    July 14th, 2009 17:57

    “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.

  • GarrettNo Gravatar

    July 14th, 2009 19:06

    I prefer slocate and updatedb, or slocate -u.

    Can’t teach an old dog new tricks I guess.

  • hornicatorNo Gravatar

    July 14th, 2009 20:09

    Maybe I’ll have more luck teaching my friends with this.

    Is it just me or is CLI way faster?

  • scroolooseNo Gravatar

    July 15th, 2009 04:31

    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

  • BrianNo Gravatar

    July 15th, 2009 07:17

    Some very useful commands there…. aardvarks and blondes, lol.

  • DrMelonNo Gravatar

    July 15th, 2009 09:05

    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.

  • NixieNo Gravatar

    July 15th, 2009 15:20

    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. =)

  • PhillNo Gravatar

    July 20th, 2009 11:05

    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.

  • NixieNo Gravatar

    July 21st, 2009 09:35

    Everything you wanted to know about my setup, and more:

    http://nixiepixel.com/blog/blog7.php/nixie-pixel-faq

  • The HulkNo Gravatar

    August 9th, 2009 11:40

    Thanks Nixie, now how about the grep command?

  • otopsi videolarıNo Gravatar

    August 18th, 2009 18:24

    thanks its very good information for us ı like it

  • aşk videolarıNo Gravatar

    August 19th, 2009 18:20

    thanks. but i’d like to know somethingabout grep command.

  • hhhNo Gravatar

    August 20th, 2009 20:52

    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.

  • hhhNo Gravatar

    August 20th, 2009 21:01

    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.

  • PeteNo Gravatar

    September 20th, 2009 15:24

    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

  • RafaelNo Gravatar

    November 29th, 2009 00:02

    you have such a lovely voice ;)

  • AmauriNo Gravatar

    December 1st, 2009 19:33

    Very good video

    Congratulations

    BrAzil ˜!

  • Buy Term PaperNo Gravatar

    December 30th, 2009 03:41

    I truly enjoyed reading it. Waiting for some more great articles like this from you in the coming days

  • freakwareNo Gravatar

    January 3rd, 2010 22:24

    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

  • SKuLL-HacKeRNo Gravatar

    January 7th, 2010 13:27

    G00d Job Nixie

    http://www.s3curity-art.com

    Welcom

    Regards

  • trustnooneNo Gravatar

    April 12th, 2010 18:07

    Doesn’t nautilus have a pretty good search also, although I will admit this terminal way is way more powerful, cheers

  • SimonNo Gravatar

    August 14th, 2010 17:14

    Anyway, can’t find any article on this blog. How to search for your articles about the Acer Aspire One?

  • çeviri bürolarıNo Gravatar

    September 1st, 2010 03:43

    An interesting approach to the topic, but I disagree.

Trackbacks

  1. Nicholas Sanders (linuxfiend) 's status on Tuesday, 14-Jul-09 23:39:56 UTC - Identi.ca
  2. Linux Tips Aggregated #1 | Three Wise Men
  3. Four Reasons Twitter’s New Promoted Tweets Advertising Will | twittersRus.info

Subscribe without commenting


Leave a Reply

Note: Any comments are permitted only because the site owner is letting you post, and any comments will be removed for any reason at the absolute discretion of the site owner.


  • depression self help
  • buy ultram
  • stomache ulcers
  • vitamin for hair loss
  • breast cost enhancement
  • apotheke online
  • diflucan male
  • simple remedy obesity
  • male sexual arousal
  • help for heart failure
  • medical discount international drug
  • soma information
  • compare viagra cialis
  • headache help
  • valium on line
  • heart attack causes preventions cure
  • order medrol
  • allegra side effects
  • cialis 5
  • antibiotic men
  • drug stop smoking
  • natural weight loss supplement
  • phentermine no doctor
  • tramadol use
  • alternative arthritis remedies
  • online levitra
  • pharmacy phentermine
  • heart rates in cardiac arrhythmias
  • drugs for rhuematiod arthritis
  • new antidiabetic drugs
  • hair regrowth
  • non-prescription treatments for erectile dysfunction
  • stop psoriasis itching
  • cialis cheap prices
  • hiv medications
  • womens health
  • buy online tramadol
  • valium 5 mg
  • treatment of arthritis
  • medication for cats
  • phentermine no prescription fast delivery
  • diet pill side effects
  • tramadol cod
  • rate weight loss products
  • skin infections antibiotics
  • pet treats available
  • tips for gaining muscle mass
  • no prescription cialis
  • psoriasis on the face
  • buy pain med
  • online phamacy viagra
  • strengthen immune system
  • buy levitra no prescription
  • pfizer viagra
  • pain prescription online
  • buy cialis delived next day
  • prevent pregnancy
  • cheapest phentermine online free shipping
  • woman sexual enhancement
  • side effects of blood pressure tablets
  • vitamin c deficiency
  • heart failure online
  • canada drugs on line
  • light cure for pain
  • high blood pressure cause
  • generic for actos
  • generic for nexium
  • alcohol celebrex
  • pills for weight loss
  • drugs for adhd
  • prescription pills
  • buy alpha lipoic acid
  • new smoking cessation drugs
  • order cialis jelly
  • generic viagra
  • ambien withdrawl symptoms
  • weight loss ideas
  • all natural breast enhancers
  • oral chlamydia
  • cialis by mail
  • allergy sinus tablets
  • anxiety meds online
  • treat muscle spasms
  • pediatric diarrhea
  • buy phentermine cheap
  • 100mg tramadol
  • menopause tablets
  • the cialis
  • gout cures
  • verapamil
  • medication to help stop smoking
  • xanax and drug testing
  • latest treatment for heart attack
  • viagra information
  • online pharmacies pain meds
  • cheap body building supplement
  • treatment for vomiting
  • body building diet nutrition
  • drug free high blood pressure help
  • cialis 30mg
  • non prescription drugs
  • cheap levitra
  • penis enlarger
  • celexa no prescription
  • cheap pharmacy no prescription
  • medication on line prescription
  • diarrhea children treatment
  • avodart prescription
  • asthma facts
  • back acne and dry skin
  • mebendazole tablets
  • body building online course
  • buy cheap low blood sugar
  • alternative arthritis remedy
  • cheap depression medications
  • anti depression medicine
  • buy tramadol online without prescription
  • does clomid work
  • osteoporosis and bone health
  • irritable bowel syndrome treatments
  • stopping diabetes
  • metabolic weight loss
  • bupropion pharmacy
  • antifungal drug
  • otc scabies cream
  • treatment for stroke
  • severe neck muscle spasm
  • drug zolpidem
  • canadian pharmacy drug
  • natural hair loss treatment
  • walmart pharmacy
  • headache help
  • bust enlarge
  • flu shots
  • new medicines for depression
  • viagra cialis levitra comparison
  • valium and xanax
  • baby flu
  • klonopin blood pressure
  • ambien no prescription
  • soma vicodine
  • levitra tablet
  • viagra in britain
  • blood pressure medication names
  • depression effexor
  • levaquin online
  • sex with levitra
  • treatment of heart attacks
  • claritin for allergies
  • viagra by mail
  • weight loss supplement
  • stomach pains and gas constipation
  • viagra cialis levitra
  • levitra canada
  • dose nexium
  • discount viagra in the usa
  • muscle building food
  • help for snoring
  • ranitidine interaction
  • itching ointment
  • severe acne treatments
  • different anti depressants
  • eye allergy medicine
  • buy vitamins
  • alternative treatment joint pain
  • flaxseed oil
  • medicines used for headaches
  • how heart rate regulated
  • muscle pain treatment
  • speed of viagra
  • cheapest phentermine online
  • buy phentermine online without a prescription
  • united pharmacy
  • buying pain relievers pills
  • body building diets
  • what valium does
  • online pharmacy mexico
  • professional viagra cheap
  • age of anxiety
  • drugs for male health
  • buying medications online without a prescription
  • viagra cialis on line
  • what does a valium look like
  • pharmacy mexico
  • buy soma drug
  • what burns body fat
  • new adhd drugs
  • prednisone prednisolone
  • online viagra
  • valium 5 mg
  • lipitor and zocor
  • powerful weight loss
  • 20mg levitra
  • anti obesity
  • pet medications
  • generic name viagra
  • long lasting condoms
  • bronchitis treatment in pregnancy
  • phentermine with hoodia
  • obesity care