You are currently viewing Linux cheat sheet: terminal commands for beginners

Linux cheat sheet: terminal commands for beginners

The terminal and text commands are the primary way to manage a Linux operating system, especially for a server. And although the word “terminal” scares newcomers, believe us, it’s much more straightforward. Today we have prepared a cheat sheet with basic commands for you – bookmark it and increase your productivity.

Let’s start with the theory.

Linux (Linux) is a family of open-source Unix operating systems based on the Linux kernel. This includes all the most popular OS-based systems such as Ubuntu, Fedora, Mint, Debian, etc. They are also called distributions.

Linux (Linux) is a family of open-source Unix operating systems based on the Linux kernel. This includes all the most popular OS-based systems such as Ubuntu, Fedora, Mint, Debian, etc. They are also called distributions.

A terminal (or “Bash”, short for “Bourne-Again shell”) is a programme that is used to interact with a shell. The terminal is used to perform administrative tasks such as: installing packages, acting on files and managing users.

A command is the name of a certain programme that the user enters into the terminal to perform a certain task. Commands can have additional data and parameters.

There are several hundred commands and their variations in the OS. They are grouped into several categories:

  • By location – these can be command line utilities or a built-in shell function.
  • By frequency of use – those commands used all the time, on occasion (occasional) or rarely.
  • By type of action – a large group of commands that can control processes or retrieve information. We will talk about them today.

Commands to find out more about your system

id – if you want to get information about your account.

w – is a useful command if you want to find out which user is currently logged in (or -f if you want to find out where the login came from).

lsblk – if you want to open a list of block storage devices.

lscpu – displays information about the processors.

free – shows how much memory is free and how much is already in use (alternatively free -g).

lsb_release -a – if you want to get information about the version of your operating system.


Commands for file management

Contains almost all the small utilities and tools for interacting with files and folders.

ls – shows you the contents of the directory you are in. If you enter the address of a particular folder after the command, it will show you what is stored there. If you add the -R argument, the output of the command will show the files from the subdirectories.

cd – change directory, which translates to “change directory”. It is clear from the name that you can use this command to navigate between folders. You type it and then the address: cd /user/test/dir/111. There are abbreviated variants: cd- to move to the previous directory or cd (without arguments) to jump to the home directory.

pwd – will specify the full path to the directory you are in. If you jumped to your desktop using cd ~/Desktop/, pwd will show something like /home/Polzovatel/Desktop.

dd – is a powerful tool for manipulating partitions. It can make copies of partitions, move them around, or remove them permanently.

rm – is a dangerous command to erase directories and their contents. It will erase all the data it finds in the directory without allowing it to be recovered.

grep – is a full text file search. A handy command when you need to find something. For example, grep value /path/to/file will show the lines with ” value “. And the command grep -ril value /path/to/file/* will show all files that have the value you are looking for.

-r – recursive search

-i – ignore case (case insensitive)

-l -displays the results in a list.

chown user:group – command allows changing the owner of a file.

chmod – changes permissions on file or directory

find – is a super useful command. You can search for files by specifying parameters.

The following commands are useful for files of all sizes and types:

cat – displays the contents of files. It can also be used in two ways: 1) a single text file (cat path_to_file), it displays the contents of the file in the terminal window, 2) if you specify more items, the command will glue them together (cat path_to_file_1 path_to_file_2).

head – “head”, like cat, shows the contents of the documents, but not all of them, just the first 10 lines. If desired, the number of lines can be increased or decreased by adding the -n parameter.

tail -f – is used to view the growing file in the interactive code window.

touch – is a command designed to change the time a file or directory was last opened but is used mostly to create new files.

wget – downloads documents, pictures, full pages, and other content from the Internet.

wc – counts strings, words, characters, and bytes.

zip – packs files into a .zip archive.

diff – is short for “difference”. It shows the difference between two text files.

What can you do with binaries? There are not really many options:

strings – the command will print the lines of the file ready for printing;

od – allows you to print the file in octal format;

cmp – allows you to compare files byte-for-by-byte.

If you need to compare text files with each other, enter these commands:

comm – the files will be sorted line by line.

diff – allows you to diff the files line by line. This command is the most commonly used because of its rich set of options.


Commands for user management

Linux is a multi-user system, so adding and editing user accounts is quite complex. But it is possible to simplify your life and use these commands:

useradd – creates a new user account. For example, if we wanted to add a new user named ArkHost, then use this command – type useradd ArkHost.

passwd – specifies password for account. In short, it works in conjunction with the previous command. That is, immediately after creating an account, type passwd ArkHost.

userdel – removes the selected account. The syntax is simple: userdel <name of account> to be deleted


To install, remove and update packages

Linux uses package managers to install software, but they are different for each distribution. Here are the commands for the most popular distributions:

Debian/Ubuntu

sudo apt-get install package_name – installs the program of your choice.

sudo apt remove name_package – command, using which you can remove not only software, but also all unused packages.

sudo apt-get update – updates information about packages present in the system and those stored in connected repositories.

sudo apt-upgrade – updates installed packages to the latest versions available in connected repositories.

sudo apt purge – removes all configuration files along with software packages.

sudo apt autoremove -purge – removes absolutely everything: packages, dependencies and config files.

sudo apt search package_name – check whether a package is available in the repository


Red Hat Linux/CentOS

sudo dnf install package_name – installs a program of choice.

sudo dnf upgrade – upgrades installed packages to the latest versions.

sudo dnf remove package_name – erases package from hard disk.


Bonus! Tricks to save time

This list of useful characters will speed up your work with these commands:

!! – Repeats the last command.

!$ – allows you to change the command by saving the last argument. For example, the command less !$ – is used to reopen a smaller file.

!* – allows you to change the command, but save all its arguments. For example, head states.txt | grep ‘^Al’ – must be tail when used.

tail !* – saves you from typing the rest of the command.

>x.txt – used to create an empty file or clean up an existing one.

lsof -P -i -n – determines which scripts are being accessed by the web server.

And the coolest command in Linux: to output a complete manual about a particular command is man (short for manual). To display the manual, just execute man <command name>. As an example, let’s look at the cat command:

CAT(1) User Commands CAT(1)

NAME
cat - concatenate files and print on the standard output

SYNOPSIS
cat [OPTION]... [FILE]...

DESCRIPTION
Concatenate FILE(s) to standard output.

With no FILE, or when FILE is -, read standard input.

-A, --show-all
equivalent to -vET

-b, --number-nonblank
number nonempty output lines, overrides -n

-e equivalent to -vE

-E, --show-ends
display $ at end of each line

-n, --number
number all output lines

-s, --squeeze-blank
suppress repeated empty output lines

-t equivalent to -vT

-T, --show-tabs
display TAB characters as ^I

-u (ignored)

-v, --show-nonprinting
use ^ and M- notation, except for LFD and TAB

--help display this help and exit

--version
output version information and exit

EXAMPLES
cat f - g
Output f's contents, then standard input, then g's contents.

cat Copy standard input to standard output.

To exit viewing mode, simply type quit or q.

This list might look like a lot to memorise, but you learn it hard! The more often you use particular commands, the more likely you will remember them.

And, if you want to try some commands on a real server – try our Cloud VPS with ready-made templates of popular Linux distributions: Ubuntu, Debian, AlmaLinux, RockyLinux, CentOS Stream,…