Linux Quick Tips
Things that I wish I’d known when I’d started
This segment is for the stupid little things that would have saved me an awful lot of time wasted had I known them when I first started playing with Linux…
Bash
bash#> CTRL-R
Search through your bash history
bash#> sudo !!
Repeat the last typed command as root
bash#> !55
Repeat the 55th typed command from your bash history (view your history by using the history command)
bash#> Alt-.
Add the argument to your previous command to the terminal (keep pressing it to cycle). (Submitted by vidda)
$ while [ 1 ] ; do command1 ; done
Run ‘command1′ on a loop.
$ while [ 1 ] ; do command1 ; command2 ; sleep 10 ; done
Run ‘command1′ and ‘command2′ on a 10 second loop.
$ mount | awk ‘{print $2}’
Print column 2 of a tabulated output (replace mount with the command that produces the output – this is called using a hammer to crack a nut, as awk is a whole other programming language), you can also set the delimiter by hand.
$ grep -i terms /file/to/search
Case insensitive grepping.
$ grep -v terms /file/to/search
Inverse grepping.
$ command | grep terms
Grep the output of a command.
$ command | wc -l
Count the lines of the command output.
$ echo $(($NUM+9))
Do maths between $(( and )), in this case adding 9 to the variable “NUM”.
$ ./configure && make && sudo make install
Does the latter command only if the prior command returned status 0 (ie. it worked).
$ echo $?
Show the status code of the last command to run (remember echo is a command).
Quick BASH tips | Nothing But Reboots said,
[...] is already documented over at the ‘Linux Quick Tips‘ section, perhaps one of the most useful BASH shortcuts is the CTRL-R command, that allows [...]
RSS feed for comments on this post · TrackBack URI