أهم النقاط
- A few dozen commands cover most day-to-day server work.
- Use man or --help to see every option for a command.
- Be careful with rm, chmod and anything run with sudo.
Moving around and files
| Command | What it does |
|---|---|
pwd | Show the current folder |
ls -lah | List files with sizes, permissions and hidden files |
cd /var/www | Change folder (cd .. goes up, cd ~ goes home) |
cp -r src dest | Copy files or folders |
mv old new | Move or rename |
rm file / rm -r folder | Delete (permanently) |
mkdir -p a/b/c | Create folders |
nano file | Edit a file in the terminal |
cat, less, tail -f | View a file, page through it, follow it live |
Searching
grep -rn "DB_NAME" /var/www # find text in files
find /var/www -name "*.php" -mtime -2 # files changed in the last 2 days
Permissions and ownership
chmod 644 file.php # owner read/write, others read
chmod 755 folder # owner full, others read/enter
chown -R www-data:www-data /var/www/site
Use the chmod calculator to convert between numbers and letters.
Processes and resources
top # or htop: live CPU and memory use
free -h # memory
df -h # disk space
ps aux | grep php
kill PID # stop a process
Services and logs
sudo systemctl status nginx
sudo systemctl restart nginx
sudo journalctl -u nginx --since today
sudo tail -n 50 /var/log/nginx/error.log
Packages
sudo apt update && sudo apt upgrade
sudo apt install package-name
Networking
curl -I https://example.com # response headers
dig example.com A +short # DNS lookup
ss -tulpn # listening ports
ping -c 4 example.comالأسئلة الشائعة
How do I connect to my server to run these?
With SSH from a terminal: ssh username@your-server-ip. See our tutorial on connecting to a VPS with SSH.
Can I undo rm?
No — Linux has no recycle bin on the command line. Double-check paths, and keep backups.