Skip to content

terminal cheatsheet

dir structure

Directory Description
bin Essential command binaries. No subdirectories in /bin.
boot Static files of the boot loader
dev Device files
etc Host-specific system configuration
lib Essential shared libraries and kernel modules
media Mount point for removeable media
mnt Mount point for mounting a filesystem temporarily
opt Add-on application software packages
sbin Essential system binaries
srv Data for services provided by this system
tmp Temporary files
usr Secondary hierarchy
var Variable data

Each directory listed above is specified in detail in separate subsections below.

/usr and /var each have a complete section in this document due to the complexity of those directories.

source

The following commands, or symbolic links to commands, are required in /bin.

Command Description cat Utility to concatenate files to standard output chgrp Utility to change file group ownership chmod Utility to change file access permissions chown Utility to change file owner and group cp Utility to copy files and directories date Utility to print or set the system data and time dd Utility to convert and copy a file df Utility to report filesystem disk space usage dmesg Utility to print or control the kernel message buffer echo Utility to display a line of text false Utility to do nothing, unsuccessfully hostname Utility to show or set the system's host name kill Utility to send signals to processes ln Utility to make links between files login Utility to begin a session on the system ls Utility to list directory contents mkdir Utility to make directories mknod Utility to make block or character special files more Utility to page through text mount Utility to mount a filesystem mv Utility to move/rename files ps Utility to report process status pwd Utility to print name of current working directory rm Utility to remove files or directories rmdir Utility to remove empty directories sed The `sed' stream editor sh The Bourne command shell stty Utility to change and print terminal line settings su Utility to change user ID sync Utility to flush filesystem buffers true Utility to do nothing, successfully umount Utility to unmount file systems uname Utility to print system information If /bin/sh is not a true Bourne shell, it must be a hard or symbolic link to the real shell command.

