Beginner's guide to the Linux terminal. Everything you need to know in under 8 minutes of your time

Beginner's guide to the Linux terminal. Everything you need to know in under 8 minutes of your time
Photo by Lukas / Unsplash

Linux is an open-source operating system that powers many servers, supercomputers, and devices. Learning Linux can boost your career as a software developer, system administrator, cybersecurity professional, or IT support specialist. In this blog post, I will introduce one of the most useful skills you need to master in Linux: the command line.

What's the terminal?

The command line, also known as the terminal or the shell, is a text-based interface that allows you to interact with the operating system and run various commands. You can use the command line to perform tasks such as navigating the file system, managing files and directories, installing and updating software, monitoring system performance, troubleshooting problems, and automating tasks.

How do I use it?

To access the command line, you need to open a terminal emulator program, such as GNOME Terminal, Konsole, or xterm. You can find one in your applications menu. Once you have a terminal window open, you can type commands and press Enter to execute them.

You will see a prompt that indicates your username, hostname, and current directory. For example:

user@host:~$

The terminal. user is the user you're logged in as and host is the computer's host name.

Basic navigation

One of the most common commands is ls, which stands for list. This command shows you the files and folders in your current directory, which is the location where you are working. For example, if you type ls in your home directory, you will see something like this:

Documents Downloads Music Pictures Videos

You can also use ls with some options to change the output. For example, ls -l shows more details about the files and folders, such as their size, permissions, owner, and modification date. ls -a shows hidden files and folders, which start with a dot. ls -h shows the sizes in human-readable format, such as KB or MB.

user@host:~$ ls -l /etc
total 1544
drwxr-xr-x. 1 root root      126 Jul 19 03:00 abrt
-rw-r--r--. 1 root root       18 May  4  2023 adjtime
-rw-r--r--. 1 root root     1529 Jul 25 03:00 aliases
drwxr-xr-x. 1 root root       70 Sep  1 03:00 alsa
drwxr-xr-x. 1 root root     3144 Dec  7 21:58 alternatives
drwxr-xr-x. 1 root root       56 Nov 23 19:01 anaconda
-rw-r--r--. 1 root root      541 Jul 19 03:00 anacrontab
-rw-r--r--. 1 root root      269 Jul 19 03:00 anthy-unicode.conf
-rw-r--r--. 1 root root      833 Feb 10  2023 appstream.conf
-rw-r--r--. 1 root root       55 Sep  4 03:00 asound.conf
-rw-r--r--. 1 root root        1 Jul 19 03:00 at.deny
...

The output of ls -l

Another common command is cd, which stands for change directory. This command allows you to move to a different directory. For example, if you want to go to your Documents folder, you can type cd Documents and press Enter. You can also use cd .. to go back to the previous directory, or cd ~ to go to your home directory.

You can also use pwd, which stands for print working directory, to see the full path of your current directory. For example:

user@host:~$ pwd
/home/user/Documents

File management

To create a new file or folder, you can use the touch and mkdir commands, respectively. For example, if you want to create a new file called test.txt in your current directory, you can type touch test.txt. If you want to create a new folder called test in your current directory, you can type mkdir test.

To delete a file or folder, you can use the rm and rmdir commands, respectively. For example, if you want to delete the test.txt file that you created earlier, you can type rm test.txt. If you want to delete the test folder that you created earlier, you can type rmdir test. Be careful with these commands, as they do not ask for confirmation and they do not move the files or folders to the trash bin.

To copy or move a file or folder, you can use the cp and mv commands, respectively. For example, if you want to copy the test.txt file from your current directory to your Downloads folder, you can type cp test.txt ~/Downloads. If you want to move it instead of copying it, you can type mv test.txt ~/Downloads.

To rename a file or folder, you can also use the mv command. For example, if you want to rename the test.txt file to new.txt, you can type mv test.txt new.txt.

To edit a text file, you can use a text editor like nano or vim. For example, if you want to edit the test.txt file with nano, you can type nano test.txt. This will open the file in a simple text editor that allows you to make changes and save them. To exit nano, press Ctrl+X and follow the instructions.

Basic commands

