Linux Bash Terminal CheatSheet
Extract specific file from tar archive
$ tar -xzvf {tarball.tar.gz} {path/to/file}
Find symbolic links recursively under a folder
ls -lR /path/to/folder | grep ^l
Copy specific file types keeping folder hierarchy*
find . -name '*.txt' -exec cp --parents \{** /target \;
Copy files with folder hierarchy
cp --parents src/prog.js images/icon.jpg /tmp/package
Bash get Nth field/column with awk
echo "a:b:c" | awk -F ":" '{print $2}'
if -F delemeter param is not given, input is seperated by spaces
Get Nth field from end
$ echo "aa:bb:cc:dd:ee:ff:String Test" | awk -F ":" '{print $(NF -0)}'
String Test
Remove chars from filename
for file in *; do mv "${file}" "${file/000/}"; done
This will remove 000 from all the filenames in folder. * can be substituted
with / or more for files in subfolders.
Convert host list into whitespace seperated list
for host in `cat a | grep -o '[a-z].*domain.com'`; do echo -n "$host "; done
Print specific json fields on a file
jq -r '.status' response.json
status is the name of the json field here without ".**
Write file with cat EOF
$ cat < print.sh
#!/bin/bash
echo \$PWD
echo $PWD
EOF
ref - https://stackoverflow.com/questions/2500436/how-does-cat-eof-work-in-
bash