Skip to content

Beginner's Guide to 🐧 Debian Linux Commands

A guide to mastering the essential Linux commands on Debian-based systems. We'll walk through each command step-by-step, explain what it does and provide simple examples.

Let's 🥽 dive in! 🥽 the world of Debian Linux!


The Terminal

All commands are done in terminal / powershell

To open the Terminal: Look for the terminal icon in your applications, or search for it, or press Ctrl + Alt + T.

1. pwd - Print Working Directory

What it does: Displays the full path of the current directory you're in.

How to use it:

  1. Type the Command:
pwd
  1. Press Enter: The terminal will display the current directory path.

Example:

$ pwd
/home/<yourusername>

This tells you that you're in the home directory.


2. ls - List Directory Contents

What it does: Shows the files and folders in the current directory.

How to use it:

  1. Type the Command:
ls
  1. Press Enter: You'll see a list of files and directories.

Common Flags:

  • -l : Long format (shows details like permissions, owner, size, and date).
  • -a : Includes hidden files (those starting with a dot .).

Example:

$ ls -l
total 12
drwxr-xr-x 2 yourusername yourusername 4096 Oct 1 12:00 Documents
-rw-r--r-- 1 yourusername yourusername   23 Oct 1 12:05 notes.txt

Using -l provides detailed information about each item.


3. cd - Change Directory

What it does: Moves you to a different directory.

How to use it:

  1. To Enter a Directory:
cd <Documents>
  1. To Go Back One Level:
cd ..
  1. To Return to Home Directory:
cd ~

Example:

$ cd <Documents>
$ pwd
/home/yourusername/Documents

You've moved into the Documents folder.


4. mkdir - Make Directory

What it does: Creates a new folder.

How to use it:

  1. Type the Command:
mkdir <NewFolder>
  1. Press Enter: A new directory named NewFolder is created.

Example:

$ mkdir <Projects>

You've created a folder called Projects.


5. touch - Create an Empty File

What it does: Creates a new, empty file.

How to use it:

  1. Type the Command:
touch <filename.txt>
  1. Press Enter: The file is created.

Example:

$ touch <notes.txt>

An empty file named notes.txt is now in your directory.


6. rm - Remove Files or Directories

What it does: Deletes files or directories.

Warning: Be careful! Deleted items can't be easily recovered.

How to use it:

  • To Remove a File:
rm <filename.txt>
  • To Remove a Directory and Its Contents:
rm -r <directoryname>

Common Flags:

  • -r : Recursively delete a directory and its contents.
  • -i : Prompts before every removal (safer).

Example:

$ rm <notes.txt>
$ rm -r <OldProjects>

You've deleted notes.txt and the OldProjects directory.


7. cp - Copy Files and Directories

What it does: Makes a copy of files or folders.

How to use it:

  • To Copy a File:
cp <original.txt> <copy.txt>
  • To Copy a Directory:
cp -r <OriginalFolder> <CopyFolder>

Example:

$ cp <notes.txt> <backup_notes.txt>
$ cp -r <Projects> <ProjectsBackup>

You've copied notes.txt and the Projects folder.


8. mv - Move or Rename Files and Directories

What it does: Moves or renames items.

How to use it:

  • To Move a File to Another Directory:
mv <file.txt> </path/to/destination/>
  • To Rename a File:
mv <oldname.txt> <newname.txt>

Example:

$ mv <notes.txt> <Documents/>
$ mv <old_notes.txt> <new_notes.txt>

You've moved notes.txt to Documents and renamed a file.


9. cat - View File Contents

What it does: Displays the content of a file.

How to use it:

  1. Type the Command:
cat <filename.txt>
  1. Press Enter: The file's contents appear in the terminal.

Example:

$ <cat> <notes.txt>
This is a note.

You can read what's inside notes.txt.


10. sudo - Run Command with Superuser Privileges

What it does: Executes commands with administrative rights.

How to use it:

  1. Type sudo Before Your Command:
sudo <command>
  1. Enter Your Password: If prompted.

Example:

$ sudo apt <update>

You've updated package information with admin rights.


11. apt - Advanced Package Tool

What it does: Installs, updates, and removes software packages.

Common Uses:

  • Update Package List:
sudo apt update
  • Upgrade Installed Packages:
sudo apt upgrade
  • Install a New Package:
sudo apt install <packagename>

Example:

$ sudo apt install nano

You've installed the nano text editor.


12. man - Manual Pages

What it does: Displays the user manual for commands.

How to use it:

  1. Type the Command:
man <commandname>
  1. Press Enter: Read through the manual.

Example:

$ man ls

You've opened the manual for the ls command.


13. echo - Display a Line of Text

What it does: Prints text to the terminal.

How to use it:

  1. Type the Command:
echo <"Your message here">
  1. Press Enter: The message appears.

Example:

$ echo <"Hello, Debian!">
Hello, Debian!

You've printed a greeting to the terminal.


14. grep - Search for Patterns in Text

What it does: Finds specific text within files.

How to use it:

  1. Type the Command:
grep <'searchterm'> <filename.txt>
  1. Press Enter: Lines containing the term are displayed.

Common Flags:

  • -i : Ignore case differences.
  • -r : Search directories recursively.

Example:

$ grep <'error'> <logfile.txt>

You've searched for the word "error" in logfile.txt.


15. find - Search for Files and Directories

What it does: Locates files or folders based on criteria.

How to use it:

  1. Type the Command:
find </path> -<name> <'filename'>
  1. Press Enter: Matching items are listed.

Example:

$ find </home/yourusername> <-name> <'notes.txt'>

You've searched your home directory for notes.txt.


16. chmod - Change File Permissions

What it does: Modifies who can read, write, or execute files.

How to use it:

  1. Type the Command:
chmod <permissions> <filename>
  1. Press Enter: Permissions are changed.

Understanding Permissions:

  • Numbers Represent Permissions:
  • 4 : Read (r)
  • 2 : Write (w)
  • 1 : Execute (x)
  • Combine Numbers:
  • 7 (4+2+1) : Read, write, and execute
  • The three numbers represent user, group, and others.

Example:

$ chmod 755 script.sh

script.sh is now executable by all, but only writable by you.


17. chown - Change File Owner and Group

What it does: Changes who owns a file or directory.

How to use it:

  1. Type the Command:
sudo chown <newowner:newgroup> <filename>
  1. Press Enter: Ownership is updated.

Example:

$ sudo chown root:root systemfile

You've changed the owner and group of systemfile to root.


18. tar - Archive Utility

What it does: Creates or extracts .tar archive files.

How to use it:

  • To Create an Archive:
tar -cvf archive.tar /path/to/directory
  • To Extract an Archive:
tar -xvf archive.tar

Common Flags:

  • -c : Create an archive.
  • -x : Extract an archive.
  • -v : Verbose