The usual action in case you don't remember the name is to press Tab. Most shells (including bash
, zsh
, ksh
) will guess as many characters as they could on the first keystroke, then display a list of matching files and directories on the second.
For example, if you have dir1
, dir2
and dir3
in your home directory, then typing cp file ~/d
and hitting Tab twice would produce
dir1 dir2 dir3
$cp file ~/dir
Here, your shell could guess from the letter "d" you have typed that you want one of the three directories mentioned above, and filled the common part ("dir") in your command for you. All you have to do is to type "1", "2" or "3", and hit Enter.
Tab can be used multiple times while typing the same command. If your target directory is buried deep in the directory three, or if there are many files/directories to chose from, it is convenient to type a few characters, hit Tab, check how many the shell could guess, type a few more, hit Tab again etc. Thanks @EightBitTony for the remark.
Note that command line competition using Tab also works with command names. cp
is short enough to type entirely, but if you need something longer like wpa_supplicant
then typing wpa_s
and hitting Tab will save you a fair amount of keystrokes. Personally, I use zsh
which is by default configured to guess command line options, e.g. typing service sshd r
and hitting Tab is automatically expanded to service sshd restart
.