Useful Linux Commands

A handy crib sheet of various commands I need to remember and don’t use all that often.

su - rootpreserve the path when changing to superuser (note the sp between – and root)
taskselthis will allow other display managers to be installed (ie. gnome)
find / -name aptfind all commands with the regex name “apt” (no quotes)
find / -name apt 2> /dev/nullas above, but redirect errors to the null device
grep -Ril "text-to-find-here" /find in files
whichlocate the command which would have been executed
dmesg -w | grep -i “mode”display kernel messages containing “mode” (must be su)
inxi -Gxsystem information, -Gx returns graphics related stuff
xrandr --verboseshow monitor configuration
grep '/usr/s\?bin' /etc/systemd/system/display-manager.serviceshow which display manager is installed
sudo apt-get install gdm3
sudo dpkg-reconfigure gdm3
install gdm3 display manager
apt update && apt full-upgradeInstall any upgrades
apt-get remove --autoremove remove package and any other dependent package which is no longer needed
apt-get purge --autoremove as above, but also delete configuration and/or data files of the package
apt-mark showmanualshow manually install packages
apt list --installed | grep -w "installed]" | grep htopshow all manually installed packages containing ‘htop’
apt-cache policy htop
ls /etc/apt/sources.list.d/show custom package sources
dpkg -L htopList files ‘owned’ by the htop package
dpkg -S uname
apt search uname
Find the package containing the file ‘uname’
<command> `uname -r`command substitution
df -hx tmpfsshow the file system sizes in human readable form, exluding tmpfs
tar -xvzf community_images.tar.gzextract a tar.gz

Other commands

How to exclude a package from apt-get autoremove?

apt-get autoremove -s \
  | sed -ne 's/Remv \(linux[^[]*\)\[.*/\1/gp' \
  | xargs apt-get remove -y

Frank Ray

Frank Ray & Associates is a software engineering consultancy that builds high quality software for businesses.

We develop new applications, automate manual processes, integrate vendor packages, replace Excel workarounds, fix unreliable applications, retire end of life software and remove dependence on poor value suppliers.

Get in touch if you need our help