Getting System Information and Logs

free -<m|g|h>  # free memory, by Mebibyte, Gibibyte, or Human-readable
df -<m|g|h>    # disk free
whoami
id             # the user running the session along with the list of groups they belong to
uid
gid
uname -a       # -a = -snrvmpio, see uname --help
dmesg          # kernel logs
dmesg | grep [componemt]journalctl

#dumps all the available logs
journalctl -<r|f|u> [.service]  # -r: newer messages are shown first
																# -f: continuously print
																# -u: limit the messages to those emitted by a specific systemd unit

Discovering the Hardware

dmidecode
dmidecode -t
dmidecode -t [type No.]

lspci   # lists PCI devices
lspci | grep Ethernet
lspci -v -s `lspci | grep VGA | cut -f1 -d\ `

lsusb    # lists USB devices

lspcmcia # lists PCMCIA cards, need pcmciautils package

lsdev    # need procinfo package

lshw     # a combination of the above programs

Managing Files and Directories

# Moving around
pwd

cd [directory]
cd -    # get back
cd ..

pushd [directory]  # instead of cd, remembering more than just the last directory visited
popd
dirs

# List
ls -<l|a>     # long / all
tree -aCd -L 2 /home

# New
mkdir [directory]
touch [file]
touch -t 12091600 myfile  # set the date and timestamp to 4 p.m., December 9th

# Displaying
cat [file_name]
tac [file_name]
less [file_name]
more [file_name]
head [file_name]
tail [file_name]
<head|tail> -n 15 [file_name]

# Creating/Removing Directoris
mkdir [dir_name1] [dir_name2]
rm -rf [dir_name1]/ [dir_name2]/

mkdir ["dir name"]
rmdir ["dir name"]     # The directory must be empty
rm -rf ["dir name"]/   # To remove a directory recursively
rm -rf [dir\ name]/

mkdir -p [dir_name]/{sub_dir1,sub_dir2,sub_dir3}
ls -l [dir_name]/

# Remove, copy and move files
rm -f [target_file]   # force
rm -i [target_file]   # interactively
cp [source_file] [target_file]
mv [source_file] [target_file]

# Finding Files
locate [file]   # just search in `locate.db` updated by `cron`

which [file]    # return $PATH, where the program resides on the filesystem
whereis [file]  # looks for packages in a broader range of system directories
echo $PATH

find [directory] [criteria]     # most complex and flexible
find / -name sbd*

find /usr -type d -name gcc     # Searching only for directories named gcc
find /usr -type f -name gcc     # Searching only for regular files named gcc

find -name "*.swp" -exec rm {} ’;’  # Find and remove all files that end with .swp

find [directory] -<ctime|atime|mtime> <n|+n|-n>
find / -ctime 3                 # -ctime is when the inode metadata, created at excactly 3 days ago
find / -ctime +3                # within 3 days
find / -ctime -3                # before 3 days
# -atime: accessed/last read
# -mtime: modified/last written ()

find / -size 0
find / -size +10M -exec [command] {} ’;’  # find files greater than 10 MB in size and running a command on those files

grep -r [expression] [files]    # -r: enables a recursive search

type [command]
type rm
type cd

Timing and Sizing

time [command] # timing
time find [directory] [criteria]
time locate [file]

du -shc [file]

Install / Remove Packeges in Debian

apt

apt update
apt update --fix-missing

apt upgrade
apt upgrade [package]

apt-cache search [keyword]
apt search [keyword]
apt show [package]

apt install [package]
apt --fix-broken install <package>

apt remove [package]  # remove package but keep configuration
apt remove --purge [package] # same as following
apt purge [package]          # remove package and configuration

sudo apt autoremove
sudo apt clean
sudo apt autoclean

dpkg

# import pgp and check sha256sum
wget -q -O - <https://www>.[package_linke.deb] | gpg --import
gpg --fingerprint [fingerprint]
# download the SHA256SUMS and SHA256SUMS.gpg files
wget -O SHA256SUMS http://[SHA256SUMS]
wget -O SHA256SUMS.gpg http://[SHA256SUMS.gpg]
# then:
gpg --verify SHA256SUMS.gpg SHA256SUMS

sudo dpkg -i [package.deb]

sudo dpkg -r [package.deb]
sudo dpkg -l | grep [package] <| less>
sudo dpkg --listfiles [package] <| less>
sudo dpkg --purge [package]
sudo dpkg --configure -a      # repair the dpkg database

# List all kernel versions installed
sudo dpkg --list | egrep -i --color 'linux-image|linux-headers'

# currently running Linux kernel
v="$(uname -r | awk -F '-virtual' '{ print $1}')"
echo $v

# Remove all old kernels
sudo apt-get --purge autoremove

snap

sudo snap install <package>

Install / Remove Zipped Packeges

Readings: How To Extract Zip, Gz, Tar, Bz2, 7z, Xz and Rar File in Linux