Practical Syntax, Examples & Expected Output
Purpose: Displays the full path of your current directory.
pwd
pwd
Verify your current location before creating, deleting, or moving files.
Purpose: Shows the contents of a directory.
ls [options]
| Option | Description |
|---|---|
| -l | Long listing format |
| -a | Show hidden files |
| -h | Human-readable file sizes |
| -t | Sort by modification time |
ls -lah
Purpose: Move from one directory to another.
| Action | Command |
|---|---|
| Go to Home | cd |
| Specific Directory | cd /var/log |
| One Level Up | cd .. |
| Previous Directory | cd - |
Purpose: Creates new directories.
mkdir project
mkdir -p project/src/images
project/
└── src/
└── images/
rm file.txt
rm -r project
rm -rf project
rm -rf permanently deletes files and directories.
mv report.pdf backup.pdf
cp -r website backup/
mv old.txt new.txt
mv report.pdf /home/ram/Documents/
cat notes.txt
cat > hello.txt
Hello Linux
Ctrl + D
grep "error" logfile.log
grep -i "warning" logfile.log
grep -r "password" /etc
find /home -name "*.pdf"
find . -empty
find . -mtime -7
chmod +x install.sh
chmod 755 script.sh
| Permission | Meaning |
|---|---|
| 7 | rwx |
| 5 | r-x |
| 4 | r-- |
sudo chown ram file.txt
sudo chown ram:developers project/
sudo chown -R apache:apache /var/www/html
df -h
du -sh Downloads
du -sh * | sort -h
ps -ef
ps -ef | grep httpd
top
| Key | Action |
|---|---|
| P | Sort by CPU |
| M | Sort by Memory |
| k | Kill Process |
| q | Quit |
kill 2345
kill -9 2345
pkill firefox
sudo systemctl start nginx
sudo systemctl stop nginx
sudo systemctl restart nginx
systemctl status nginx
sudo systemctl enable nginx
tar -cvf backup.tar project/
tar -czvf backup.tar.gz project/
tar -xzvf backup.tar.gz
ssh user@192.168.1.20
ssh -p 2222 user@example.com
ssh -i ~/.ssh/id_rsa user@example.com