15 Linux Terminal Commands That Will Rock Your World
15 Linux Terminal Commands That Will Rock Your World
I have been using Linux for about 10 years and what I am going to show you in this
article is a list of Linux commands, tools, clever little tricks and some plain fun
commands that I wish somebody had shown me from the outset instead of
stumbling upon them as I went along.
As you can see I have a spelling error and for the command to work I would need to
change "intall" to "install".
Imagine the cursor is at the end of the line. There are various ways to get back to
the word install to change it.
I could press ALT + B twice which would put the cursor in the following position
(denoted by the ^ symbol):
Now you could press the cursor key and insert the ''s' into install.
Another useful command is "shift + insert" especially If you need to copy text from a
browser into the terminal.
02 SUDO !!
of 15
sudo !!
How do you use sudo !!? Simply. Imagine you have entered the following
command:
The words "Permission denied" will appear unless you are logged in with elevated
privileges.
sudo !! runs the previous command as sudo. So the previous command now
becomes:
CTRL + Z - Pauses an
application
Halfway through typing text into the file, you realize that you quickly want to type
another command into the terminal but you can't because you opened nano in
foreground mode.
You may think your only option is to save the file, exit nano, run the command and
then re-open nano.
All you have to do is press CTRL + Z and the foreground application will pause and
you will be returned to the command line. You can then run any command you like
and when you have finished return to your previously paused session by entering
"fg" into the terminal window and pressing return.
An interesting thing to try out is to open a file in nano, enter some text and pause
the session. Now open another file in nano, enter some text and pause the session.
If you now enter "fg" you return to the second file you opened in nano. If you exit
nano and enter "fg" again you return to the first file you opened within nano.
I always connect to the Raspberry PI via ssh from a laptop. If I started downloading
a large file on the Raspberry PI without using the nohup command then I would
have to wait for the download to finish before logging off the ssh session and before
shutting down the laptop. If I did this then I may as well have not used the
Raspberry PI to download the file at all.
To use nohup all I have to type is nohup followed by the command as follows:
The 'at' command allows you to do just that. 'at' can be used as follows.
at 10:38 PM Fri
at> cowsay 'hello'
at> CTRL + D
The above command will run the program cowsay at 10:38 PM on Friday evening.
When the at> prompt appears, enter the command you want to run at the specified
time.
There are lots of different date and time formats and it is worth checking the man
pages for more ways to use 'at'.
06 Man Pages
of 15
You can, however, do things to make your usage of man more appealing.
export PAGER=most
You will need to install 'most; for this to work but when you do it makes your man
pages more colorful.
You can limit the width of the man page to a certain number of columns using the
following command:
export MANWIDTH=80
Finally, if you have a browser available you can open any man page in the default
browser by using the -H switch as follows:
man -H <command>
Note this only works if you have a default browser set up within the $BROWSER
environment variable.
07 Use htop To View And Manage Processes
of 15
htop provides a list of all running processes in the terminal much like the file
manager in Windows.
You can use a mixture of function keys to change the sort order and the columns
that are displayed. You can also kill processes from within htop.
To run htop simply type the following into the terminal window:
htop
ranger
The command line window will be much like any other file manager but it works left
to right rather than top to bottom meaning that if you use the left arrow key you
work your way up the folder structure and the right arrow key works down the folder
structure.
It is worth reading the man pages before using ranger so that you can get used to
all keyboard switches that are available.
09 Cancel A Shutdown
of 15
shutdown -c
pkill shutdown
Simply type the following into a terminal and then click on the window of the
application you want to kill.
xkill
Hold down the 'alt' and 'sysrq' keys on your keyboard and whilst they are held down
type the following slowly:
REISUB
This will restart your computer without having to hold the power button.
11 Download Youtube Videos
of 15
youtube-dl url-to-video
You can get the URL to any video on Youtube by clicking the share link on the
video's page. Simply copy the link and paste it into the command line (using the
shift + insert shortcut).
wget path/to/filename
For example:
wget http://sourceforge.net/projects/antix-linux/files/Final/MX-
krete/antiX-15-V_386-full.iso/download
There are a large number of switches that can be used with wget such as -O which
lets you output the filename to a new name.
In the example above I downloaded AntiX Linux from Sourceforge. The filename
antiX-15-V_386-full.iso is quite long. It would be nice to download it as just
antix15.iso. To do this use the following command:
Downloading a single file doesn't seem worth it, you could easily just navigate to
the web page using a browser and click the link.
If, however, you want to download a dozen files then being able to add the links to
an import file and use wget to download the files from those links will be much
quicker.
wget -i /path/to/importfile
13 Steam Locomotive
of 15
sl
fortune
fortune | cowsay
fortune | xcowsay
cowsay and xcowsay can be used to display any message. For example to display
"Hello World" simply use the following command: