Linux Console Snippets
3. January 2014
Absolutely random compilation of things I need to remember. Might grow.
How to mount USB stick [source]
- Find the drive identifier after plugging the USB stick in (something like /dev/sdc1)
sudo fdisk -l
- Create folder to mount the drive and mount it there
sudo mkdir /media/usb-stick
sudo mount /dev/sdc1 /media/usb-stick
How to find files in packages
- .. How to find files in installed packages, e.g. if you are looking for a source file called xyz.h:
dpkg --search xyz.h
- .. How to find files in available packages that might be not installed:
sudo apt-get install apt-file
apt-file update
apt-file search xyz.h
Backup and restore GPG keys [source]
- List public GPG keys:
gpg --list-keys
The key_id is the part after something like “pub 1024D/”.
- Export public GPG key:
gpg -ao xyz-public.key --export key_id
- List secret GPG keys:
gpg --list-secret-keys
The key_id is the part after something like “sec 1024D/”.
- Export secret GPG key:
gpg -ao xyz-private.key --export-secret-keys key_id
- Restore GPG keys:
gpg --import xyz-public.key
gpg --import xyz-private.key
Backup and restore installed packages
- Save installed packages as list in file:
dpkg --get-selections > selections.txt
- Install package list from file:
dpkg --set-selections < selections.txt
sudo apt-get update
sudo apt-get dselect-upgrade
sudo apt-get dist-upgrade
sudo apt-get upgrade
Network usage
- Bandwidth usage by program How much bandwith is used by running programs:
sudo nethogs wlan0
- Traffic in local network
sudo iftop -i wlan0
- Port usage by program
sudo netstat -taupen