Update cookies preferences

Don't Fear the Command Line: 15 Basic Linux Server Commands.

25 Aug 2025, 16:30:41
The fear of a "black screen with letters" is the main barrier for a new user of a Linux-based OS. However, an experienced user knows that the command line is the main advantage of Linux, which gives it the notorious flexibility, speed and huge automation capabilities. Most dedicated and virtual servers use systems on the Linux kernel for a reason. In this article, we will consider 15 of the most popular commands that will be useful for a new owner of a server on Debian, Ubuntu, AlmaLinux, CentOS or any other Linux distribution. All commands are executed on a virtual server, which can be connected to via a terminal using the SSH utility (MacOS, Linux) or an SSH client (Putty, Hyper, MobaXterm).

1. cd - go to directory

By connecting to the server via SSH, you get to your user's home directory. However, this is rarely the same directory where the site's files are located. To go to a specific directory, use the cd command:
cd /path/to/dirIn the example, this is the domain directory:
20250825_4eYxb3PI
Useful examples:
  • cd - - return to the previous directory;
  • cd .. - go to the parent directory, the directory above;
  • cd ~ - go to the user's home directory.

2. ls - view directory contents

The command displays the contents of the specified directory. If the directory is not specified, the contents of the current directory:
ls -lahSPopular flags:
  • -l - long list (rights, owner, group, size, creation time and the file/directory itself);
  • -a - show hidden files (start with a dot .);
  • -h - human-friendly display of file size;
  • -S - sort by size (large files on top);
  • -t - sort by time (new files on top).
20250825_b5KSxIcH

3. pwd - where am I?

Sometimes scripts need to specify the full path to a directory. A simple command to display the full path of the current directory:
pwd20250825_VaDECoHg

4. mkdir - create directory

The command creates a new directory. In the example, this is the newPath directory in the modules directory, which we also create automatically:
mkdir -p modules/newPathPopular flags:
  • -p - create nested directories if they do not exist.
20250825_uVnWDTCW

5. rm - delete

The command deletes files and directories. In the example, we delete the newPath directory that we created earlier:
rm -rf modules/newPathPopular flags:
  • -i - request confirmation for deletion (interactive);
  • -r - recursive delete, directory delete;
  • -f - forced deletion (no questions asked).
20250826_LgfhgXNJ

6. cp - copy files and directories

Basic command for copying files and directories, including recursively. In the example, we copy the wp-content directory to wp-content_backup while preserving all rights:
cp -ar wp-content/ wp-content_backup/20250825_TvoGv3CB
Or we can copy only one index.php file to the wp-content_backup directory:
cp -av index.php wp-content_backup/20250825_rAJeuUQ2
Popular flags:
  • -a - preserve file attributes;
  • -r - copy recursively (directory);
  • -i - ask for confirmation when overwriting a file;
  • -v - detailed output of information about the copying progress.

7. mv - move or rename

The command moves files and directories and changes their name. Let's rename the index.php file to index_old.php:
mv -iv index.php index_old.php20250825_rbD1VkVu
We can also move the new file to the wp-content_backup directory:
mv -iv index_old.php wp-content_backup/20250825_z350sB0k
Popular flags:
  • -i - ask for confirmation when rewriting;
  • -v - detailed output of information about the progress of execution.

8. grep - find the required lines

We have previously used the grep utility to search for and highlight a specific word from the ls command output. However, the utility has many more capabilities and is very often used to recursively search for a specific string across multiple files and directories. As an example, let's find a file that contains the Nginx configuration for the domain.com domain:
grep -ri "domain.com" /etc/nginxThe search was successful, we received the file and the entry string:
20250825_6mVk9X3F
As we have seen before, grep works well not only with files, but also with command output. For example, let's filter the output of the ps command, showing only the Nginx and MariaDB processes, and also enable highlighting of matches:
ps aux | grep --color=auto -E "(nginx|mariadb)"20250825_Y6GqwulT
Popular flags:
  • -i - ignore case when searching;
  • -n - display line numbers;
  • -r - recursive directory search;
  • -v - inverse search (output of lines that do not match the search expression);
  • -E - use extended regular expressions;
  • --color=auto - turns on highlighting of matches.

9. tail - an indispensable tool for viewing log files

The utility is used to display the last lines of a file, as well as to view file changes in real time. Useful when working with log files:
tail -5 dpkg.logOutputs the last 5 lines of the specified file. In the dpkg.log example:
20250825_WpEngY2S
Popular flags:
  • -n - output the specified number of lines at the end of the file. Analog -[NUM].
  • -f - "monitor" the contents of a file in real time.

10. head - the reverse analogue of tail

