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

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

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.


  • adhd in children
  • toprol online
  • prozac pharmacy
  • cialis capsules 10
  • cialis cheapest online prices
  • ways to control appetite
  • upper left abdominal pain
  • lamisil generic
  • health vitamins
  • erythromycin pregnancy
  • anti depression
  • prevacid medication
  • aleve dosage
  • singulair generic
  • arthritis information
  • hoodia pill
  • buy zyrtec
  • bph medications
  • medication prices
  • buy mojo maxx
  • online celexa
  • cialis discount generic
  • fluconazole
  • general health care
  • lower blood pressure diet
  • cymbalta dosage
  • generis cialis
  • buy vigrx
  • reducing blood pressure
  • heart failure symptoms
  • reduce swelling methods
  • weight loss tablet
  • pain pills cheap
  • natural weight loss remedies
  • light cure for pain
  • drug discount codes
  • cat infections
  • internal human parasites
  • medicine paxil
  • flu treatment
  • prescription norvasc
  • life after a heart attack
  • buy pain pills on line
  • nausea and vomiting with cancer
  • top acne treatments
  • muscle burning pain
  • erectile dysfunctions
  • treatment of bph
  • online pharmacy carisoprodol
  • cheapest cialis online
  • cure for pain
  • powerful weight loss
  • natural dog products
  • tips for lowering blood pressure
  • flomax side effects
  • online drugs
  • medicine that prevents blood clots
  • fat weight loss products
  • buy canada levitra
  • altace generic
  • new depression treatments
  • levitra tab 20mg
  • on line drug store
  • right heart failure
  • buy prescription medication online
  • spots on face
  • diet pills
  • new treatment for osteoporosis
  • swelling
  • internet drugs
  • india pharmacies
  • cialis benefits
  • order no prescription diet pill
  • natural breast enhancer
  • aids for sleeping
  • buy viagra in canada
  • online pharmacy no prescription needed
  • generic cialis soft tabs
  • type 2 diabetes
  • improve sleep
  • order prilosec
  • online diazepam
  • treatment for hepatitis b
  • chlamydia cures
  • chlamydia and treatment
  • pet health problems
  • antidiabetic drug
  • cialis 5mg
  • buy asthma meds
  • treatments for cancer
  • sleep disorders remedy
  • cancer drugs
  • low blood sugars
  • diet drug online
  • infection lung
  • abilify 10mg
  • heart pain chest
  • norvasc cheap
  • viagra viagra
  • fitness muscle online
  • body building diets
  • male body building
  • cialis blood pressure
  • xanax dosages
  • prices soft tab cialis
  • order viagra online
  • viagra women
  • sleep disorders medicine
  • how to lower your cholesterol
  • treatment for alzheimer's disease
  • abilify 10mg
  • improving immune system
  • drugs that treat high blood pressure
  • cheap generic viagra online
  • travellers diarrhea
  • natural dog health
  • drugs for adhd
  • reduce swelling methods
  • levitra side effects
  • better erection
  • drugs for pain
  • vitamin b-12
  • flomax generic
  • serevent generic
  • buying medication
  • online ativan
  • help with weight loss
  • clonazepam .5mg vs valium
  • adhd products
  • weight loss challenge
  • albuterol proventil
  • way to improve skin
  • where can i get pain medication
  • drug information loss weight
  • wellbutrin sr
  • osteoporosis calcium drug
  • weight loss for kids
  • building your body
  • how to clear acne
  • canada online pharmacy viagra
  • vitamin supplement websites
  • symptoms of fluid retention
  • constipation pain
  • natural cure arthritis
  • flu vaccine
  • revatio drug
  • drugs valium
  • medical discount international drug
  • penis enlargement result
  • buy prescription drugs with no prescription
  • natural health for dogs
  • canada women health
  • buy online viagra
  • cialis for women
  • bacterial infection treatment
  • buy discount viagra online
  • gernic viagra
  • revatio effects
  • allergies singulair
  • diet and weight loss
  • bust increase
  • approved canadian pharmacy
  • building muscles
  • relief from arthritis pain
  • weight loss after birth
  • prevention of pregnancy
  • generic kamagra
  • high blood pressure elderly
  • antibiotics diarrhea
  • flu treatment alternative
  • prevent blood clots
  • how to treat depression
  • cialis buy cialis online
  • parasite killer human
  • med weight loss
  • blood pressure treatment drugs
  • discount prescription medications
  • progesterone clomid
  • cheap diet pills that work
  • how to sperm more
  • irritable bowel syndrome cures
  • strattera pharmacy
  • anti malaria drugs
  • cheap anxiety pills
  • buy tetracycline
  • nolvadex 20mg
  • women's health products
  • teeth whitening product
  • anxiety cure
  • acne care
  • weight loss disorders
  • recurrent urinary tract infection
  • cheap medicine
  • diabetes treatment
  • levitra warfarin
  • antibiotics chlamydia
  • natural supplements for mens health
  • buy avodart
  • osteoporosis calcium drug
  • pain relief product