Shell | Helpful Hacks
This document will cover everything about using Shell in the Linux/Mac/Win OS all there is to know for me.
Create dummy files
linux
fallocate -l 10G gentoo_root.img #LinxOs
MacOs
mkfile -n 1g temp_1GB_file #MacOS
WinOs
fsutil file createnew temp_10GB_file 10000000000 #windows
Fix corrupted compressed zip file
zip -FFv Corrupted.zip --out Fixed_Courrupred.zip
Linux Cheatsheet
Linux Command Line Cheat Sheet
Check Public IP Address
curl -s https://checkip.amazonaws.com/
dig +short myip.opendns.com @resolver1.opendns.com
curl -s checkip.dyndns.org|sed -e 's/.*Current IP Address: //' -e 's/<.*$//'
Install Anydesk on Linux
wget -qO - https://keys.anydesk.com/repos/DEB-GPG-KEY | apt-key add -
echo "deb http://deb.anydesk.com/ all main" > /etc/apt/sources.list.d/anydesk-stable.list
apt update
apt install -y anydesk
Get/Find Anydesk ID headless
#MacOS
cat ~/.anydesk/system.conf | grep ad.anynet.id | cut -c 14-
#LinuxOS
cat /etc/anydesk/system.conf | grep ad.anynet.id | cut -c 14-
Send Anydesk id through Telegram via shell
TOKEN="<token>"
ID="-<chatid>"
URL="https://api.telegram.org/bot$TOKEN/sendMessage"
p() {
cat /etc/anydesk/system.conf | grep ad.anynet.id | cut -c 14-
}
q=$(p)
curl -s -X POST $URL -d chat_id=$ID -d text="Your $HOSTNAME Anydesk ID : $q"
Check website is up/alive
dig domain.com
ping domain.com
Kill linux running jobs
kill $(jobs -p)
Linux Date Format Options
| Date Format Option | Meaning | Example Output |
|---|---|---|
| date +%c | locale’s date time | Sat May 9 11:49:47 2020 |
| date +%x | locale’s date | 05/09/2020 |
| date +%X | locale’s time | 11:49:47 |
| date +%A | locale’s full weekday name | Saturday |
| date +%B | locale’s full month name | May |
| date +%m-%d-%Y | MM-DD-YYYY date format | 05/09/2020 |
| date +%D | MM/DD/YY date format | 05/09/2020 |
| date +%F | YYYY-MM-DD date format | 09/05/2020 |
| date +%T | HH:MM:SS time format | 11:44:15 |
| date +%u | Day of Week | 6 |
| date +%U | Week of Year with Sunday as first day of week | 18 |
| date +%V | ISO Week of Year with Monday as first day of week | 19 |
| date +%j | Day of Year | 130 |
| date +%Z | Timezone | PDT |
| date +%m | Month of year (MM) | 5 |
| date +%d | Day of Month (DD) | 9 |
| date +%Y | Year (YY) | 2020 |
| date +%H | Hour (HH) | 11 |
| date +%H | Hour (HH) in 24-hour clock format | 11 |
| date +%I | Hour in 12-hour clock format | 11 |
| date +%p | locale’s equivalent of AM or PM | AM |
| date +%P | same as %p but in lower case | am |
Check command update in interval | Watch command
watch is used to run any arbitrary command at regular intervals and displays the output of the command on the terminal window.
# watch <custom>
watch ls -lhrt
Check file creation/modification time details
How to find recently modified files in Linux
stat [File_Name]
SCP file transfer Local to Remote / Remote to Local
scp with port number specified
-P port | -r Directory
# Remote to Local
scp -P 2200 root@server-url:/home/some_random_dir/somefile.zip /Users/youruser/yourdesktop/
ShutDown/Reboot Log check
How to Check Shutdown and Reboot Date in Linux - Make Tech Easier
who -b
last -x shutdown
last -x reboot
Kill any running process
ps -ef | grep XXXX | grep -v grep | awk '{print $2}' | xargs kill
sudo kill `ps aux | grep java | grep jboss | awk {'print $2'}` || echo "Nothing"
Print few columns with grep
ps -ef | grep ./directd | grep -v grep | awk '{print $1,$2,$9 }'
ps -ef | grep directd | grep -v grep | sed -e 's/^\(.\{120\}\).*/\1/'
ps -ef | grep .sh | grep -v grep | awk '{print $1," | ", $2}'
ps -fC java | grep oneliving | grep -v grep | awk '{print $1," | ", $2," | ", $12}'

Clear terminal, bash, shell logs
cat /dev/null > ~/.bash_history && history -c && exit
media file conversation m3u8 to mp4
ffmpeg -i "url.m3u8" -c copy file.mp4