You are on page 1of 4

10 Command Line Tricks I Wish Id Always Known Al...

1 of 4

gimp: error while loading shared libraries: libgegl0.0.so.0: cannot open shared object file: No such file
or directory

http://alexsleat.co.uk/2012/04/14/10-command-line-trick...

Ubuntu 12.04 Removing conflicting operating


system files

10 Command Line Tricks I Wish Id


Always Known
One thing that Linux Gurus and Terminal Wizards often argue is that its way quicker to use the command
line to do anything in Linux than it is through menus and what not. While the jury is still out on this, there are
a lot of things they know which do help put the ball in their court which can often take a lot of time exploring
the terminal to discover. Ive compiled a list of my favourite commands and tricks that I think that would
have saved me a bunch of time if Id been aware of them when I first ventured in to Linux.

1. Repeat Recent Commands:


Lets say youve just ran a command but forgot you needed to run it as sudo, you can use !! to repeat it with
the additional sudo at the beginning, as below:
alex:~$ apt-get install package
alex:~$ sudo !!
sudo apt-get install package
Additionally youre able to use this to go back further than the last command by replacing the second ! for -n
(where n is the number of commands ago you want to repeat).
alex:~$
alex:~$
alex:~$
alex:~$
ls

ls
cd dir
cat file
!-3

How about if you want to reuse the arguments from the last command but not the command itself, well it
can do that too:
alex:~$ ls /home/alex/Desktop
alex:~$ cd !*
cd /home/alex/Desktop

2. Replace String In Last Command:


The use of the following command allows you to repeat the last command but replacing a string within it,
useful if you made a mistake or typo. The follow example shows correcting a path for a change directory
command.
alex:~$ cd /this/dir/is/wrong
alex:~$ ^wrong^right^
cd /this/dir/is/right

3. Reset:
Chances are, youll come across a situation where youve seemingly borked a terminal. Maybe you used
cat on the wrong file or a program tried to export some strange characters which changed the settings. The
following command should get you back to a fresh terminal quickly and you can often run it even when you

Friday 10 October 2014 12:08 PM

10 Command Line Tricks I Wish Id Always Known Al...

2 of 4

http://alexsleat.co.uk/2012/04/14/10-command-line-trick...

dont think you can. If the screen is really borked, try hitting enter before hand, typing reset and hitting enter
again.
alex:~$ reset

4. Running A Command In The Background:


Adding an & after the command you run allows you to continue to use the terminal screen while keeping the
process running. Below shows an example of opening gedit in the background but allowing me to continue
using the terminal for other commands. Great for editing and compiling code with the minimal number of
terminals open.
alex:~$ gedit &
Once ran itll give you the process ID which allows you to kill it easily once youre done with it.

5. Exiting A Terminal & Keeping Background Processes Running:


If youve opened a bunch of processes in the background (as per previous command) but now you want to
close the terminal screen but not these processes you can use the following to release the ownership of the
processes and exit.
alex:~$ disown -a && exit

6. htop:
Similar to top (which allows you to view tasks in real-time with other useful info such as memory and CPU
usage) but its displayed in a much easier to understand and interactive. It allows you to kill tasks without
entering its PID, search, filter, sort and a bunch of other features.
alex:~$ htop

7. Reverse History Search:


Ctrl + r

Friday 10 October 2014 12:08 PM

10 Command Line Tricks I Wish Id Always Known Al...

3 of 4

http://alexsleat.co.uk/2012/04/14/10-command-line-trick...

Using this will allow you to start typing and itll find the last command that contained the string youre typing,
hitting enter will execute that command. For example:
alex:~$ cd /home/alex/this/is/a/dir
ctrl+r & typing "a/dir"
(reverse-i-search)`: cd /home/alex/this/is/a/dir

8. Piping (Combining) Commands:


Piping commands allows you to pass the data that would usually be outputted to be directly passed as an
input to another command, for example below is a list command being passed in to the less command to
allow for scrolling of the data. This will work for most commands and experimentation is the best form of
learning in this case.
alex:~$ ls | less

9. Auto Complete Command & File Names:


Half way through typing a command you can hit the Tab key and itll auto complete the word for you, if there
are more than one other possible combinations a double tap of it will show you the possibilities. This also
works for directory and files and can save some serious typing time.

10. Other useful Keyboard Shortcuts:


A few other keyboard shortcuts that are also useful to know (and not always as obvious as they should be):
Ctrl + c kill current process
Ctrl + z put current process in to the background
Ctrl + l clear the terminal
Ctrl + a set cursor to the start of the line
Ctrl + e set cursor to the end of the line
Ctrl + shift + c copy
Ctrl + shift + c paste

Related posts:
1.
2.
3.
4.
5.

HowTo: Mount USB Persistent casper-rw File in Linux


HowTo: Remove Every Other Line in Text Files Linux
How To: Install Pyrobot in Ubuntu
One Line IP Address Bash Command
Ubuntu 12.04 Removing conflicting operating system files

April 14th, 2012 | Tags: bang bang, bash, command line, commands, linux, top 10, tricks |
Category: Blog, Command Line, Featured, Linux

3 comments to 10 Command Line Tricks I Wish Id Always Known


Paraita
September 3, 2012 at 10:36 am
Nice article :D
There is Ctrl+r to search trough previous commands which is very useful too

Friday 10 October 2014 12:08 PM

10 Command Line Tricks I Wish Id Always Known Al...

4 of 4

http://alexsleat.co.uk/2012/04/14/10-command-line-trick...

nodmonkey
October 26, 2012 at 8:40 am
Great summary of useful tips! I love the !* shortcut; never knew that one.
You may want to look at whatever is generating your HTML source. The commands you have that include
ampersands (&) are showing up as & on the page because they are being being doubly-escaped to be &
in the HTML source.

nodmonkey
October 26, 2012 at 8:42 am
Bah! The some of the & characters in my last comment have been unescaped themselves and
made it all wrong I hope you get the idea though.

Friday 10 October 2014 12:08 PM

You might also like