5 Ways To Search For Files Using The Terminal


Editor’s Note: This is a guest post by an anonymous reader of this blog. Who goes by the name “Rand

_________________________________________________________

Today we will look at some of the common ways to search for files in Linux using the Terminal.

1) find : To search for files on the command line you can use the command “find”. The following is syntax for the “find” command:

find path criteria action

“path” - The section of the files system to search (the specific directories and all the sub directories). If nothing is specified the file system below the current directory is used.

“criteria” - The file properties.

“action” - Options that influence conditions or control the search as a whole, ie,
“–print”

2007-11-22-153941_1280x800_scrot

 

2) locate : The command “locate” is an alternative to the command “find -name”. The command find must search through the selected part of the file system, a process that can be quite slow. On the other hand, locate searches through a database previously created for this purpose (/var/lib/locatedb), making it much faster. The database is automatically created and updated daily. But change made after the update has been performed are not taken into account by locate, unless the database is updated manually using the command updatedb.

2007-11-22-154054_1280x800_scrot

 

3) whereis : The command “whereis” returns the binaries (option -b), manual pages (option -m), and the source code (option -s) of the specific command. If no options is used all the information is returned, if the information is available. This command is faster than “find” but is less thorough.

2007-11-22-154226_1280x800_scrot

 

4) which : The “which” command searches all paths listed in the variable PATH for the specific command and returns the full path of the command. the command is specifically useful if several version of a command exist in different directories and you want to know which version is executed when entered without specifying a path.

2007-11-22-154254_1280x800_scrot

 

5) type : The “type” command can be used to find out what kind of command is executed when command is entered - a shell built in command or an external command. The option -a delivers all instances of a command bearing this name in the file system.

2007-11-22-154354_1280x800_scrot

If you liked this article, please share it on del.icio.us, StumbleUpon or Digg. I’d appreciate it. :)


  • Binny V ANo Gravatar

    September 25th, 2008 11:40

    Also ‘grep’ - search for text inside files.

  • JulioHMNo Gravatar

    September 25th, 2008 21:40

    locate is da shit

  • elektronischNo Gravatar

    September 25th, 2008 21:47

    No slocate?

  • chmoderNo Gravatar

    September 25th, 2008 22:53

    locate is really nice but it can make your system very vulnerable.

  • TylerNo Gravatar

    September 25th, 2008 23:08

    Nice list– you forgot one thing:
    ” find * | grep [name] ”

    I always forget about ‘locate’ though, as my method takes forever :)

  • benNo Gravatar

    September 25th, 2008 23:43

    ls /etc | grep filename

    ls /etc | grep ‘[[:digit:]]\.d$’

    ls | grep ‘*\.txt’

  • John WatersNo Gravatar

    September 26th, 2008 06:31

    du -a | grep pattern can be quite handy as well, this is also the main way that files or resources are found in Plan 9

  • GlenNo Gravatar

    September 26th, 2008 20:46

    Don’t forget about the giveme command. that benchmarked 334% faster than slocate double piped to a grep input. e.g.

    giveme /etc/a/break/you/friggin/morons

  • medyaNo Gravatar

    September 27th, 2008 07:17

    thank you , I loved the updatedb command for locate, I used to hate it when locate listed files which no longer existed. and I didnt kow how to fix it.

    thanks

  • MikkoNo Gravatar

    September 27th, 2008 10:25

    The database used for searches with locate is not created automatically. In fact, some distros like openSUSE don’t even install locate & updatedb in the default install. The interval between updates to the database depends on how the cron is configured to update the database.

    I usually take care myself on the updating the database after some major software installations.

  • KeithNo Gravatar

    September 28th, 2008 09:48

    Thanks for the great list. I have known about find and locate, but looks like there are more than I knew of.

  • BrianNo Gravatar

    October 3rd, 2008 10:13

    Great list! I love the speed of locate, but find is great if that pesky db hasn’t been updated in a sufficient amount of time.

    One thing I like to do is add all these little tips I find to Evernote, then, the next time I need something I can just pull up Evernote and find it real quick.

  • TimNo Gravatar

    November 24th, 2008 17:53

    MDFIND!!!!

    mdfind is the command line program behind spotlight and quicksilver.

    OS X ha s a journaled filesystem and is far more efficient than the older filesystems that find is useful for. So, if you want to find a file that has a specific word in it, you can just do:

    mdfind ‘my_word’

    and it will find it far faster than find, over your whole HD, and even within each file.

    Files also have metadata associated with them, so if you have it set up correctly, you could do something like this, to find all of the music files w/ an author of Roger Waters.

    $ mdfind ‘kMDItemComposer = “*Waters*” && kMDItemAudioBitRate < 128000′

    will find all of your Roger Waters tracks at a bitrate higher than 128mbs encoding. Anyway, mdfind is a HUGE topic, but is a vastly advanced find tool.

Trackbacks

  1. Buscando en Linux « Xonos
  2. Suchen mit dem Terminal - Bananas Development Blog
  3. 5 formas de buscar archivos en la Terminal | 8chapas.com
  4. Search from the command line « 0ddn1x: tricks with *nix
  5. blog.q8lug.org » Blog Archive » 5 Ways To Search For Files Using The Terminal | LinuxHaxor.net
  6. GUbuntu.es » 5 formas de buscar archivos desde el terminal

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.