Linux Tips for Beginners

Many beginners find it hard to understand and adapt to Linux. In this post I will list a few helpful tips for Linux that can get you started on how to use it efficiently.

Terminal Auto Completion

This is probably an easy, obvious one to many of us but it is still important to list. When using the terminal, you can use auto completion for commands or to use a file/folder in the directory you're currently in by pressing the TAB key on your keyboard. This is helpful if you're still new to linux, if you just forgot what the name of the command is, or if you're just too lazy to type it out (like many of us are).

Quick Navigation Between Directories

As you know in Linux, to move from one directory to the other in the terminal you use the cd command. For example:

cd my-folder

There are three shortcuts that can help you navigate between directories:

  1. Navigate to the Home directory: To move to the home directory, you just need to use cd ~.
  2. Navigate to the parent directory: To move to the parent directory, you just need to use cd ..
  3. Navigate to the previous directory: To move to the directory you were previously in, you just need to use cd -

Moving To the Beginning and End of Line

When you are running commands in the terminal, especially when you are copy/pasting the commands, a lot of time it can be a hassle when you want to edit something in the beginning of the line and then moving back to the end of it. There is an easier way to do it.

  1. To move to the beginning of the line press CTRL + A
  2. To move to the end of the line press CTRL + E

Read a File As It Updates

This is very essential when you are reading from a log file. To keep executing tail every time you want to check for changes can be a hassle and frankly eye blinding.

In case you're not aware, tail is a command used to read the end of a file.

So to read a file and have it update as any new lines are added to the file, just add -f option to the command. For example:

tail -f /var/logs/apache2/error.log

This can be used on any file as well, not just logs.

Reuse The Previous Parameter

To use the parameter you've used in the previous command, use !$. For example:

touch test.txt // creates a new file test.txt
nano !$ // edit the previous parameter which is test.txt

Reuse The Previous Command

To reuse the previous command, use !!. For example

tail -n 100 error.log
!! //use the previous command again

This is mostly helpful when you run a command, but realize you need to add sudo to it. So instead of going to the beginning of the line to do that, just use sudo !!

Get Information About Any Command

If you want to get information about any command like its description of the options and parameters it accepts, simply add --help to it. For example:

cd --help

Copying and Pasting From The Terminal

To copy anything from the terminal, use CTRL + SHIFT + C

To paste anything to the terminal, use CTRL + SHIFT + V

Search Through The Commands

If you've used a command and you want to use it again, but you forgot some of it or you're just too lazy to type it out, one way to use it again is by searching in your terminal. To do that, press CTRL + R and then type in the command. As you type you will see commands that match your search and when you find what you need, press ENTER and the command will run.

Reading Files in Parts

Use less to read a file a little by little. Many people use cat but if the file is big then using cat can be overwhelming. When you use less you can go through the file in parts and at your own pace. Example of usage:

less test.txt

To exit the file you are reading just type q.

And There's Still Many More!

If you have any other linux tips that make your day less of a pain, please share them with everyone below!