Reading Time: 1 minutes
Unix Tips & Tricks
Below are some quick tips for UNIX which can help in daily tasks:
- $ !-n where n is any integer will run nth command from last.
- CTRL+SHIFT+c, CTRL+SHIFT+v perform copy and paste respectively.
- CTRL+u clears whole line of command, CTRL+w clears single word.
- CTRL+a takes you in the beginning of your command and CTRL+e to the end.
- ^sometext^replaced^ will run last command with 'sometext' replaced with 'replaced' e.g. ^cat^ls^.
- !sometext will run last 'sometext' command e.g.!find.
- !?sometext will run last command containing string 'sometext'.
- CTRL+Z suspends the execution of the process; to bring it back to life one can use either fg or bg command.
- Use the &(ampersand) sign at the end of a command to make it run in the background.
- Use the tee command to split the output of a program so that it can be both displayed and saved in a file.
- Use the touch command to create an empty file, as an alternate to the > sample_file construction, e.g. touch sample_file.
- Use command >> sample_file to append at the end of the sample_file; if sample_file already exists, then using > will rewrite the sample_file.
- If you've done something that has completely screwed up your terminal, everything you type is either invisible or incomprehensible, then try the following:
$ ^C $ stty sane^J
If this doesn't work, try:
$ echo ^V^O
- Use gdb to determine what program dumped an anonymous core file:
$ gdb -core core [...] Core was generated by `a.out'. Program terminated with signal 6, Abort trap. [...]
If you are on a system without gdb, try the file command:
$ file core core: ELF 32-bit LSB core file of 'a.out' (signal 6) $