-
Notifications
You must be signed in to change notification settings - Fork 0
Basic 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✅ Powerful Control: Manage your system easily.
✅ Automation: Do tasks quickly without GUI.
✅ Fun & Fast: It’s like being a hacker in a movie! 🕶️💻
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)
💡 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 🕵️♂️💡 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.
💡 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 🏡💡 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 🗂️💡 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!) ⚠️💡 touch creates a blank file.
touch [file_name]📚 Examples:
touch notes.txt # Create an empty file 📄💡 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 📝💡 cp (copy) duplicates files and folders.
cp [source] [destination]📚 Examples:
cp file.txt /home/lucy/ # Copy file 📂
cp -r folder /backup/ # Copy folder recursively 🗂️💡 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💡 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
💡 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.
💡 history shows the list of previously run commands.
history📚 Example:
history | grep ls✅ Pro Tip: Use !number to repeat a command:
!100💡 clear cleans up your terminal.
clear📚 Example:
clear # Clears the screen 🧹💡 df (disk free) shows disk space usage.
df -h📚 Example:
df -h # Show disk usage in human-readable format 📊💡 du (disk usage) shows the size of folders.
du -sh [folder_name]📚 Examples:
du -sh /home/lucy # Check folder size 📊💡 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 🗂️💡 ps shows the list of active processes.
ps aux📚 Examples:
ps aux # List all running processes 👀💡 kill stops a process by its ID (PID).
kill [PID]📚 Examples:
kill 1234 # Kill process with PID 1234 💀💡 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 🚀💡 chown changes the owner of a file or folder.
chown [user:group] [file_name]📚 Examples:
chown lucy:users file.txt # Change owner to Lucy 👩💻