Basic Linux commands for beginners

Linux 2 min read

If you are new to the Linux terminal, learning a few basic commands will enable you to navigate the file system with confidence. You can enter these commands via an SSH connection; the process of connecting is described in the article on connecting to a VPS via SSH. Below, we outline the most commonly used commands.

  • pwd: shows which directory you are currently in.
  • ls: lists the contents of the current directory. The ls -la command also displays hidden files (those beginning with a full stop) and detailed information (permissions, owner, size, date).
  • cd mappanev: enters the specified directory. cd .. moves up one level, cd ~ (or simply cd) takes you to your home directory, and cd - returns you to the previous directory.

A path can be absolute (starting from the root with a /, for example /var/www/html) or relative (relative to the current directory, for example html/wp-content).

Managing files and folders

  • cp forras cel: copies a file. To copy folders, use the -r (recursive) option: cp -r mappa/ cel/.
  • mv forras cel: moves or renames a file or folder.
  • rm fajlnev: deletes the file. To delete folders, use the -r switch: rm -r mappa/. There is no recycle bin on Linux, and deletion cannot be undone, so always check the path before using rm -rf.
  • mkdir mappanev: creates a new directory. The command mkdir -p a/b/c also creates any missing parent directories.
  • touch fajlnev: creates an empty file or updates the modification date of an existing file.

Viewing the contents of files

  • cat fajlnev: displays the full contents of the file.
  • less fajlnev: displays the file in a paginated view (search: /szöveg, exit: q).
  • head -n 20 fajlnev and tail -n 20 fajlnev: the first and last 20 lines of the file, respectively.
  • tail -f naplo.log: continuously displays new lines as they are written to the file; ideal for monitoring logs (to exit: Ctrl+C).
  • nano fajlnev: a simple text editor. Our article on text editors covers the basics of nano and vim.
  • grep 'szöveg' fajlnev prints the lines containing the text. grep -r 'szöveg' mappa/ searches an entire directory. We’ll explain how to display the lines before and after the grep results in a separate article.
  • find /var/www -name 'wp-config.php': searches for files by name.

System status

  • df -h: disk space usage; du -sh mappa: the size of a folder (see: checking disk usage).
  • free -h: memory and swap usage.
  • uptime: how long the server has been running and what its load is.
  • top: running processes in real time.

Users and permissions

  • whoami: which user you are logged in as.
  • sudo parancs: runs the command with root privileges.
  • chmod and chown: changing file permissions and ownership; see: file permissions in Linux.

Help and useful tips

  • man parancsnev: the command’s built-in documentation (exit: q); many commands display a brief help message when the --help switch is used.
  • The Tab key autocompletes file and command names, so you need to type less and can avoid typing errors.
  • Use the up arrow to recall previous commands; the history lists previous commands.
  • Ctrl+C cancels the command currently being executed.

You can try out these commands on any Linux system, including your own KVM VPS.

Back: Linux articles (62)