Skip to content

Linux command line essentials

The commands you will use every day on a Linux system: moving around, working with files, permissions, packages, processes and services, and finding help.

Linux command line essentials

Most servers on the internet and in the cloud run Linux, and the command line is the fastest way to work with them. This guide covers the commands you will use every day. Try each one in a virtual machine or a test system as you read.

Finding your way around

  • pwd prints the directory you are in.
  • ls -la lists files, including hidden ones, with permissions, owners and sizes.
  • cd /etc moves to a directory; cd .. goes up one level and cd ~ goes to your home directory.

Linux paths start at the root /. Configuration usually lives in /etc, logs in /var/log, and user files in /home.

Working with files

  • mkdir projects creates a directory.
  • cp file.txt backup.txt copies a file; add -r to copy a directory.
  • mv old.txt new.txt moves or renames.
  • rm file.txt deletes a file. There is no recycle bin, so check before you delete, and be especially careful with rm -r.
  • cat prints a short file, less lets you scroll through a long one, and head and tail show the beginning and end. tail -f /var/log/syslog follows a log as new lines arrive (on some distributions the system log is read with journalctl instead).

Searching

  • grep "error" app.log shows the lines that contain a word. grep -r searches a whole directory and grep -i ignores case.
  • find /var/log -name "*.log" finds files by name.

Pipes and redirection

The real power of the command line is combining small tools. A pipe | sends the output of one command to the next: grep "Failed password" /var/log/auth.log | tail -n 20 shows the last twenty failed logins (the file name varies by distribution). Redirection saves output: > writes to a file, replacing its content, and >> appends.

Users, permissions and sudo

Every file has an owner, a group, and permissions for the owner, the group and everyone else. ls -l shows them as letters, for example rwxr-xr-x: r is read, w is write and x is execute.

  • chmod 644 notes.txt gives the owner read and write, and everyone else read only.
  • chmod 755 script.sh makes a script executable by everyone and writable only by its owner.
  • chown alice:staff report.txt changes the owner and group.

Administrative commands need elevated rights. sudo runs a single command as the administrator. Use it only when needed, and read a command carefully before you add sudo to it.

Installing software

Distributions use package managers to install and update software from trusted repositories. On Debian and Ubuntu: sudo apt update then sudo apt install nginx. On Red Hat-based systems such as Fedora, Rocky Linux and AlmaLinux: sudo dnf install nginx. Keep systems updated regularly; most security fixes arrive this way.

Processes and services

  • ps aux lists running processes, and top shows them live, sorted by resource use. Press q to quit.
  • kill 1234 asks the process with ID 1234 to stop.
  • On most modern distributions, services are managed by systemd: systemctl status nginx shows whether a service is running, sudo systemctl restart nginx restarts it, and sudo systemctl enable nginx starts it at boot.
  • journalctl -u nginx shows the logs of a single service.

Disk and network

  • df -h shows free space on each file system, and du -sh * shows how much space each item in a directory uses.
  • ip a shows network interfaces and addresses, and ss -tulpn shows which ports are listening.

Getting help

You do not need to memorise options. man ls opens the manual for a command, and most commands accept --help for a short summary. Reading manuals is a skill in itself, and it is one that experienced administrators use every day.

Practise

Create a virtual machine with a free Linux distribution and give yourself small tasks: create a user, set permissions on a shared directory, install a web server, find its logs, and restart it. The LPI Linux Essentials course is the first step in both the IT support and cloud engineer paths, and it covers these topics in a structured order.