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:
- Type the Command:
- Press Enter: The terminal will display the current directory path.
Example:
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:
- Type the Command:
- 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:
- To Enter a Directory:
- To Go Back One Level:
- To Return to Home Directory:
Example:
You've moved into the Documents
folder.
4. mkdir
- Make Directory¶
What it does: Creates a new folder.
How to use it:
- Type the Command:
- Press Enter: A new directory named
NewFolder
is created.
Example:
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:
- Type the Command:
- Press Enter: The file is created.
Example:
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:
- To Remove a Directory and Its Contents:
Common Flags:
-r
: Recursively delete a directory and its contents.-i
: Prompts before every removal (safer).
Example:
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:
- To Copy a Directory:
Example:
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:
- To Rename a File:
Example:
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:
- Type the Command:
- Press Enter: The file's contents appear in the terminal.
Example:
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:
- Type
sudo
Before Your Command:
- Enter Your Password: If prompted.
Example:
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:
- Upgrade Installed Packages:
- Install a New Package:
Example:
You've installed the nano
text editor.
12. man
- Manual Pages¶
What it does: Displays the user manual for commands.
How to use it:
- Type the Command:
- Press Enter: Read through the manual.
Example:
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:
- Type the Command:
- Press Enter: The message appears.
Example:
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:
- Type the Command:
- Press Enter: Lines containing the term are displayed.
Common Flags:
-i
: Ignore case differences.-r
: Search directories recursively.
Example:
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:
- Type the Command:
- Press Enter: Matching items are listed.
Example:
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:
- Type the Command:
- 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:
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:
- Type the Command:
- Press Enter: Ownership is updated.
Example:
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:
- To Extract an Archive:
Common Flags:
-c
: Create an archive.-x
: Extract an archive.-v
: Verbose