Linux CheatSheet

Create a user without a home directory

useradd <username>

Create a user with a home directory

useradd -m <username>

Add a user to a group

adduser <user> <group>

Delete a user and its home directory

deluser <user> --remove-home

Change primary group for a user

usermod -G <group> <user>

List all groups

cat /etc/group

Delete a group

groupdel <group>

Get system install date

sudo dumpe2fs /dev/sda1 | grep 'Filesystem created:'

Install deb package and its dependencies

dpkg -i <filename>.deb
apt -f install
dpkg -i <filename>.deb

Clear Swap and cached memory

su -c "echo 3 >'/proc/sys/vm/drop_caches' && swapoff -a && swapon -a && printf '\n%s\n' 'Ram-cache and Swap Cleared'" root

Add 'add-apt-repository' command

apt install software-properties-common

Upgrade all PIP packages

pip list --outdated --format=columns
pip install pipdate
pipdate
pip install setuptools --upgrade
pip install wheel --upgrade

Detect DisplayManger in use

Debian/Ubuntu
cat /etc/X11/default-display-manager

RedHat/Fedora
cat /etc/sysconfig/desktop

SuSe
cat /etc/sysconfig/displaymanager

List all versions of a package

apt-cache policy package
then install using apt install package=version

Exclude package from apt update/upgrade

sudo apt-mark hold package
use unhold to revert

Add DNS Suffix

Add search domain.tld to /etc/resolvconf/resolv.conf.d/tail and run sudo resolvconf -u

List of commands for Hardware Information

1. lscpu
2. lshw
3. hwinfo
4. lspci
5. lsscsi
6. lsusb
7. lsblk
8. inxi
    9. -Fx
10. df
11. pydf
12. fdisk
13. mount
14. free
    15. -m
16. dmidecode
    15. -t processor
    16. -t memory
    17. -t bios
18. /proc files
    19. cat /proc/cpuinfo
    20. cat /proc/meminfo
20. hdparm
    21. -i /dev/sdX