Opening the Terminal
On most Linux desktop environments, you can open the terminal with the keyboard shortcut Ctrl + Alt + T. You can also find it in your applications menu under "Terminal", "Console", or "Konsole" depending on your desktop environment.
When the terminal opens, you will see a prompt that typically looks like this:
This tells you your username, the computer name, your current directory (~ means your home folder), and that you are a regular user ($). A # symbol means you are the root (admin) user.
Navigating the File System
The Linux file system starts at the root directory / and branches out into directories. Understanding navigation is the first skill to master.
| Command | Description | Example |
|---|---|---|
pwd | Print current working directory | pwd → /home/user |
ls | List files and directories | ls -la (detailed list with hidden files) |
cd | Change directory | cd /var/log |
cd .. | Go up one directory level | cd .. |
cd ~ | Go to your home directory | cd ~ or just cd |
tree | Display directory structure as a tree | tree -L 2 (two levels deep) |
$ pwd
/home/user
# List files with details
$ ls -lah
drwxr-xr-x 5 user user 4.0K Apr 11 10:30 Documents
drwxr-xr-x 2 user user 4.0K Apr 10 09:15 Downloads
-rw-r--r-- 1 user user 220 Apr 1 12:00 .bashrc
# Navigate to Documents
$ cd Documents
$ pwd
/home/user/Documents
Working with Files and Directories
| Command | Description | Example |
|---|---|---|
touch | Create an empty file | touch newfile.txt |
mkdir | Create a directory | mkdir projects |
mkdir -p | Create nested directories | mkdir -p a/b/c |
cp | Copy files or directories | cp file.txt backup.txt |
mv | Move or rename files | mv old.txt new.txt |
rm | Remove files | rm unwanted.txt |
rm -r | Remove directories recursively | rm -r old-project |
rm with caution as there is no trash bin in the terminal. Consider using rm -i for interactive confirmation before each deletion.Viewing and Editing Files
| Command | Description | Example |
|---|---|---|
cat | Display entire file contents | cat config.txt |
less | View file with scrolling (press q to quit) | less /var/log/syslog |
head | Show first lines of a file | head -20 file.txt |
tail | Show last lines of a file | tail -f /var/log/syslog |
nano | Simple text editor in the terminal | nano myfile.txt |
vim | Powerful text editor (steep learning curve) | vim script.sh |
$ cat /etc/hostname
my-linux-pc
# Watch a log file in real time
$ tail -f /var/log/syslog
# Edit a file with nano (Ctrl+O to save, Ctrl+X to exit)
$ nano ~/notes.txt
Searching and Finding
| Command | Description | Example |
|---|---|---|
find | Search for files by name, type, or size | find / -name "*.conf" |
grep | Search text inside files | grep "error" logfile.txt |
grep -r | Search recursively in directories | grep -r "TODO" ./src |
which | Find the location of a command | which python3 |
locate | Fast file search using a database | locate nginx.conf |
Permissions and Ownership
Every file in Linux has permissions that control who can read, write, and execute it. Understanding permissions is essential for security and daily usage.
$ ls -l script.sh
-rwxr-xr-- 1 user group 1024 Apr 11 10:00 script.sh
# Change permissions (make executable)
$ chmod +x script.sh
# Change ownership
$ sudo chown user:group file.txt
# Set specific permissions (owner: rwx, group: rx, others: r)
$ chmod 754 script.sh
The permission string -rwxr-xr-- breaks down as: file type (-), owner permissions (rwx), group permissions (r-x), and others' permissions (r--).
System Information
| Command | Description |
|---|---|
uname -a | Display kernel and system information |
df -h | Show disk space usage in human-readable format |
free -h | Display memory usage |
top or htop | Show running processes and resource usage |
whoami | Display your current username |
uptime | Show how long the system has been running |
Pipes and Redirection
One of the most powerful features of the Linux command line is the ability to chain commands together using pipes (|) and redirect output to files.
$ ls -la | grep ".txt"
# Count the number of files in a directory
$ ls | wc -l
# Redirect output to a file
$ echo "Hello Linux" > greeting.txt
# Append to a file
$ echo "Another line" >> greeting.txt
# Sort and remove duplicates
$ cat names.txt | sort | uniq
Essential Keyboard Shortcuts
| Shortcut | Action |
|---|---|
Tab | Auto-complete commands and file names |
Ctrl + C | Cancel the current command |
Ctrl + L | Clear the screen |
Ctrl + R | Search command history |
Ctrl + A | Move cursor to the beginning of the line |
Ctrl + E | Move cursor to the end of the line |
Up Arrow | Recall the previous command |
Tab twice shows all possible completions. This is the single most useful habit you can develop when using the terminal.Ready to automate tasks?
Shell Scripting Guide →