2

I type in for example: cp /media/Macintosh

I'm recovering someone's HD so I want to get Then Tab so that it can correctly put in the formatting for Macintosh HD

I then want it to complete among a few options if you press tab...

for this example there is Desktop and Desktop (old) how do I choose Desktop (old) when I type De tab tab it shows up there as a list of options but then I don't know how to choose the second option on the list.

I need the correct formatting for the directory "/Desktop (old)/" and I can use tab to have it do that but I don't know how.

Now I have a new Problem: I am doing a data recovery for someone:

-Ubuntu:~# cp /media/Macintosh\ HD/Users/orlando/Desktop\ \(original\)/VIDEOS\ ESPANOL/ /media/\$G\$\ DATA/Orlando/Desktop/
cp: omitting directory `/media/Macintosh HD/Users/orlando/Desktop (original)/VIDEOS ESPANOL/'

When I typed that this was my response:

-Ubuntu:~# cp /media/Macintosh\ HD/Users/orlando/Desktop\ \(original\)/VIDEOS\ ESPANOL/ /media/\$G\$\ DATA/Orlando/Desktop/
cp: omitting directory `/media/Macintosh HD/Users/orlando/Desktop (original)/VIDEOS ESPANOL/'

By the way I am logged in as root. What does this mean and how do I fix it?


Now that I know something and this question is popular: Anybody know a way to modify your bash_profile so that you can use tab several times to cycle between different paths?

The correct answer for someone actually doing this would be to: cd ~/.bash_profile or ~/.basher

open the file with Sublime/TextEditorOfChoice/VIM/echo into the file:

Then copy and paste:

bind '"\t":menu-complete' OR: bind TAB:menu-complete

Then close and open your terminal/bash/commandprompt.

1

2 Answers 2

2

In windows if you type Desk and then Tab it will cycle through all possible (case insensitive) matches. Ubuntu doesn't work quite like this (by default). With ubuntu if you type De Tab it will fill up to Desktop and then you need to tell it how it differentiates.

In general putting special characters (like spaces) in a file name is not good practice. There are two ways of selecting a file named "Desktop Old" and they are

Desktop\ Old

or

"Desktop Old"

In the first option the \ acts as an escape character meaning that the character that comes after this should be interpreted not as a part of a command, or a separation of arguments, but rather part of the same argument that preceeds it. The second option simply puts it in quotes.

So, in your case what you would do is:

cp De tab --> cp Desktop

Now here you would want to type \ which should then, once you press tab again, allow you to autocomplete the (old).

Additionally, it's worth noting that the final command after autocompletion will look like:

cp Desktop\ \(Old\)

As parentheses are also special characters, like spaces.

1

You don't "choose", you just keep typing. The Tab completion will stop as soon as it finds the 1st character that is different in the two files. So, using your example, you'd see

$ cd Desktop
Desktop/       Desktop (old)/ 
$ cd Desktop

You just need to keep typing. However, you have chosen to use strange names that contain spaces and parentheses. This is a bad idea since it makes them harder to deal with. To enter a space as part of the file name (it is normally taken to signify the end of a word or file name) you need to escape it with a backslash (\). So, in this case, you'd need to write \ (that's \Space) and then hit Tab again:

$ cd Desktop
Desktop/       Desktop (old)/ 
$ cd Desktop\ ##<--- hit Tab again here

It will magically complete to

$ cd Desktop\ \(old\)/

Note how the parentheses will be automatically escaped as well.


The above is how Ubuntu's default shell (bash) works. Other shells let you hit Tab again to cycle through the available options. For example, both zsh and fish let you cycle through and choose the one you want. Both are in the repositories so you might want to check them out.

You must log in to answer this question.

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