Software & Apps Linux 55 55 people found this article helpful 15 Linux Terminal Commands That Will Rock Your World Maximize your effectiveness with these utilities By Gary Newell Writer Gary Newell was a freelance contributor, application developer, and software tester with 20+ years in IT, working on Linux, UNIX, and Windows. our editorial process Gary Newell Updated March 11, 2020 Linux Switching from Windows Tweet Share Email The Linux command line offers a much easier, and cross-distribution, method of completing common tasks. 01 of 15 Useful Command Line Keyboard Shortcuts The following keyboard shortcuts are useful and will save you time: CTRL+U: Cuts text up until the cursor.CTRL+K: Cuts text from the cursor until the end of the line.CTRL+Y: Pastes text.CTRL+E: Moves the cursor to the end of the line.CTRL+A: Moves the cursor to the beginning of the line.ALT+F: Jumps forward to the next space.ALT+B: Skips back to the previous space.ALT+Backspace: Deletes the previous word.CTRL+W: Cuts the word behind the cursor.Shift+Insert: Pastes text into a terminal. So that the commands above make sense, look at the next line of text. sudo apt-get intall programname There's a spelling error in the command, and for the command to work, intall needs to be changed to install. Imagine the cursor is at the end of the line. There are several ways to get back to the word install to change it. You could press ALT+B twice, which would put the cursor in the following position (denoted by the ^ symbol): sudo apt-get^install programname Then, 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 of 15 SUDO !! You'll appreciate this command every time you enter a command, and the words Permission denied appear. How do you use sudo !!? Imagine you entered the following command: apt-get install ranger The words Permission denied appear unless you are logged in with elevated privileges. sudo !! runs the previous command as sudo. So the previous command now becomes: sudo apt-get install ranger 03 of 15 Pause Commands and Run Commands in the Background To run terminal commands in the background, press: CTRL+Z: Pauses an applicationfg: Returns you to the application Imagine you have opened a file in nano as follows: sudo nano abc.txt Halfway through typing text into the file, you realize that you want to type another command into the terminal, but you can't because you opened nano in foreground mode. When you press CTRL+Z, the foreground application pauses, and you are returned to the command line. You can then run any command you like, and when you finish, return to your previously paused session by entering fg into the terminal window and pressing Enter. An interesting thing to try is to open a file in nano, enter some text, and pause the session. Then, open another file in nano, enter some text, and pause the session. If you 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 in nano. 04 of 15 Use nohup to Run Commands After You Log Out of an SSH Session The nohup command is useful if you use the ssh command to log in to other machines. Use it to log in to another computer remotely using ssh and run a command that takes a long time, then exit the ssh session but leave the command running. For example, you can use a Raspberry PI to download distributions for review purposes. Connect to the Raspberry PI via ssh from a laptop. If you started downloading a large file on the Raspberry PI without using the nohup command, then you must wait for the download to finish before logging off the ssh session and before shutting down the laptop. If you did this, then you may as well have not used the Raspberry PI to download the file at all. To use nohup, all you have to type is nohup followed by the command as follows: nohup wget http://mirror.is.co.za/mirrors/linuxmint.com/iso//stable/17.1/linuxmint-17.1-cinnamon-64bit.iso & 05 of 15 Run a Linux Command 'at' a Specific Time The nohup command is good if you are connected to an ssh server, and you want the command to remain running after logging out of the ssh session. Imagine you want to run that same command at a specific point in time. The at command allows you to do just that. at can be used as follows. at 10:38 PM Friat> cowsay 'hello'at> CTRL+D The above command runs the program cowsay at 10:38 p.m. on Friday evening. The syntax is at followed by the date and time to run. When the at> prompt appears, enter the command you want to run at the specified time. The CTRL+D keyboard shortcut returns you to the cursor. There are many date and time formats, and it's worth checking the man pages for more ways to use at. 06 of 15 Man Pages Man pages offer an outline of what commands do and the switches that can be used with each command. The man pages are kind of dull on their own. 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 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 of 15 Use htop to View and Manage Processes Which command do you currently use to find out which processes are running on your computer? If you use ps and you use various switches to get the output you desire, install htop. 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, type the following into the terminal window: htop 08 of 15 Navigate the File System Using ranger If htop is useful for controlling the processes running via the command line, then ranger is useful for navigating the file system using the command line. You will probably need to install ranger to be able to use it, but once installed, you can run it by typing the following into the terminal: ranger The command line window will be much like any other file manager, but it works left to right rather than top to bottom. When 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 the available keyboard switches. 09 of 15 Cancel a Shutdown Abort a scheduled shutdown with the command: shutdown -c If the shutdown has started, then it may be too late to stop the shutdown. Another command to try is as follows: pkill shutdown 10 of 15 Kill Hung Processes the Easy Way Imagine you are running an application, and for whatever reason, it hangs. You could increase the process's priority with nice, but it's often better not to give a runaway process more resources. You could use ps -ef to find the process and then kill the process, or you could use htop. There is a quicker and easier command called xkill. Type the following into a terminal, then click the window of the application you want to kill. xkill What happens though if the whole system is hanging? Press the Alt+SysRq keys on your keyboard and while the keys are held down, type the following letters slowly: REISUB This technique restarts your computer without using the power button. 11 of 15 Download Youtube Videos Generally speaking, many people are happy for YouTube to host the videos and for them to watch videos by streaming them through a media player. If you know you are going to be offline for a while, then you may wish to download a few videos onto a pen drive and watch them at your leisure. All you have to do is install youtube-dl from your package manager. Use youtube-dl as follows: youtube-dl url-to-video Get the URL to any video on Youtube by clicking the share link on the video's page. Copy the link and paste it into the command line (using the Shift+Insert shortcut). 12 of 15 Download Files From the Web With wget The wget command downloads files from the web using the terminal. The syntax is as follows: 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, AntiX Linux is downloaded from Sourceforge. The filename antiX-15-V_386-full.iso is long. It would be nice to download it as antix15.iso. To do this, use the following command: wget -O antix.iso http://sourceforge.net/projects/antix-linux/files/Final/MX-krete/antiX-15-V_386-full.iso/download Downloading a single file doesn't seem worth it; you could easily 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 is quicker. Use the -i switch as follows: wget -i /path/to/importfil 13 of 15 Steam Locomotive This one isn't so much useful as a bit of fun. Draw a steam train in the terminal window using the following command: sl 14 of 15 Get Your Fortune Told Another one that isn't particularly useful but just a bit of fun is the fortune command. Like the sl command, you might need to install it from your repository first. Then type the following to get your fortune told: fortune 15 of 15 Get a Cow to Tell Your Fortune Finally, get a cow to tell you your fortune using cowsay. Type the following into the terminal: fortune | cowsay If you have a graphical desktop, you can use xcowsay to get a cartoon cow to show your fortune: fortune | xcowsay cowsay and xcowsay display any message. For example, to display "hello world," use the following command: cowsay "hello world"