The most current data is written to the end of the log file. However, sometimes we need to know when the log file began. The head utility outputs a specified number of lines from the beginning of the file. In the example, we output the first line of the dpkg.log log file:
head -1 dpkg.log20250825_znp4fARB
  • -n - output the specified number of lines from the beginning of the file. Analog -[NUM].

11. find - advanced file search

The find utility is used to search for files by mask, name, type, size, date. It is a powerful tool for automating many server management processes and deserves a separate article, but we will consider only the most popular parameters.

For example, let's find all files with the .jpg extension in the current and child directories:
find . -type f -name "*.jpg"Since the output will be huge, for convenience we will simply count the found files using the utility wc -l:
20250825_iuSyLjZm
The team found 170 jpg files in the site directory. That's not bad, but the whole point of the find utility is in its various filters. We'll add a new condition to our search - the files must be larger than 300 kilobytes:
find . -type f -name "*.jpg" -size +300kWe get only 6 files and can view the output in full:
20250825_v2YLPyCT
But that's not all. The most important function of find is the ability to execute a specified command on each file or directory found. For example, we will execute the ls -lh command on each file found, but in real tasks it can be anything, even your own scripts:
find . -type f -name "*.jpg" -size +300k -exec ls -lh {} \;20250825_gWVsJVkp
Popular flags:
  • -type f - type of object to search for (f - file, d - directory);
  • -name "*.jpg" - name, file name mask;
  • -size +300k - search for files larger(+) or smaller(-) than the specified size(k, M, G);
  • -print - output of search results;
  • -delete - deleting found files;
  • -exec [CMD] {} \; - run command [CMD] for each file found;

12. chmod - access rights management

Utility for managing access rights to files and directories. Most webmasters are accustomed to the digital designation of rights, where a three-digit number is used:
  1. Owner (u)
  2. Group (g)
  3. Other (o)
Each of these numbers is the sum of the rights values:
  • Read (r) = 4
  • Write (w) = 2
  • Execut (x) = 1
For example, rights 644 for a file are:
  • 6 = 4 (r) + 2 (w). The owner has read and write (edit) rights to the file;
  • 4 = 4 (r). Users in the file's group can only read the file;
  • 4 = 4 (r). All others can only read the file.
Command to set permissions to 644 for the specified file (index.php):
chmod 644 index.php20250825_3QV17YFA
Linux users are accustomed to a more convenient designation of rights and roles - letter (letter designations of rights are indicated in brackets). In it, setting rights 644 for a file looks like this:
chmod u+rw,g+r,o+r index.phpWe literally added (+) to the user (u) read (r) and write (w) rights, to the group (g) read (r) rights, and to others (o) also read (r):
20250825_fp39u7bm
To remove (-) or set specific rights (=) you need to use the same logic. Remove the read right (r) for all others (o):
chmod o-r index.php20250825_qgDvEltQ
To set new specific rights for the user (u) to execute (x), read (r) and write (w):
chmod u=rwx index.php20250825_n4OzFw3s
Useful flags:
  • -R - recursive application of rights for a directory and its contents.

13. chown - change user and group of file

When gaining root access to a new server, some users upload site files under the root user. However, running site scripts as the root user is dangerous for the entire server. Using a simple chown command, you can change the user and group for the entire site directory recursively:
chown -R user01:user01 /path/to/dir
  • -R - recursive execution of an operation.
In the example we set the user and group user01 for the domain directory:
20250825_aiyh3DJN

14. df - free disk space

The df utility displays information about mounted partitions on the server and the space used on them.
df -Th
  • -T - output file system type;
  • -h - human-friendly display of units of measurement.
20250825_4hE5o3vw

15. du - find out the size of directories and files

Unlike df, which takes information from the file system, du takes measurements of the files being processed directly.
Using du, we can find out the size of a specific directory:
du -sh /var/www20250825_rbHVsnKP
Or each directory and file in it separately:
du -sh /var/www/*20250825_wo7mfmPQ
Popular flags:
  • -h - human-friendly display of units of measurement;
  • -s - only the total for each argument.
A very convenient utility for determining large directories. Has an interesting pseudo-graphical analogue - ncdu:
20250825_JGmIKqeo
However, the latter should be used with caution if the server uses large amounts of disk space, since the utility automatically goes through all nested directories recursively.

We have reviewed 15 of the most popular commands for a server with an operating system based on the Linux kernel. This list can be fully called the minimum base that is necessary for a confident start in learning Linux administration. Master them at the level of muscle memory and you will never need a control panel on the server to work with your sites. If you have any difficulties with executing these commands on our VPS and dedicated servers, you can contact our technical support at any time through the ticket system or online chat on the site.