4

Sometimes I want to run a command, as arguments to this command I want to supply multiple files that are located in a folder deep in the file system hierarchy, eg:

command /this/is/a/long/path/foobar /this/is/a/long/path/quux

I was hoping I could use brace expansion, and sure, this works:

command /this/is/a/long/path/{foobar,quux}

However, the filenames can be long and I would like to use filename completion (TAB-key) but it doesn't seem to work inside braces, any ideas?

5
  • I don't suppose it's possible to cd to \this\is\a\long\path and run it from there? Then the command is only command foobar\file.exe quuz\file2.exe.
    – Duall
    Nov 27, 2012 at 14:59
  • This kind of completion could be appended in your $BASH_COMPLETION. But I do not know if this is what you want...
    – oHo
    Nov 27, 2012 at 16:04
  • @olibre - could you give an example? I would love to have this as well.
    – nerdwaller
    Nov 27, 2012 at 16:14
  • @nerdwaller My BASH_COMPLETION knowledge is rusty :( Moreover I have to go home in few minutes... I hope someone will answer this question using BASH_COMPLETION (I am also interested ;) Cheers.
    – oHo
    Nov 27, 2012 at 17:37
  • @olibre No worries, I will do my homework, just knowing where to start (i.e. having a name) is a huge help. Thank you!
    – nerdwaller
    Nov 27, 2012 at 19:37

1 Answer 1

1

A little workaround: in Bash, [Ctrl]+u deletes from the beginning of the commandline until the cursor, and puts it in memory, [Ctrl]+y "yanks" (paste) it back.

So assuming you want to run the command ls and give it as arguments files from the ./deep/below/directory/ , you could:

1) start by entering the long dir name, preceded by a space (this will saves a few keystrokes later): ./deep/below/directory/ (you can use [Tab] as needed), followed by [Ctrl]+u, which will delete it and keep it in memory (note: you do have to use './' at the beginning of the directory name if it's a relative path, otherwise bash won't autocomplete the directory names at the beginning of the commandline)

2) then type the command (and its options) followed by a space : ex: ls -alFtr

3) use [Ctrl]+y to yank the long dir name here, and then type the beginning of the filename you seek, and use [tab] as you usually do to autocomplete its name (the cut directory name is still in memory, ready to be reused)

4) repeat step 3) as many times as necessary

5) [Enter]

Long to type, but much faster to use ^^, try it!

1
  • Of course it also works with absolute paths ^^ (I say that as a friend asked me why I insisted on the "./" : it's only so that bash can autocomplete while typing the directory name) Nov 28, 2012 at 19:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .