3.5 Some useful commands
This sections is a bit of a random collection of commonly used terminal commands. Many if not most are probably known to Linux users or already mentioned in other sections, so consider this a short summary of miscellaneous commands and things that would go missing when only mentioned in a specific topic someplace else.
- Instead of
sudo -s(su doesn't work with the root user disabled)
- Monitor system resources:
- See currently logged in users:
- Check system uptime:
- Memory usage:
- Disk space:
- See IP and MAC-address:
- See external IP:
- See gateway:
- Use netstat to see open ports:
- To display open ports and established TCP and UDP connections, enter:
- To see full dns hostname, remove the -n flag:
Update packages and OS:
sudo apt-get update sudo apt-get dist-upgrade
adduser username, edit password:
Custom commands (aliases)
Add a line to
~/.bash_aliases with a custom shortcut, e.g:
alias mycommand='~/path/runsomescript.sh arg1 arg2'
.bash_aliasses is uncommented in
Control disk space
Check disk space available on all drives with
df -h. Check the size occupied by a folder using
du -sh /some/folder/ or use a wildcard to list all the content in a folder at once:
du -sh /some/folder/*.
Clean disk space by removing apt-get caches and downloads, and by pruning obsolete packages:
sudo apt-get clean sudo apt-get autoremove
/var/log/ is a common evildoer in terms of eating precious SD card disk space. To limit the size of log files, edit
- change weekly to daily
Scripts that should run as a background daemon on each startup must go in
/etc/init.d/. Such a script should be able to process 'start' and 'stop' arguments, a simple example can be found here.
Make it executable (
chmod +x /etc/init.d/myscript) and make it automatically start and stop it when the system boots or shuts down, like so:
update-rc.d myscript defaults
To stop it from running automatically:
update-rc.d myscript remove
Cronjobs, tasks that are automatically repeated at set times, are explained in the section about periodic backups.