Wednesday 4 March 2015

Tips: Linux Terminal Tab Completion

Beginners to using the Linux terminal may find this of use - it's an essential trick and great time saver.

Let's say you have a file with a long file name in the current directory and you want to delete it. Typing the entire file name is one way, but you'd have to make sure all the spaces were escaped properly (i.e. adding \ character before each space) and you  might easily make a mistake. However, if you type rm and the first character of the file name, and press the Tab key, Bash will automagically fill in the file's name for you.

Of course, you might have multiple files that begin with this letter and Bash won't know which one you want to delete. If you hit Tab again, Bash will show you a list of all matching file names. Continue typing your desired file name and press Tab again, and Bash will fill your desired file name.

Usefully, this also works for commands. Not sure which command you need, but you know it begins with "gnome"? No problem. Type "gnome" and press Tab to see a list!

No comments:

Post a Comment