Foundations

The Linux Command Line, Gently

ten commands that cover most of what you need to start

2 min readupdated by Syed Khaleel Ahmed

Security tools, servers and most of the cloud run Linux, and the command line is how you drive them. It looks unfriendly at first, but a small set of commands carries you a long way.

Finding your way around

  • pwd shows where you are. ls -la lists files, including hidden ones, with permissions and owners.
  • cd folder moves into a folder; cd .. goes up one level.
  • cat file prints a file. less file lets you page through a long one.

Searching and filtering

  • grep "text" file shows lines that contain text. grep -r "text" folder searches a whole folder.
  • find / -name "*.log" 2>/dev/null finds files by name.
  • head and tail show the start or end of a file. tail -f file follows a log as it grows.
  • The pipe | sends the output of one command into the next, which is the secret to the command line. For example: grep "Failed password" /var/log/auth.log | wc -l counts failed logins.

Permissions

ls -l shows something like -rwxr-xr--. The three groups are owner, group and everyone else, each with read (r), write (w) and execute (x). chmod changes them and chown changes the owner. Files that anyone can write to, or programs that run with elevated rights (sudo, the setuid bit), are classic places for privilege escalation.

Seeing the system

  • ps aux lists processes. top shows what is using resources.
  • ss -tulpn shows listening ports and which program owns them.
  • ip a shows network interfaces and addresses.
  • whoami and id show which user you are.

Be careful

Commands run with the power of the account you use. Do not paste commands you do not understand, be extra careful with sudo and rm, and practice in a safe virtual machine or a learning site, not on a machine you care about.[2]

Sources

  1. The Linux Documentation Project: Bash Beginners Guide
  2. OverTheWire: Bandit (practice wargame)

Test yourself

My notes

Private — saved only on this device, never sent anywhere.