Linux

Folder structure

/bin - essential binaries for all users (like cd, bash)
/sbin - admin system binaries
/boot - files for booting (like the kernel)
/dev - device files (file-like access to (virtual) hardware)
	/dev/sda - first SATA drive
	/dev/random - random number generator
	/dev/null - no output, discard all input
	/dev/zero - infinite 0s
/etc - configuration files for programs
/home - home folders for each user (alias ~)
	/home/username - also contains userspace config files
/lib - system library files (needed for programs in /bin)
/lost+found - corrupted files after a crash will end here
/media - removable media (USB-Drives, CDs, etc.)
/mnt - manual mounting points (created by admins)
/opt - optional software
/proc - contains info about running processes
/root - home folder for root user
/tmp - temporary files (no guaranteed persistance)
/usr - user binaries and program data
	/usr/bin - userspace /bin (contains most programs)
	/usr/sbin - admin programs
	/usr/lib - library files
	/usr/share - documentation
	/usr/include - include files for compiling
/var - runtime information stored by programs (logs, cache)
	/var/log/wtmp - login history

chmod

Number Permission Sum
0 – – – 0+0+0
1 – – x 0+0+1
2 – w – 0+2+0
3 – w x 0+2+1
4 r – – 4+0+0
5 r – x 4+0+1
6 r w – 4+2+0
7 r w x 4+2+1

Three groups:

  1. One permission for the owner, the person who created the file or folder.
  2. One permission for all of the people in the same primary group of the owner.
  3. One permission for everyone else, which includes unauthenticated and anonymous users.

To change all directories under the current path to 755 (drwxr-xr-x), excluding dotfiles (recursive):

find . ! -path . ! -path '*/.*' -type d -exec chmod 755 '{}' \;

To change all files in the current path to 644 (-rw-r--r--), excluding dotfiles (recursive):

find . ! -path '*/.*' -type f -exec chmod 644 '{}' \;

chown

Chown Command in Linux (File Ownership) | Linuxize

chown -R USER:GROUP ./ 

which

Find out where binary lives

which curl

Find process

ps -aux | grep [keyword]

Find text in files

grep -HiRn [text] [files/folders]

Find previous command

history | grep [command]

Find text or files starting with minus -

Passing arguments which starts with a minus to a tool will be usually interpreted as an option. This creates a problem when you want to delete a filename or grep text starting with a minus.
Solution: Pass -- to signify the end of the options.

ps --help | grep -- -a
rm -- --somefile.txt

Source: https://unix.stackexchange.com/a/87357

Compress / extract zip files

tar -czf [filename/folder]
tar -xzf [filename]

"Compres Ze File" / "Xtract Ze File

Show active network connections

netstat -tulpen

Show filesystems

df -Thal

Show disk usage

du -hs *

Show files in current folder (detailed)

ls -lisah

Logrotate

Warning

Does not work properly on CentOS6, but seems to work as intended on Ubuntu 24.04

https://linux.die.net/man/8/logrotate
Put a file (usually named after the program/logfile you are rotating) in /etc/logrotate.d/. For example: /etc/logrotate.d/mosquitto

/var/log/mosquitto/mosquitto.log {
    rotate 12
    monthly
    compress
    delaycompress
    size 100k
    nocreate
    missingok
    postrotate
        if invoke-rc.d mosquitto status > /dev/null 2>&1; then \
            invoke-rc.d mosquitto reload > /dev/null 2>&1; \
        fi;
    endscript
}