Main content

1. ls: List directory contents

Description: The ls command is used to list the contents of a directory.

Syntax: ls [options] [directory]

Example: ls /home/user

Output: file1.txt file2.txt file3.txt

In short: Show what’s in a folder. Why: Quickly see files and subfolders before you act.

ls /home/$USER
ls -l /home/$USER
ls -lah

2. cd: Change directory

Description: Navigate the filesystem; cd with no args moves to your home directory.

In short: Move to a different folder. Why: Get to where your files are to run commands there.

cd ~
cd /var/log
cd ..
cd -

3. pwd: Print working directory

Description: Print the absolute path of the current directory.

In short: Show where you are. Why: Avoid mistakes by confirming your current path (useful in scripts too).

pwd

4. mkdir: Create a new directory

Description: Create directories; use -p to create parent dirs as needed.

In short: Make a new folder. Why: Organize projects and files into tidy places.

mkdir projects
mkdir -p projects/javascript/project-1
mkdir dir1 dir2 dir3

5. rm: Remove a file or directory

Danger: removal is permanent unless you use a trash utility. Double-check paths before running destructive commands.

In short: Delete files or folders. Why: Clean up clutter or remove things you no longer need.

rm file.txt
rm -r myfolder
rm -rf unwanted-folder
rm -i filename

6. cp: Copy a file or directory

Use -r to copy directories, -a to preserve attributes.

In short: Make a duplicate. Why: Back up files or copy them to other locations.

cp file.txt file.backup.txt
cp file.txt /tmp/
cp -r folder1 folder2
cp -a folder1 folder1-backup

7. mv: Move or rename a file or directory

Moves/renames files. Use -i for interactive confirmation to avoid accidental overwrites.

In short: Move or rename files/folders. Why: Keep things organized or change names safely.

mv oldname.txt newname.txt
mv file.txt ~/documents/
mv file1.txt file2.txt ~/backup/

8. touch: Create a new file

Creates an empty file if missing or updates file timestamps.

In short: Create a blank file fast. Why: Start a new file or trigger tools that watch timestamps.

touch notes.txt
touch existing-file.txt
touch a.txt b.txt c.txt

9. cat: Display the contents of a file

Prints files to stdout. For long files, prefer less to paginate output.

In short: Show a file’s text. Why: Quickly read or combine files right in the terminal.

cat file.txt
cat file1.txt file2.txt
cat -n file.txt

10. echo: Print text to the terminal

Prints text or variables; commonly used in scripts and to write simple files.

In short: Output text or values. Why: Test commands, log info, or write quick content to files.

echo "Hello, world!"
echo $HOME
echo -n "No newline after this"
echo "data" > file.txt

11. Package Managers (common distributions)

Different distributions use different package managers — here are the most common ones with quick usage examples.

In short: Install, update, and remove software. Why: Safely manage apps and dependencies from trusted repositories.

Debian / Ubuntu (APT)

sudo apt update
sudo apt install package-name
sudo apt remove package-name
apt search term

Fedora / RHEL (DNF)

sudo dnf update
sudo dnf install package-name
sudo dnf remove package-name

CentOS (YUM — legacy)

sudo yum update
sudo yum install package-name

Arch Linux (pacman)

sudo pacman -Syu
sudo pacman -S package-name
sudo pacman -R package-name

openSUSE (zypper)

sudo zypper refresh
sudo zypper install package-name
sudo zypper remove package-name

Alpine (apk)

sudo apk update
sudo apk add package-name

Gentoo (emerge)

sudo emerge --sync
sudo emerge package/name

Flatpak & Snap (universal)

flatpak install flathub org.example.App
sudo snap install package-name

12. sudo: Run commands as superuser

Description: sudo temporarily elevates privileges to run commands as root (superuser). Use carefully — privileged actions affect the whole system.

In short: Run a command with admin rights. Why: Do system-level tasks that a normal user can’t.

sudo command
sudo -i
sudo -s
sudo su -
sudo visudo
sudo -u otheruser command

Notes & safety

  • By default, sudo asks for your user password (not root's) and logs commands.
  • Use visudo to safely edit /etc/sudoers (it checks syntax before saving).
  • Prefer sudo for single commands instead of a persistent root shell for safety.
  • On systems without sudo, you may need to use su to switch to root.