Advanced

Finding Files On The Command Line

Posted by falko on · 8 comments
HowtoForge
Mail this story
Print this story

One of the things I like about Linux is the command line. I have used nautilus, gnome-commander, konqueror, kommander, dolphin and thunar to manage files in Linux and these file managers are great for what they do. But there are times when one simply wants to find a file when working on the command line without having to open a GUI application.

One of the things I like about Linux is the command line. I have used nautilus, gnome-commander, konqueror, kommander, dolphin and thunar to manage files in Linux and these file managers are great for what they do. But there are times when one simply wants to find a file when working on the command line without having to open a GUI application.

http://www.howtoforge.com/finding-files-on-the-command-line

Full Story

  Nav
» Read more about: Story Type: Tutorial; Groups: Linux

» Get new stories by e-mail: nightly or as they are published

« Return to the newswire homepage

  Related stories
» More like this

Comments (8)

This is a good tutorial. Find is an extremely valuable tool.

The "but" refers to the first introductory paragraph only. Nowadays the author, probably correctly, assumes that the typical Linux user will know a bunch of GUI tools and file managers but have no clue on the command line. Find is UNIX 101. It's an absolute basic. Yet it's assumed to be an unknown while nautilus and konqueror are assumed to be known quantities.

How the Linux community has changed in the past decade or so...
$ locate filename-fragment | grep username

A lot faster, no anti-globbing measures required, and it requires less disk I/O and fewer seeks. It's also not as flexible as "find", but if you're just wanting to find a file, the KISS principle works very well.
I find (no pun) that I use locate more as well, with the mlocate backend. locate foo and toss in | grep is fine tuning is needed. On large systems I can run locate many times in the time frame it takes on $ find -name foo / .
I use my home brewn '/usr/local/bin/where' a lot. It looks for a part of a file name recursively (doh!) in the current dir.

#!/bin/bash [ -z $1 ] && echo "No argements given" && exit /usr/bin/find . -iname "*$1*"

Sure, slocate is quicker, but not always up to date. And -exec when combined to "find" is great, especially when you have to delete lots of certain files. For example when you wrote an id3tag-script that fails miserably due to id3tag creating new files whenever it has files as arguments that don't exist (because you didn't carefully escape the spaces in the song names!)
You know, commands I don't use a lot, I forget. And both find and locate are ones I just never became accustomed to using. So I appreciate this kind of tutorial even though I'm not console-phobic.

In a related matter, I have the second edition of this book, which can probably be obtained used very, very cheaply. The new edition isn't expensive either. It's a great command-line resource:

http://www.amazon.com/Unix-Linux-Visual-QuickStart-Guide/dp/...
For a system command reference I like:

http://www.amazon.com/Linux-System-Commands-Patrick-Volkerdi...

I've had it on my bookshelf for a long time and it, as a reference book, is as good as it gets. Some here probably have a bias in favor of one of the authors :)
> Some here probably have a bias in favor of one of the authors :)

Possibly. :)
Having met the man....

Yeah.

Post a comment

A free account is needed to post. Write your comment here first: your text is kept in this browser while you sign up or log in, and is waiting for you when you come back.

Your message:
|||||
10
Markdown: **bold**, *italic*, [text](https://link), - lists, > quotes, $x^2$ for math. Formatting help

Sign up and post (it is free)  or  Log in and post