Linux Commands – top ten or thereabouts
Commands I’m forever Googling…
Command | Does what? | Example |
history | Prints previously executed commands | history |
!! !n !-n | Re-executes a previous command: !! – last command (inc sudo !!) !n – command at history line n !-n – n commands ago | !! sudo !! !702 !-1 |
pwd | Print Working Directory | pwd |
rmdir | Remove empty Directory | rmdir |
rm | Remove any Director | rm |
locate | find file | locate -l hello* |
df | disk space | df -m |
du | disk usage | du Documents |
ls -lah ls -alSr | LiSt directory with file sizes in size order (S), in reverse (r) | ls -lah ls -alSr |
ps | Process Status | ps aux (note “aux” are a, u & x options) |
service | list enabled services detail specific service | service –status-all service <service-name> status |
cal | show this month show any month | cal cal 10 1971 |
diff | ||
find | returns the full path of matching files, either in full file system (with quotes) or limited to home folder (without quotes) | find -name “*my_file.*” find -name *my_file.* |
grep | ||
& | run in background | |
md5sum | ||
netstat | ||
free | free -h -s 3 free -m | |
mysqldump | ||
tail /path/to/file | prints the last 10 lines of the file | tail ./Documents/my_file.txt sudo tail -f /var/log/syslog |
tail -f /path/to/file | prints the last 10 lines and keeps live updating the output as its added to – useful for live viewing an updating/live log | |
sudo systemd-resolve –flush-caches | flush client dns cache (not on Raspbian) | |
scp | Secure CoPy In this –> example scp copies a file named “file.name” from “host” to the same filename (“.”) on the local machine | scp user@host:file.name . |
top | prints various system capacity usage statistics for each running process, and updates every 3s interpret output | top |
And package management…
apt | apt-get / -cache | Does what? |
apt install | apt-get install | Installs package |
apt remove | apt-get remove | Removes package |
apt purge | apt-get purge | Removes with config |
apt update | apt-get update | Refreshes repository |
apt upgrade | apt-get upgrade | Upgrades all upgradeables |
apt autoremove | apt-get autoremove | Removes unwanteds |
apt full-upgrade | apt-get dist-upgrade | Upgrades, handles dependencies |
apt search | apt-cache search | Searches for packages |
apt show | apt-cache show | Package details |
Nano…
Esc + $ | Enables soft line wrapping | Esc + $ is achieved by pressing and releasing <Esc> then holding <Shift> and typing <4> (Shift+4 = $) |
A few Node-RED goodies…
sudo systemctl start node-red | Restart Node-RED |
cd .node-red sudo nano settings.js | Edit settings |
sudo crontab -e | Edit crontab |
A few MacOS ones too…
open . | Open current folder in Finder from Terminal |
MySQL…
To list the size of each database:
select table_schema, sum((data_length+index_length)/1024/1024) AS MB from information_schema.tables group by 1;