Linux

Created
Language
Last Edit

Cheat Sheet

Common Commands

Find

1. find . -name thisfile.txt

If you need to know how to find a file in Linux called thisfile.txt, it will look for it in current and sub-directories.

2. find /home -name *.jpg

Look for all .jpg files in the /home and directories below it.

3. find . -type f -empty

Look for an empty file inside the current directory.

4. find /home -user randomperson-mtime 6 -iname ".db"

Look for all .db files (ignoring text case) that have been changed in the preceding 6 days by a user called randomperson.

Hide User & Directory Prompt Details

export PS1="\$ "

Port Owner

lsof -i :8000

Tail

Command displays the last 100 lines of the log.

tail -n 100 some_log.log

Basics

OS Details

Get Release Version

lsb_release -a

System Hostname

hostnamectl

Release File Content

cat /etc/*release

Disk Info

Filesystem disk space usage

df -h

Information about block devices, including disks and partitions

lsblk

Services

List all services

systemctl list-units --type=service

List running services

systemctl list-units --type=service --state=running

List enabled (set to start on boot) services

systemctl list-unit-files --type=service --state=enabled

Status of specific services

systemctl status <service-name>

User Management

Add User

sudo adduser <username>

Add User To sudo Group

To give the new user administrative privileges (allowing them to use sudo)

sudo usermod -aG sudo <username>

Switch User

su - <username>