The [ and test commands must be placed together in either /bin or /usr/bin.

Tip Rationale

For example bash behaves differently when called as sh or bash. The use of a symbolic link also allows users to easily see that /bin/sh is not a true Bourne shell.

Specific Options The following programs, or symbolic links to programs, must be in /bin if the corresponding subsystem is installed:

Command Description csh The C shell (optional) ed The `ed' editor (optional) tar The tar archiving utility (optional) cpio The cpio archiving utility (optional) gzip The GNU compression utility (optional) gunzip The GNU uncompression utility (optional) zcat The GNU uncompression utility (optional) netstat The network statistics utility (optional) ping The ICMP network test utility (optional) If the gunzip and zcat programs exist, they must be symbolic or hard links to gzip. /bin/csh may be a symbolic link to /bin/tcsh or /usr/bin/tcsh.

Tip Rationale

The tar, gzip and cpio commands have been added to make restoration of a system possible (provided that / is intact).

Conversely, if no restoration from the root partition is ever expected, then these binaries might be omitted (e.g., a ROM chip root, mounting /usr through NFS). If restoration of a system is planned through the network, then ftp or tftp (along with everything necessary to get an ftp connection) must be available on the root partition.

Specific Options The following directories, or symbolic links to directories must be in /etc, if the corresponding subsystem is installed:

Directory Description opt Configuration for /opt The following files, or symbolic links to files, must be in /etc if the corresponding subsystem is installed: [6]

File Description csh.login Systemwide initialization file for C shell logins (optional) exports NFS filesystem access control list (optional) fstab Static information about filesystems (optional) ftpusers FTP daemon user access control list (optional) gateways File which lists gateways for routed (optional) gettydefs Speed and terminal settings used by getty (optional) group User group file (optional) host.conf Resolver configuration file (optional) hosts Static information about host names (optional) hosts.allow Host access file for TCP wrappers (optional) hosts.deny Host access file for TCP wrappers (optional) hosts.equiv List of trusted hosts for rlogin, rsh, rcp (optional) hosts.lpd List of trusted hosts for lpd (optional) inetd.conf Configuration file for inetd (optional) inittab Configuration file for init (optional) issue Pre-login message and identification file (optional) ld.so.conf List of extra directories to search for shared libraries (optional) motd Post-login message of the day file (optional) mtab Dynamic information about filesystems (optional) mtools.conf Configuration file for mtools (optional) networks Static information about network names (optional) passwd The password file (optional) printcap The lpd printer capability database (optional) profile Systemwide initialization file for sh shell logins (optional) protocols IP protocol listing (optional) resolv.conf Resolver configuration file (optional) rpc RPC protocol listing (optional) securetty TTY access control for root login (optional) services Port names for network services (optional) shells Pathnames of valid login shells (optional) syslog.conf Configuration file for syslogd (optional) mtab does not fit the static nature of /etc: it is excepted for historical reasons. [7]

go to homedir

cd

getting manual

man <package>

domain

whois <domain>
dig <domain>
dig <domain> @<nameserver>
dig txt <domain> @<nameserver>
dig any <domain>
dig any <domain> @<nameserver>
dig ns dig <domain>
ip address or ip addr
ipconfig

apps

sudo apt install <package>
sudo ## if sudo doesnt exist
ipcalc ## calculate ip net
tree ## print dir structure
btop ## monitor
whois ## who is ?
perf ## speedtest generator
deja-dup ## simple backup
parted ## disk util
gparted ## disk util
screenfetch ## show info
    screenfetch -n
tweaks ## system util gui
nautilus ## file manager gui
lastlog ## show last user
tldr ## show most useful commands for every package
curl 
    curl cheat.sh/<package> ## like tldr

insight

ipcalc 192.168.0.0/24
tree -a

the -a option should be passed to see all files. by default tree does not print hidden files (those beginning with a dot ‘.’). In no event does tree print the file system constructs ‘.’ (current directory) and ‘..’ (previous directory).

to list directories only

tree -d

freeze resource monitor
++ctrl+c++ and ++ctrl+q++
whois <domain.tld>

random stuff

to get su

sudo -i

show user

id
id -u
id -g

screen

run command in background while closing ssh session

start a new named screen session

screen -S session_name
start a new daemon and log the output to screenlog.x
screen -dmLS session_name command
show open screen sessions
screen -ls
reattach to an open screen
screen -r session_name
detach from inside a screen
Ctrl + A, D
kill the current screen session: Ctrl + A, K or exit

history

history
!<number>

Note

all inputs are logged in ~/.bash_history

delete history

rm ~/.bash_history && history -c

change default history size 500 in ~/.bashrc

HISTSIZE=<number of entries, -1 for unlimited>
or run HISTSIZE=

copy & paste in terminal

++ctrl+shift+c++

++ctrl+shift+v++

Note

sometimes just highlighting does copy the text or copy it with pressing scrollwheel

delete

delete folder and its files

rm -rf <folder>

umask

Mask Files Directories
000 666 (rw-rw-rw-) 777 (rwxrwxrwx)
002 664 (rw-rw-r--) 775 (rwxrwxr-x)
007 660 (rw-rw----) 770 (rwxrwx---)
022 644 (rw-r--r--) 755 (rwxr-xr-x)
027 640 (rw-r-----) 750 (rwxr-x---)
077 600 (rw-------) 700 (rwx------)
277 400 (r--------) 500 (r-x------)

source

permission

who own files

chown -R $USER:$USER /<path>

who has permission

chmod -R 777 /<path>
chmod -R a=,a+rX,u+w,g+w /<path>
source

user and groups

sudo passwd sudo su

user

getent passwd cat /etc/passwd

useradd -D useradd ## Manual guided adduser ## Automatic

useradd -u <UID> -g <GID> -M -s /usr/sbin/nologin <username>
-M NoHome
-s no Shell
adduser <user>
deluser —remove-home <user>

group

getent group less /etc/group groups

groupadd -g 1000 <name>

show open ports

lsof -i | grep smb

or

ss -tuln

dmesg

kernel

dmesg

dmesg | grep -i error
show logs when its not directly kernel relevated
sudo journalctl
show last boot messages
sudo journalctl -b

follow logs

sudo journalctl -f