Let's face it, we are mere mortals that keep forgetting everytime we learn something new. So that's why I created this simple cheatsheet. Every time I forget something important, I want to refer back in one single place instead of scouring the Internet for the same answer that I did before. Hope this will help.
I plan to use this repo as sort of my knowledge base notes and it will continue to grow larger from now on. Need to restructure this repo since there's so many new tools I need to use such as Openstack and Openshift. Maybe a separate new repo for both of this tool since it is very powerful and capable to create entirely new infrastructure and deployment place for application from scratch.
- Introduction
paste <(cat /etc/passwd | cut -d: -f1) <(cat /etc/passwd | cut -d: -f3) <(cat /etc/passwd | cut -d: -f4) <(cat /etc/passwd | cut -d: -f5) | column -s $'\t' -t
- Show only the username, user id, group id and comment/description from
passwd
file.
df -h | awk '/^C:\\/ {print $3 "/" $2}'
- Show C: disk usage, use in WSL.
df -h -t ext4 -t xfs | awk '{print $1, $3 "/" $2}' | column -t
- Show disk usage for disk using ext4/xfs filesystems.
free -h | awk '/^Mem:/ {print $3 "/" $2}'
- Show memory used/total.
find . -printf '%s %p\n'| sort -nr | head -10
- Show top 10 largest files (descending order, starting from the current folder, recursively).
du -hsx * | sort -rh | head -10
- Show top 10 largest folders.
ps axch -o cmd:15,%mem --sort=-%mem
- Show most memory intensive process.
ps axch -o cmd:15,%cpu --sort=-%cpu
- Show most CPU intensive process.
apt-mark showmanual
- Show explicit installed packages.
echo $PATH | tr : \\n
- Show current PATH environment variable.
systemctl list-unit-files --state=enabled --no-pager
- Show all installed services.
sudo useradd -d /home/miku -s /bin/bash -m miku -c "Add comment"
- Add a new user, specifices home directory, default shell, creates home directory for new user if it does not exist and adds a comment/description.
- This is the long way, can be done much faster using
adduser
:P
sudo setfacl -R -m u:username:rX /var/logs
- Grant specific user read only access to the directory belongs to other user, for read and list out all the content in the directory without changing owner and ownership of the directory.
sudo setfacl -R -x u:username /var/logs
- Remove ACL access given previously.
getfacl /var/logs
- Check the directory whether it has user set by setfacl
usermod -aG admin miku
- Modify the user by adding it to group admin.
fdisk -l
- List partitions
fdisk /dev/sdX
- Start the partition process:
m
for helpn
create a new partitiont
change partition typew
write changes to the diskq
to quiti
print information about a partition
pvcreate /dev/sdX?
- Create physical volume. Check using
pvs
command.
vgcreate vg-anyname /dev/sdX?
- Create volume group. Check using
vgs
command.
lvcreate -L sizeG -n lv-anyname vg-anyname
- Create logical volume with the specified size. Check using
lvs
command.
lvcreate -l 100%FREE -n lv-anyname vg-anyname
- Create logical volume by using remaining free space from volume group, in this case all available space (100%).
- This can also fix error
volume group vg-anyname has insufficient free space (14799 extents): 14800 required when creating logical volume
.
mkfs.xfs /dev/vg-anyname/lv-anyname
- Create
xfs
file system on the LVM disk
cd / ; mkdir -p newdir ; mount /dev/vg-anyname/lv-anyname newdir/
- Change to root directory, create new directory named
newdir
and mount newly formatted disk onnewdir
directory.
/dev/mapper/vg-anyname/lv-anyname /newdir xfs defaults 0 0
- Edit
fstab
file and the parameter above to make sure the mounted disk is boot persistent. - Check the disk using
fdisk -l
. - Save and exit the file.
umount /dev/mapper/vg-anyname/lv-anyname
- Pretty much the opposite of
mount
. Don't forget to mount back
ip a show scope global dynamic | awk '$1 == "inet" {print $2, $4}'
- Show IP and broadcast address.
curl -4 https://icanhazip.com
- Show my external IP address.
sed 's/"//g'
- Remove all double quotes on each line.
sed 's/[^ ]* //'
- Remove everything before the first space.
sed 's/,$//'
- Remove last comma on each line.
sed -e 's/\[[^][]*\]//g'
- Remove bracket and everything between a pair of bracket.
sed 's/,/ /g'
- Replace all commas with spaces.
awk '{print $0}'
- Print all column.
awk '(NR>1)'
- Print all line except first.
awk 'NF'
- Remove empty lines from list result.
awk '{$1=$1};1
- Remove all leading, trailing whitespaces and tabs from each line.
awk 'NR==2{ print; }'
- Grep specific line numbers.
grep -oP '\[\K[^\]]+'
- Extract everything inside brackets.
grep -m1 'searchstring' file_name
- Find only first occurence in a file.
ffmpeg -i video_name.mp4 -i audio_name.m4a -c copy -map 0:v -map 1:a output_name.mp4
- Adding audio to a video without re-encoding.
yt-dlp --extract-audio --audio-format mp3 https://ytvideolink
- Extract audio track from Youtube video and store as mp3.
nmap -sC -sV -p- -oN output-name ip-address
- Scan all of target port using default script, version detection and output the result normally.
nmap --script=http-enum -p80 ip-address
- Enumerate specific port using http-enum script.
gobuster dir -u http://ip-address -w /usr/share/dirbuster/wordlists/directory-list-2.3-medium.txt
- Search name of the hidden directory on the web server with wordlist.
enum4linux -M -G -S ip-address
- Enumerate machine list, group and user list with share list.
smbclient //ip-address/Anonymous
- Mount and connect to the sharename (Anonymous).
hydra -l ssh-username -P /usr/share/wordlists/rockyou.txt ssh://ip-address
- Bruteforce SSH password with wordlist from known SSH username.
source <rc-file-download-from-osp-project>
openstack server list --fit
openstack server show <server-id> --fit
openstack volume list --fit
openstack volume create --size <num> <volume-disk-anyname>
openstack volume list --fit
openstack server add volume <server-id> <volume-id>
openstack server show <server-id> --fit
source overcloudrc
openstack hypervisor list --fit | grep <hypervisor-host>
openstack server list --all-project --host <hypervisor-host> --fit
source stackrc
openstack baremetal node list --fit | grep <hostname>
openstack baremetal node show <hostname> --fit
openstack server list --fit | grep <hostname>
ssh user@ip-from-previous-command
sudo su -
shutdown now
openstack server list --fit
openstack network list --fit
openstack subnet list --fit
openstack image list --fit
openstack volume list --fit
openstack flavour list --fit