-
Notifications
You must be signed in to change notification settings - Fork 0
Linux Basic & Advance Commands
sreepathysois edited this page Nov 27, 2025
·
1 revision
| Command | Example | Explanation |
|---|---|---|
pwd |
pwd |
Shows the current working directory path. |
ls |
ls |
Lists files and directories in the current location. |
ls -la |
ls -la |
Lists all files including hidden ones, with detailed info like permissions and size. |
mkdir |
mkdir projects |
Creates a new directory named projects. |
cd |
cd projects |
Moves into the specified directory. |
cd .. |
cd .. |
Moves one level up (to parent directory). |
cd ~ |
cd ~ |
Takes you to your home directory. |
cd / |
cd / |
Takes you to the root directory. |
| Command | Example | Explanation |
|---|---|---|
rm |
rm file.txt |
Deletes a file. |
rm -rf |
rm -rf folder |
Deletes folder and its contents recursively, forcefully. Dangerous — no confirmation! |
mv |
mv old.txt new.txt |
Renames a file. Also used to move files. |
cp |
cp file1.txt /tmp/ |
Copies a file to another location. |
cp -r |
cp -r folder /backup/ |
Copies a directory recursively. |
| Command | Example | Explanation |
|---|---|---|
chown |
chown user:group file.txt |
Changes ownership of file or directory. |
chmod |
chmod 755 script.sh |
Changes permissions of a file or directory. 755 = owner full access, others read/execute. |
| Symbol | Meaning |
|---|---|
r |
read |
w |
write |
x |
execute |
u |
user/owner |
g |
group |
o |
others |
a |
all |
Example: chmod u+x script.sh
Adds execute permission for the owner.
| Command | Example | Explanation |
|---|---|---|
cat |
cat file.txt |
Displays the contents of file.txt on the terminal. |
gedit filename |
gedit notes.txt |
Opens GUI text editor (for desktop Linux). |
vi filename |
vi notes.txt |
Opens file in vi editor. Press i to insert text, :wq to save & exit. |
nano filename |
nano notes.txt |
Opens file in nano editor (easy CLI editor). |
| Command | Example | Explanation |
|---|---|---|
touch |
touch index.html |
Creates an empty file. |
clear |
clear |
Clears the terminal screen. |
history |
history |
Shows the list of previously used commands. |
whoami |
whoami |
Prints the current logged-in username. |
| Command | Example | Explanation |
|---|---|---|
systemctl status |
systemctl status nginx |
Shows the running status of a service. |
systemctl start |
systemctl start nginx |
Starts a service. |
systemctl stop |
systemctl stop nginx |
Stops a service. |
systemctl restart |
systemctl restart nginx |
Restarts a service. |
systemctl enable |
systemctl enable nginx |
Enables service to start on boot. |
systemctl disable |
systemctl disable nginx |
Disables service from starting automatically. |
systemctl is-active |
systemctl is-active nginx |
Checks if a service is currently running. |
| Command | Example | Explanation |
|---|---|---|
cat |
cat /var/log/syslog |
Prints entire file content to terminal (use with caution for large logs). |
tail |
tail /var/log/syslog |
Shows the last 10 lines of a log file. |
tail -f |
tail -f /var/log/syslog |
Streams the log live (useful for debugging). |
head |
head file.txt |
Shows the first 10 lines of a file. |
journalctl |
journalctl -u nginx |
Shows logs of a systemd service like nginx. |
dmesg |
dmesg |
Displays kernel messages, often used for hardware/debug info. |
| Command | Example | Explanation |
|---|---|---|
grep |
grep "error" syslog |
Finds lines containing the word error. |
grep -i |
grep -i "error" syslog |
Case-insensitive search. |
grep -r |
grep -r "password" /etc |
Recursively search directories. |
grep -n |
grep -n "http" access.log |
Shows line numbers for matches. |
grep -v |
grep -v "debug" syslog |
Shows lines not containing the pattern. |
| Command | Example | Explanation |
|---|---|---|
ps |
ps aux |
Lists all running processes. |
top |
top |
Real-time view of CPU & memory usage. |
htop |
htop |
Enhanced version of top (if installed). |
kill |
kill 1234 |
Kills process with PID 1234. |
kill -9 |
kill -9 1234 |
Force kill a process (immediate termination). |
pgrep |
pgrep nginx |
Finds PID of a process by name. |
| Command | Example | Explanation |
|---|---|---|
ifconfig / ip a
|
ip a |
Shows network interfaces and IP addresses. |
ping |
ping google.com |
Tests network connectivity to a host. |
curl |
curl https://example.com |
Fetches data from a URL. |
wget |
wget https://file.com/app.zip |
Downloads files from the internet. |
netstat -tulnp |
netstat -tulnp |
Shows listening ports and services. |
ss -tulnp |
ss -tulnp |
Modern replacement for netstat. |
| Command | Example | Explanation |
|---|---|---|
df -h |
df -h |
Shows disk usage in human-readable format (GB/MB). |
du -sh |
du -sh /var/log |
Shows size of a directory. |
mount |
mount /dev/sdb1 /data |
Mounts a disk/device. |
fdisk |
fdisk -l |
Lists disk partitions. |
| Command | Explanation |
|---|---|
uname -a |
Shows kernel and OS details. |
uptime |
Shows how long the system is running. |
hostname |
Prints system hostname. |
free -h |
Memory usage in human-readable format. |