Cheatsheet General
Gestion des fichiers
# Disk left on disk
df -h
# Where Executable is located
which
chmod u+x [filename] #Add Execute to User to a file
chmod 330 [filename] #Set Read Write to User & Group
# Number of files in a directory
ls | wc -l
# Create directory with a full path
mkdir -p [path]
# See Current directory
pwd
Gestion des devices
# List of connected USB devices
lsusb
# Device messages
dmesg
Gestion des utilisateurs
THEUSER=frodo
# Ajouter un utilisateur
adduser $THEUSER
# Ajouter l'utilisateur au group sudo
adduser $THEUSER sudo
# Voir la liste des users
cat /etc/passwd
Remove SUDO password, add at the end of /etc/sudoers: [username] ALL=(ALL) NOPASSWD: ALL
File Edit
File |
Linux Command |
Print content of a file |
cat [filename] |
See last 50 lines |
tail -n50 [filename] |
Replace Strings examples |
sed -i "s/127.0.0.1/$(cat ip.address)/g" overrides.json |
Process Command
|
Linux Command |
List of running process |
ps -aux | less |
Interactive list |
top |
Look up or signal processes based on name and other attributes. |
pgrep |
Display a tree of processes |
pstree |
Detach a process (nohup, no hangup) |
nohup ./process & |
Network Command
|
Linux Command |
Get a file from a http address |
wget |
Execure Http & https command |
curl [URL] |
List All Open Ports |
netstat -tulpn | grep LISTEN |
List DNS TXT entries |
host -t txt o7conseils.com |
List All Active Port 22 |
nmap -p22 192.168.25.0/24 |
Log in remote shel |
ssh user@192.168.99.101 |
nc example usage
System Information
|
Linux Command |
See what version of Debian you are running |
cat /etc/debian_version |
See OS release notes |
cat /etc/os-release |
What kernel version is running |
uname -a |
What hardware you are using |
cat /proc/cpuinfo |
Cron Job
|
Linux Command |
See list of Jobs |
crontab -l |
Set Jobs from a file |
crontab filename |
System Command
|
Linux Command |
Start a service |
systemctl start [name.service] |
Stop a service |
systemctl stop [name.service] |
Re-Start a service |
systemctl restart [name.service] |
View Service status |
systemctl status [name.service] |
View Service status + more logs |
systemctl status -n50 [name.service] |
See all available services |
systemctl list-unit-files --type=service |
View Boot time of each service |
systemd-analyze blame |
|
systemctl reload [name.service] |
Reload all unit files |
systemctl daemon-reload |
|
systemctl is-active [name.service] |
Location of user services |
/etc/systemd/system |
reference
service parameters
Keys & Encryption
|
Linux Command |
Creates a new SSH key |
ssh-keygen -t rsa -b 4096 -C "<label, ex your e-mail>" |
See Sha256 sum of a file (usually to validate a download) |
sha256sum [filename] |
Bash Script Util
|
Linux Command |
See Return code of last command |
echo $? ] |
Print yyyy-mm-dd |
echo $(date '+%Y-%m-%d') |
Condition (IF)
reference
Haut-Niveau : if [ $VERSION_ID == '2' ]; then [CMD] else [CMD2] fi
Example :
Directory
Location |
Usage |
/bin |
Essential User Binaries |
/etc |
Configuration Files |
/etc/opt |
Configuration files for add-on packages that are stored in |
/home |
Home Folders |
/lib |
Essential Shared Libraries |
/opt |
Optional Packages |
/root |
Root Home Directory |
/sbin |
System Administration Binaries |
/tmp |
Temporary Files |
/usr |
User Binaries & Read-Only Data |
/usr/bin |
Non-essential command binaries (not needed in single-user mode); for all users. |
/usr/lib |
|
/var |
Variable Data Files |
/var/log |
Log files. Various logs. |
/var/tmp |
Temporary files to be preserved between reboots. |
/boot |
Static Boot Files |
/dev |
Device Files |
/mnt |
Temporary Mount Points |
/proc |
Kernel & Process Files |
/lost+found |
Recovered Files |
Reference
Package Management
|
Linux Command |
Remove un-used package |
apt autoremove |
Useful Package