se162xg / notes

1 stars 1 forks source link

Practical Shell Script #3

Open se162xg opened 4 years ago

se162xg commented 4 years ago

Scan Directory

$ find /home -type f -printf "%f\t%u\t%g\t%p\t%m\n" 2>/dev/null |column -t
// %f filename, %u user, %g group, %p path, %m permission

Base64 Decode

$ echo ZmRhZmRhc2ZkYWZkYXNmZGE= |base64 -d > file

$ echo fTEzAfYDoz1YzkqhQkH6GQFYKp1XY5hm7bjOP86yYxE= |base64 -d |xxd -p
//convert binary into hexdump

Download All Files from an Online HTTP Directory

$ wget -r -np http://hostname/aaaa/
// -r: recursively
// -np: not going to upper directories

Output HTTP Status Code

$ curl -w %{http_code} <url> 

Upload a File

$ curl -F "file=@/tmp/test.html" <url>
se162xg commented 4 years ago

Determine Whether a Command is Installed

if [ -x "$(command -v zip)" ]; then
echo "1"
else
echo "0"
fi
se162xg commented 4 years ago

Hexdecimal ~ Binary

! a useful method to download a file when there's no file transfer tools

// binary -> hex
$ hexdump -ve '1/1 "%.2x"' binary.data > hex.data
// hex -> binary
$ xxd -r -p hex.data binary.data 
se162xg commented 4 years ago

List Alive URL

cat list.txt | parallel -j50 -q curl -w 'Status:%{http_code}\t Size:%{size_download}\t %{url_effective}\n' -o /dev/null -sk

se162xg commented 4 years ago

Config Startup Application on Ubuntu

$ sudo gnome-session-properties