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 su: sudo -s (su doesn't work with the root user disabled)
  • Monitor system resources: top
  • See currently logged in users: w or w username
  • Check system uptime: uptime
  • Memory usage: free
  • Disk space: df -h


  • See IP and MAC-address: ifconfig
  • See external IP: curl icanhazip.com
  • See gateway: route -n
  • Use netstat to see open ports: netstat --listen
  • To display open ports and established TCP and UDP connections, enter: netstat -vautn
  • To see full dns hostname, remove the -n flag: netstat -vat


Update packages and OS:

sudo apt-get update
sudo apt-get dist-upgrade

Update firmware:

sudo rpi-update

User management

Add user: adduser username, edit password: passwd username

Custom commands (aliases)

Add a line to ~/.bash_aliases with a custom shortcut, e.g:

alias mycommand='~/path/runsomescript.sh arg1 arg2'

Make sure .bash_aliasses is uncommented in ~/.bashrc.

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 /etc/logrotate.conf:

  • change weekly to daily
  • uncomment #compress

Startup scripts

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.

results matching ""

    No results matching ""