Users & groups
cat /etc/passwd
– list system users
cat /etc/group
– list system user groups
useradd user
– create new user
passwd user
– edit user password (Skip username to edit your own password)
usermod -g group user
– changes user’s primary group
usermod -a -G group user
– add existing user to secondary group
Archives
tar -zcf archive.tar.gz dir1/ dir2/subdir file.txt
– create new archive with name archive.tar.gz, include dir1/, dir2/subdir, file.txt directories & files
tar -xf archive.tar.gz -C extract/to/dir
– extract files from archive.tar.gz to extract/to/dir (Omit destination path & -C
option to extract to same directory)
zip
zip -r archive.zip dir1/ dir/subdir file.txt
– create new archive with name archive.zip, include dir1/, dir2/subdir, file.txt directories & files
unzip archive.zip -d extract/to/dir
– extract files from archive.zip to extract/to/dir (Omit destination path & -d
option to extract to same directory)
Software
dpkg --list | grep php
– list installed packages, optionally filter by name with grep
apt-cache search kde
– search for packages available to install
apt-get install firefox
– install package
apt-get remove --purge skype
– uninstall package and all of its configuration files (To retain configuration files, skip --purge
option)
apt-get autoremove
– remove all orphaned, not used packages (Packages, which were used as components for other packages, now all removed)
Hardware
lsblk
– list all devices (Including CD-Roms, USB flashes etc.) and mount points (If mounted)
mount /dev/sdb /mnt
– mounts /dev/sdb/ device to /mnt path (Path must exist)
umount /dev/sdb
– unmounts device
Processes
ps aux | grep nginx
– list all running processes, optionally filter by name (Process name, command will be filtered) with grep
kill 123
– kill process with PID 123 (PID can be retrieved with ps aux
)
pkill nginx
– kill process by name
Mysql
mysqldump --host=localhost --user=db_user --password=db_password db_name | gzip > db.sql.gz
– creates dump of db_name database, logging in with provided credentials and gzips it to db.sql.gz file
zcat db.sql.gz | mysql --host=localhost --user=db_user --password=db_password db_name
– imports gzipped database dump to db_name database