Including the aforementioned, some of the most common and useful commands you should know are:

  • pwd: print the current working directory
  • cd: change the current working directory
  • cp: copy files and directories
  • mv: move or rename files and directories
  • rm: remove files and directories
  • mkdir: create directories
  • touch: create or update files
  • cat: display or concatenate files
  • echo: display a message or a variable
  • grep: search for a pattern in a file or input
  • find: search for files or directories that match certain criteria
  • ps: display information about processes
  • top: display dynamic information about system performance
  • kill: terminate a process by its process ID
  • ping: test the connectivity to a host by sending packets and measuring the response time
  • ssh: connect to a remote host using the Secure Shell protocol
  • scp: copy files securely between hosts using the Secure Shell protocol
  • curl: transfer data from or to a server using various protocols
  • tar: create or extract compressed archive files
  • man: display the manual page for a command or a topic

That's not all! There's a lot of commands. Check out a neat little overview that you can skim through right here!

59 most used Linux commands - with usage examples
This is a compilation of some of the most used commands in Linux. I find that if you already know 50% of these, you’re doing quite well. The list 1. ls: List directory contents. * Scenario 1: View files in a directory: ls * Scenario 2: Display detailed information: ls -l * Scenario

Using the terminal to its fullest

Tab completion

You can use the Tab key to autocomplete commands, filenames, and directories. This can save you a lot of typing and avoid typos. You can also use the double tab to see all the possible options that match your input. For example, if you type ls /e and press tab twice, you will see all the directories that start with /e.

user@host:~$ ls /etc/
Display all 317 possibilities? (y or n)

If there are a lot of possibilities, you'll be prompted if the terminal should show them.

These are some of the basic commands and tips that will help you get started with the command line in Linux. There are many more commands and options that you can explore and learn by using the man command, which shows the manual page for any command. For example, if you want to learn more about the ls command, you can type man ls.

You can use the Ctrl+R key combination to search for a previous command that you have typed in the terminal. This can be useful if you want to repeat a long or complex command without typing it again.

You can type a part of the command and press Ctrl+R repeatedly to cycle through the matching commands in your history. To execute the command, press Enter. To edit the command, press Esc.

History

You can use the history command to see a list of all the commands that you have typed in the terminal. You can also use the up and down arrow keys to navigate through the history.

You can use the !n syntax to execute the command with the number n in the history. For example, !10 will execute the 10th command in the history. You can also use the !! syntax to execute the last command in the history.

Pipes and redirection

You can use the pipe symbol (|) to pass the output of one command as the input of another command. This can allow you to chain multiple commands together and perform complex operations. For example, ls -l | grep txt will list only the files that have the txt extension.

You can also use the redirection symbols (> and <) to redirect the output or input of a command to a file. For example, echo "Hello World" > hello.txt will create a file named hello.txt and write Hello World to it.

I've mentioned grep in this section. This tool is insanely useful for filtering all sorts of things. Read about it below!

grep: Do you know this must-have skill you can learn in just a few minutes?
If you’ve recently switched to Linux or even MacOS, you’ve likely encountered at least some degree of terminal commands. Don’t let the command line intimidate you – things get rather spicy if you know it well. Let’s explore a simple yet incredibly useful command: grep. Introducing grep

The manual

You can learn more about each command by typing man followed by the command name. For example, man ls will show you the manual page for the ls command, which explains its syntax, options, and examples.

If you're ever curious or don't know how to use a certain command, the manual page is a great resource for it - albeit I find a quick google search is usually faster at providing answers.

Conclusion

The command line is a powerful and versatile tool that can help you accomplish many tasks in Linux. By learning the basic commands and how to combine them, you can improve your productivity and efficiency. You can also explore more advanced features, such as pipes, redirection, variables, scripts, and aliases, to further enhance your command line skills.

I hope this blog post has given you an overview of the command line and why it is a useful skill to know in Linux. If you want to learn more, you can check out some of the online courses and tutorials available

Learning Unix Operating System Commands: Understanding and Using the Language of the Terminal
We explore the process of learning Unix commands, the importance of understanding the logic behind them
10 Concepts Every Linux User Should Know About
Linux is a powerful and versatile operating system that can run on a variety of devices, from desktops and laptops to servers and smartphones. Linux is also free and open source, which means anyone can use, modify, and distribute it. However, Linux can also be intimidating for new users, especially

Read more