Skip to content

Linux Commands ​

pwd - Print Working Directory ​

bash
pwd

Displays the full path of the current working directory.

ls - List Directory Contents ​

bash
ls              # Basic listing
ls -l           # Long format listing
ls -a           # Show hidden files
ls -la          # Long listing including hidden files
ls -lh          # Long listing with human-readable file sizes

cd - Change Directory ​

bash
cd /path/to/directory   # Change to specific directory
cd ~                    # Change to home directory
cd ..                   # Move up one directory
cd -                    # Return to previous directory

File Operations ​

touch - Create Empty Files ​

bash
touch file.txt          # Create a new file or update timestamp
touch file1.txt file2.txt   # Create multiple files

mkdir - Create Directories ​

bash
mkdir directory         # Create a new directory
mkdir -p dir1/dir2/dir3 # Create nested directories

cp - Copy Files and Directories ​

bash
cp source.txt destination.txt         # Copy a file
cp -r source_dir destination_dir      # Copy directories recursively

mv - Move or Rename Files ​

bash
mv old_name.txt new_name.txt          # Rename a file
mv file.txt /path/to/destination/     # Move a file

rm - Remove Files and Directories ​

bash
rm file.txt             # Delete a file
rm -i file.txt          # Interactive deletion (prompts before deleting)
rm -r directory         # Delete directory and contents recursively
rm -rf directory        # Force delete directory without prompts (use with caution!)

File Viewing Commands ​

cat - Concatenate and Display File Contents ​

bash
cat file.txt            # Display entire file content
cat file1.txt file2.txt # Display multiple files

less - View File Content with Pagination ​

bash
less file.txt           # View file with pagination

Use arrow keys to navigate, press q to exit.

head - Display Beginning of File ​

bash
head file.txt           # Display first 10 lines
head -n 20 file.txt     # Display first 20 lines

tail - Display End of File ​

bash
tail file.txt           # Display last 10 lines
tail -n 20 file.txt     # Display last 20 lines
tail -f log.txt         # Follow a file in real-time (useful for logs)

grep - Search Text Patterns ​

bash
grep "pattern" file.txt         # Search for pattern in file
grep -i "pattern" file.txt      # Case-insensitive search
grep -r "pattern" directory/    # Recursive search in directory

System Information Commands ​

uname - Print System Information ​

bash
uname -a               # All system information
uname -s               # Kernel name
uname -r               # Kernel release

df - Disk Space Usage ​

bash
df                     # Show disk space usage
df -h                  # Human-readable format

free - Memory Usage ​

bash
free                   # Show memory usage
free -h                # Human-readable format

top - Process Monitoring ​

bash
top                    # Dynamic real-time view of processes

Press q to exit.

ps - Process Status ​

bash
ps                     # Show current processes
ps aux                 # Show all processes in detail

User Management Commands ​

whoami - Print Current User ​

bash
whoami                # Display current username

su - Switch User ​

bash
su username           # Switch to another user
su -                  # Switch to root user (with environment)

sudo - Execute Command as Superuser ​

bash
sudo command          # Execute command with superuser privileges
sudo -i               # Start a shell as root

passwd - Change Password ​

bash
passwd                # Change your password
sudo passwd username  # Change another user's password (as admin)

File Permissions ​

chmod - Change File Permissions ​

bash
chmod 755 file.txt    # Change permissions using octal notation
chmod u+x script.sh   # Add execute permission for user
chmod -R 755 directory # Change permissions recursively

chown - Change File Owner ​

bash
chown user:group file.txt     # Change owner and group
chown -R user directory       # Change recursively

Network Commands ​

ping - Test Network Connectivity ​

bash
ping google.com       # Send ICMP echo requests
ping -c 4 google.com  # Send only 4 packets

ifconfig/ip - Network Interface Configuration ​

bash
ifconfig              # Show network interfaces
ip addr show          # Modern equivalent

netstat - Network Statistics ​

bash
netstat -tuln         # Show listening ports

ssh - Secure Shell ​

bash
ssh username@hostname  # Connect to remote host

Archiving and Compression ​

tar - Archive Files ​

bash
tar -cvf archive.tar directory/   # Create archive
tar -xvf archive.tar              # Extract archive
tar -zcvf archive.tar.gz directory/ # Create compressed archive
tar -zxvf archive.tar.gz          # Extract compressed archive

zip/unzip - Zip Files ​

bash
zip -r archive.zip directory/     # Create zip archive
unzip archive.zip                 # Extract zip archive

Package Management ​

Debian/Ubuntu (apt) ​

bash
apt update                        # Update package lists
apt upgrade                       # Upgrade installed packages
apt install package_name          # Install packages
apt remove package_name           # Remove packages

Red Hat/Fedora (dnf/yum) ​

bash
dnf update                        # Update packages
dnf install package_name          # Install packages
dnf remove package_name           # Remove packages

Redirects and Pipes ​

Redirecting Output ​

bash
command > file.txt                # Redirect output to file (overwrite)
command >> file.txt               # Append output to file
command 2> error.log              # Redirect errors to file

Pipes ​

bash
command1 | command2               # Pipe output of command1 to command2
ls -la | grep "pattern"           # List files and filter with grep

Practice Exercises ​

  1. Navigate to your home directory and create a new directory called "linux_practice"
  2. Create five empty files inside this directory named file1.txt through file5.txt
  3. Create a text file with some content using a command
  4. List all files, including hidden ones, in long format
  5. Rename file1.txt to first_file.txt
  6. Copy file2.txt to backup_file2.txt
  7. Move file3.txt to a subdirectory
  8. Delete file4.txt
  9. Check how much disk space is available on your system
  10. Find all files in your home directory that contain the word "linux"

In the next sections, we'll dive deeper into the Linux file system, permissions, and process management.