This guide is for beginners and pros alike. Whether you're SSH-ing into a remote server or just trying to rename a file without breaking things, these Linux commands will save your day.
1. Navigating the File System
Before you do anything, you need to know where you are in the Linux world. These commands will help you move around like a pro.
🔹 pwd → Prints your current working directory.
pwd
Ever gotten lost in folders? This tells you exactly where you are.
🔹 ls → Lists files and directories.
ls
ls -l # Detailed list
ls -a # Shows hidden files
Because sometimes, that file you swear is there is just hidden.
🔹 cd → Changes directory.
cd /home/user/Documents # Go to a specific directory
cd .. # Move up one directory
cd ~ # Go to home directory
No need to click around, just type and move!
2. File and Directory Manipulation
Creating, deleting, and modifying files without a GUI? You bet.
🔹 touch → Creates an empty file.
touch newfile.txt
Like a blank canvas, but for text files.
🔹 mkdir → Creates a directory.
mkdir myFolder
Because organization is key.
🔹 rm → Removes files or directories.
rm filename.txt # Deletes a file
rm -r myFolder # Deletes a directory and its contents
⚠ Use with caution! There's no Recycle Bin here.
🔹 mv → Moves or renames files.
mv oldfile.txt newfile.txt # Rename file
mv file.txt /home/user/Documents # Move file to another directory
No dragging and dropping required!
🔹 cp → Copies files or directories.
cp file.txt copy_of_file.txt # Copy file
cp -r folder1 folder2 # Copy directory
Great for making backups before you "experiment".
3. Viewing and Editing Files
🔹 cat → Displays the contents of a file.
cat filename.txt
Great for small files. For large ones, use less
.
🔹 less → Allows you to scroll through a file.
less bigfile.txt
Much better than cat when dealing with huge logs.
🔹 nano, vim, emacs → Text editors for modifying files.
nano myfile.txt # Simple and user-friendly
vim myfile.txt # Advanced users only!
emacs myfile.txt # For those who like complex setups
Pick your side in the eternal vim vs emacs
debate.
4. Process Management
When things get out of control, these commands help you regain control.
🔹 ps → Shows currently running processes.
ps aux
Want to know what's hogging your CPU? This is your go-to.
🔹 kill → Terminates a process.
kill PID # Replace PID with process ID
kill -9 PID # Force kill if it refuses to die
Sometimes, you gotta be ruthless.
🔹 top → Shows real-time system usage.
top
Like Task Manager, but in the terminal.
5. User Management
🔹 whoami → Prints the current user.
whoami
Because sometimes you forget who you are.
🔹 adduser → Adds a new user.
sudo adduser newuser
🔹 passwd → Changes user password.
passwd
Security first! 🔒
🔹 sudo → Runs a command as root (admin privileges).
sudo apt update
⚠ Be careful! With great power comes great responsibility.
6. Networking & System Info
🔹 ifconfig / ip a → Shows network interfaces.
ifconfig
ip a
🔹 ping → Checks if a server is reachable.
ping google.com
🔹 wget → Downloads a file from the internet.
wget http://example.com/file.zip
🔹 uptime → Shows how long the system has been running.
uptime
🔹 df -h → Displays disk usage.
df -h
🔹 free -m → Shows available memory.
free -m
Useful when things feel... sluggish.
7. Permissions & Ownership
🔹 chmod → Changes file permissions.
chmod 755 myscript.sh
🔹 chown → Changes file ownership.
chown user:user file.txt
If you don’t own it, you can’t change it.
8. Package Management
For Ubuntu/Debian-based distros:
sudo apt update # Update package lists
sudo apt install package_name # Install a package
sudo apt remove package_name # Remove a package
For CentOS/RHEL:
sudo yum install package_name
For Arch:
sudo pacman -S package_name
Choose your Linux flavor wisely! 😎
Final Thoughts: Master Linux, Master the World
Linux can be intimidating at first, but once you get the hang of it, you'll feel unstoppable. These commands are just the beginning. Keep exploring, keep experimenting, and soon, you'll be navigating Linux like a true sysadmin.
💬 Got a favorite Linux command? Drop it in the comments below!
🚀 Happy Command-Lining!
0 comments:
Post a Comment