I'm trying to become comfortable with the terminal by using it as much as I can. The aspect of my computer usage where I lose most time using command line instead of the gui is when I try to find a song I am interested in.

My music folder is structured like so Music->Bands->Albums->Songs

I often forget what Album a Song is in but I always remember what Band played that song.

I don't search for the song from the Music directory because it takes too long to find a song (I have a lot of music) so I search for the song after I get to the Band directory. Right now in command line I have

# totem /home/user/Music/Red\ Hot\ Chili\ Peppers/

but I forgot what Album the Song "Dani California" is in (totem is a music player in gnome.) The quickest way for me to get around this is to get inside the Red Hot Chili Peppers folder in the file manager gui and hit ctrl+f and type "Dani California".

Is there a way I can search the contents in a directory from terminal while I'm in the middle of writing a command? Or do you have any recommendations on how I can most quickly achieve the same goal I do in the gui from the command line?


This is not particularly intuitive as the auto-completion is not working, but you could achieve what you want using file masks:

totem /home/user/Music/Red\ Hot\ Chili\ Peppers/*/Dani\ Ca*

Another option is use find and then make it pass the filenames it has found to totem:

find . -name "Dani Calif*" -exec totem '{}' +

Though this isn't exactly "search while you're writing a command"


Hitting "tab" twice should give you a list of files or directories. Then just type part of the one you want and hit "tab" to complete it.

  • 1
    But imagine he has 10 albums by some artist and he doesn't know which album the song is from (which is a shame, LedZeppelin, btw - Dani California is from Stadium Arcadium :) ). Using autocompletion, he would have to iterate through all the albums one by one until he finds the one. Which is what the question is about, as I understand – Sergey Sep 5 '11 at 3:33
  • Heh, yah I know it's from stadium arcadium. I miss John so much... his high notes, followed by low notes and his emphasis on emotion and melody... – user784637 Sep 5 '11 at 5:06

Really interesting question. That's a pretty neat way to force yourself to use the CLI. But man, that sounds too painful for music. I don't see how I could live with the limits of Totem (vs. Banshee or Rhythmbox). I would think banning yourself from using Nautilus and gedit would go far enough to force you to use a terminal more often.

But I admire your patience and discipline. Perhaps you might want to look into a CLI/Terminal oriented music player. Here's a good review of some: http://www.linux.com/archive/feature/124907

Apologies in advance if none of them solve the particular problem you're asking about, but given the background of your question, I think you might find these options interesting nonetheless. Best of luck.

  • Not sure whether i should flag this as not relevant or not. But given the fact that pm is not supported, perhaps i shouldn't. – Mahesh Apr 12 '12 at 19:29

The already suggested solution of metachar is great, but sometimes it could not be enough.

I use frequently more than a terminal at a time, multiplexing a single window using screen, but gnome-terminal's tabs could do the job as well (I should point out that the screen solution will work also in a ssh session or in a virtual terminal, so it is more general).

So, switching to another terminal, you can use the locate command whose results are obtained much more quickly than from find.


It can also be done via Bash programmable completion. I've put together a small sample script.

The script below completes a fap (find and play) command which you should define separately, for example


#! /bin/sh
totem "$file" > /dev/null &
exit 0

Then put the following script into the /etc/bash_completion.d directory


    local cur prev dir i saveIFS

    _get_comp_words_by_ref cur prev

    if [ -z "$cur" ]; then
    elif ! [ -d "$cur" ]; then
        dir="`dirname "$cur"`"

    local files=$(find `dequote "$dir"` -type f -iname "*${prev}*" -printf "%p\n")
    COMPREPLY=( $( compgen -W "${files}" -- $cur ) )

    for ((i=0; i < ${#COMPREPLY[@]}; i++)); do
        _quote_readline_by_ref ${COMPREPLY[i]} COMPREPLY[i]


    return 0
} &&
complete -F _fap -o nospace fap

Change the dir="/home/user/music" line accordingly (start folder for your music collection). Next source the script

. /etc/bash_completion.d/fap

Now you can use TAB completion like this

fap frozen [TAB]
fap frozen /home/user/music/MADONNA\ -\ RAY\ OF\ LIGHT/TRACKS/09\ -\ Madonna\ -\ Frozen.mp3

or, if there are more options

$ fap girl [TAB]
$ fap girl /home/user/music/MADONNA\ -\ RAY\ OF\ LIGHT/TRACKS/[TAB][TAB]
/home/user/music/MADONNA\ -\ RAY\ OF\ LIGHT/TRACKS/04\ -\ Madonna\ -\ Candy\ Perfume\ Girl.mp3
/home/user/music/MADONNA\ -\ RAY\ OF\ LIGHT/TRACKS/13\ -\ Madonna\ -\ Mer\ Girl.mp3
$ fap girl /home/user/music/MADONNA\ -\ RAY\ OF\ LIGHT/TRACKS/0[TAB]
$ fap girl /home/user/music/MADONNA\ -\ RAY\ OF\ LIGHT/TRACKS/04\ -\ Madonna\ -\ Candy\ Perfume\ Girl.mp3
  • Seems interesting, let me give it a try – enzotib Sep 7 '11 at 12:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.