Some useful Linux commands
-
cat
cat [file]
- cat = dump file contents to terminal; ls -l to ensure small file
-
df
df -h
- df = show disks space per partition
- / = separate volume/disk for root os, logs
- /data = separate volume/disk for websites, apps
- -h = human readable size
- df = show disks space per partition
-
grep
grep [search] [files]
- grep = filter results, look for patterns in files
- Example: grep Error *.log
-
htop
htop
- htop = top list of processes, nicely colored; can sort, filter
-
kill
kill [pid]
- kill = force stop/kill a process; only use for 'hung' process
- [pid] = pid from
ps aux
list
-
ls
ls -lhtr [dir]
- ls = list contents of directory
- -l = details
- -h = human readable sizes
- -t = sort by time
- -r = reverse sort, so new shows at bottom
- -1 = just list names in a single column
- Example: ls -lhtr logs/*
-
ps
ps aux
- ps = process list
- a = all, including other users
- u = user format
- x = register format
- Example: ps aux | grep nginx
-
reboot
sudo reboot
- reboot = reboot server; should not be needed; restart individual services
-
systemctl
sudo systemctl [action] [process]
- systemctl = manage services such as nginx, php-fpm
- Example: sudo systemctl status nginx
- Example: sudo systemctl restart nginx
- Example: sudo systemctl status php-fpm
- Example: sudo systemctl restart php-fpm
-
tail
tail -f -n50 [file]
- tail = returns the last few lines of a file
- -n# = number of lines
- -f = follow, useful for tailing an active log file
- Example: tail -f logs/app.log
-
vim
vim [file]
- vim, vi = text editor; ls -l to ensure small file
- arrow keys = move cursor
- shift G = go to end of file
- ctrl u = page up
- ctrl d = page down
- /[patttern] = search for pattern
- esc = get out of most vi modes
- :q = quit
- :q! = quit without writing
- :wq = write, quite
- note, if quit a SSH session with a file vi-ed/open, be sure to SSH in again and cleanup the vi auto backup [file]~; vi-ing the original file again will prompt you about
- Example: sudo vim /var/log/messages
-End of Document-
Thanks for reading