Skip to content

Basic Linux Commands

PotatoScript edited this page Mar 30, 2025 · 1 revision

🖥️ Basic Linux Commands Tutorial


🌟 1. What Are Linux Commands?


💡 Linux Commands are like giving instructions to your computer.
✅ You type the command in the Terminal.
✅ The computer follows your instructions.

🎮 Think of it like this:

  • 🕹️ Terminal – Your game console.
  • ⌨️ Commands – Game cheat codes!
  • 🎉 Result – Your system follows the command!
# Open Terminal using:
Ctrl + Alt + T

🎯 2. Why Should You Learn Linux Commands?


Powerful Control: Manage your system easily.
Automation: Do tasks quickly without GUI.
Fun & Fast: It’s like being a hacker in a movie! 🕶️💻


📚 3. Basic Linux Command Syntax


🔥 General Command Structure:

command [options] [arguments]

command: What you want to do (e.g., ls)
options: Customize the behavior (e.g., -l to list files in detail)
arguments: Specify the target (e.g., a file name)


🚀 4. Basic Linux Commands with Examples


📂 1. ls – List Files and Directories


💡 ls (list) shows all files and folders in the current directory.

ls

📚 Examples:

ls              # List all files 📂
ls -l           # List in detailed format 📄
ls -a           # Show hidden files 🕵️‍♂️

📍 2. pwd – Show Current Directory


💡 pwd (print working directory) shows where you are in the system.

pwd

📚 Example:

/home/lucy

Use Case: To check your current location before running commands.


🚪 3. cd – Change Directory


💡 cd (change directory) moves you to another folder.

cd [directory_name]

📚 Examples:

cd /home/lucy       # Go to Lucy’s home 📚
cd /etc            # Go to system configuration 📂
cd ..              # Move up one level ⬆️
cd ~               # Go to home directory 🏡

🗂️ 4. mkdir – Create a New Directory


💡 mkdir (make directory) creates a new folder.

mkdir [folder_name]

📚 Examples:

mkdir projects      # Create "projects" folder 📂
mkdir /home/lucy/new_folder  # Create in a specific path 🗂️

🗑️ 5. rm – Remove Files and Directories


💡 rm (remove) deletes files or folders.

rm [file_name]

📚 Examples:

rm file.txt         # Delete a file 🗑️
rm -r folder_name   # Delete a folder and its content 🧹
rm -rf /folder      # Force delete (Be careful!) ⚠️

📝 6. touch – Create an Empty File


💡 touch creates a blank file.

touch [file_name]

📚 Examples:

touch notes.txt     # Create an empty file 📄

🚚 7. mv – Move or Rename Files


💡 mv (move) moves or renames files.

mv [source] [destination]

📚 Examples:

mv file.txt /home/lucy/    # Move file.txt 📂
mv old.txt new.txt         # Rename file.txt 📝

📄 8. cp – Copy Files and Directories


💡 cp (copy) duplicates files and folders.

cp [source] [destination]

📚 Examples:

cp file.txt /home/lucy/    # Copy file 📂
cp -r folder /backup/      # Copy folder recursively 🗂️

🔍 9. cat – View File Contents


💡 cat displays the contents of a file.

cat [file_name]

📚 Examples:

cat notes.txt   # Show file content 📄

Pro Tip: Combine with | more for large files:

cat largefile.txt | more

📝 10. nano – Edit Files


💡 nano is a simple text editor.

nano [file_name]

📚 Examples:

nano notes.txt    # Open and edit file 📚

Save and Exit:

  • Press Ctrl + O – Save
  • Press Ctrl + X – Exit

🔥 11. sudo – Run as Superuser


💡 sudo (superuser do) gives you admin powers.

sudo [command]

📚 Examples:

sudo apt update    # Update system 🔄
sudo rm -rf /      # Delete EVERYTHING (Do NOT run!) ⚠️

Be Careful: sudo gives you too much power! Use wisely.


📜 12. history – Show Command History


💡 history shows the list of previously run commands.

history

📚 Example:

history | grep ls

Pro Tip: Use !number to repeat a command:

!100

🕹️ 13. clear – Clear the Terminal Screen


💡 clear cleans up your terminal.

clear

📚 Example:

clear   # Clears the screen 🧹

💾 14. df – Check Disk Space


💡 df (disk free) shows disk space usage.

df -h

📚 Example:

df -h    # Show disk usage in human-readable format 📊

📚 15. du – Check Folder Size


💡 du (disk usage) shows the size of folders.

du -sh [folder_name]

📚 Examples:

du -sh /home/lucy     # Check folder size 📊

📦 16. tar – Compress Files and Folders


💡 tar creates or extracts compressed files.

# Create a tar archive
tar -cvf archive.tar folder_name
# Extract a tar archive
tar -xvf archive.tar

📚 Examples:

tar -cvf backup.tar /home/lucy    # Compress folder 📦
tar -xvf backup.tar               # Extract files 🗂️

17. ps – Show Running Processes


💡 ps shows the list of active processes.

ps aux

📚 Examples:

ps aux    # List all running processes 👀

🚨 18. kill – Kill a Running Process


💡 kill stops a process by its ID (PID).

kill [PID]

📚 Examples:

kill 1234   # Kill process with PID 1234 💀

🎯 19. chmod – Change File Permissions


💡 chmod (change mode) sets file permissions.

chmod [permissions] [file_name]

📚 Examples:

chmod 755 script.sh   # Give execute permissions 🛡️
chmod +x script.sh    # Make the script executable 🚀

🔐 20. chown – Change File Owner


💡 chown changes the owner of a file or folder.

chown [user:group] [file_name]

📚 Examples:

chown lucy:users file.txt   # Change owner to Lucy 👩‍💻

Clone this wiki locally