Useful Tricks
There are a couple of useful tricks for Terminal windows that will allow you to save typing time.
- You can use the up and down arrow keys to scroll through a list of previously typed commands. This will help you out if you frequently type the same command, or if you make a typo and need to change it.
For Example:- I type "
cd /afs/eos.ncsu.edu/courses/e/e112" (notice I mistyped e115) - Instead of typing the whole line again, I can just hit the up arrow and make my correction.
- I type "
- You can use the TAB key to complete long filenames.
For Example:- I have a file called "
this_is_a_very_long_filename_for_a_text_file" in my home directory. - I would like to edit this file with Nedit.
- To do so, I would just type "
nedit this_is", then hit the TAB key and let Linux fill in the rest of the name. - Note however, that this only works if one filename starts with the characters you originally type.
- I have a file called "
Script
Script is a useful command for keeping a log of everything displayed in the terminal screen. This can help you keep track of common mistakes you may make as well as help you to remember a complex set of instructions that you may have typed into the terminal. To begin recording the log file use the following command:
eos% script logfilename
When you want to close out the log, simply type in exit to close out the log file. You can also use the -a option to append the log to an existing file instead of overwriting the contents.
Chaining
Sometimes you might want to execute several commands in a row. To keep from having to type in each command after the other has executed, you can chain them together on a single line, by separating them with a semicolon.
For example, if you wanted to copy a file into your home directory and then go to your home directory and read the file you could type:
unity% cp filename ~/ ; cd ; more filename
Another example, if you have a very popular website and you want to swap a file without any downtime, you could rename your files simultaneously and then check to make sure it worked:
unity% mv filename filename.old ; mv filename.new filename ; ls filename*
You should note that if any command in a chain of commands returns a Standard Error of "false" (it could not complete), then the chain of commands will halt at that point and all the other commands in the chain will not execute. This is a good thing to keep in mind when troubleshooting.




