Here you can find useful bash commands and my scripts for GNU/Linux.
I mostly use Debian distribution, so if you get an error there is a high chance you need to install extra software using apt install [name of missing package] (do not forget to apt update first). Some commands may need to be run as su.
Watch out what are you doing, you can damage your operating system if you are not careful!
dpkg-query -Wf '${Installed-Size}\t${Package}\n' | sort -n | tail -n 10
lists 10 largest packages on a system
dpkg --list |grep "^rc" | cut -d " " -f 3 | xargs sudo dpkg --purge
purges leftover configuration files from already uninstalled programs
echo "scale=10000;4*a(1)" | bc -l
computes pi to 10000th decimal place using bc commandline calculator
(free -m | grep Mem | awk '{print "RAM Used: "$3" | Total: "$2}';free -m | grep Swap | awk '{print "SWAP Used: "$3" | Total: "$2}') |tr '\n' ' | '
free memory monitor
echo $RANDOM
od -A n -t d -N 2 /dev/urandom | tr -d ' '
openssl rand 16 | od -DAn
various commands to get a random integer number
save below as temps.sh and give it executable rights (chmod +x ./temps.sh):
#!/bin/bash
show_temp1(){(echo "ACPI:";sensors | grep -A 0 "temp1:" | cut -c16-19)}
show_cpu_temp(){(echo "CPU";sensors | grep -A 0 "Core" | cut -c16-19)}
show_thermal_zone0(){
x=$(</sys/class/thermal/thermal_zone0/temp)
temp=$((x / 1000))
echo "thermal_zone0 "$temp
}
(show_temp1;echo "C |";show_cpu_temp;echo "C |";show_thermal_zone0;echo "C") |tr '\n' ' | '
simple script for monitoring system temperatures
vnstati --vsummary --hsummary -i eno1 -o ./summary.png;firefox ./summary.png
generates .png image with various network adapter statistics using firefox and vnstati
How to compile stuff from source (in general, basic flow):
1) unpack a tarball: tar zxvf prog.tar.gz or tar jxvf prog.tar.bz2
2) ./configure && make && sudo make install
or ./autogen.sh && make && sudo make install
dpkg architecture commands:
dpkg --print-architecture - current architecture, main architecture
dpkg --print-foreign-architectures - other architectures installed on a system
dpkg --remove-architecture
note before removing architecture with dpkg you have to remove all of that
architecture's packages.
sudo apt-get purge ".*:i386" for example for i386
then
dpkg --remove-architecture i386
listing i386 packages
dpkg -l | grep i386
this works similar for other architectures installed on the system, just replace i386 with different architecture's name
system install date:
usually you would want to install package like tuptime right after having installed your fresh OS. But if you could not or are working on a system where you can not install such package, see below commands how to deduce when the system was installed:
first run ls -lact --full-time /etc | tail
then compare the oldest file with ls -lact --full-time / | tail
and finally ls -lact --full-time /var | tail
then if the oldest file is a file you can further check it with
stat FILE | grep Change
on a system that lack GNU Coreutils don't use --full-time.
disk erase (double-check if the drive you are erasing is the right one or you risk of loss of your valuable data!):
fdisk -l # check for disk name
hdparm -I /dev/sdb # disk info
if the drive is not frozen:
hdparm --user-master u --security-set-pass p /dev/sdb # set temporary password
if the drive is frozen:
put the computer to sleep and wake it up
echo -n mem > /sys/power/state
if the disk supports the secure erase enhanced:
hdparm --user-master u --security-erase-enhanced p /dev/sdb
if not
hdparm --user-master u --security-erase p /dev/sdb
after waiting for the process to finish check again with
hdparm -I /dev/sdb if the password is reset and drive state back to normal
to zero-fill a drive
sudo dd if=/dev/zero of=/dev/sdb bs=1M status=progress
to random fill a drive
sudo dd if=/dev/urandom of=/dev/sdb bs=1M status=progress
then verify with
dd if=/dev/sdb bs=1M count=128 for nothing or random output
sudo shred -v -n1 /dev/sdb # overwrite with random data using shred
watch -n1 "df -BM && sensors"
simple monitoring of free disk space and system temperatures