diff --git a/README.md b/README.md index 175ca00..b39fe4c 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,2 @@ # oneliners -one-line-solutions, primarily bash +useful one-liners, primarily in bash diff --git a/bash/biggest_dir_on_same_fs.sh b/bash/biggest_dir_on_same_fs.sh new file mode 100755 index 0000000..96d8ddd --- /dev/null +++ b/bash/biggest_dir_on_same_fs.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +# find biggest directories in a given path without leaving the current filesystem +dir="/var/opt/gitlab"; for i in $(ls $dir); do mountpoint -q $dir/$i || du -shx $dir/$i ; done | sort -rh | head diff --git a/bash/biggest_file_in_installed_deb.sh b/bash/biggest_file_in_installed_deb.sh new file mode 100755 index 0000000..d742df3 --- /dev/null +++ b/bash/biggest_file_in_installed_deb.sh @@ -0,0 +1,3 @@ +#!/bin/bash +# find the biggest file in an installed deb package: +export PKG=vim; for i in $(dpkg -L $PKG) ; do if [[ -f "$i" ]] && [[ ! -L "$i" ]]; then ls -lh1 $i ;fi; done | sort -k 5 -hr | head -1 | cut -d " " -f 5,9- diff --git a/bash/extract_base64_from_xml.sh b/bash/extract_base64_from_xml.sh new file mode 100755 index 0000000..baf9f57 --- /dev/null +++ b/bash/extract_base64_from_xml.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +# extract base64-coded binary within a given tag in an xml (1st match) +cat file.xml | sed -n -e 's/.*\(.*\)<\/ns5:Daten>.*/\1/p' | base64 -d > output_file && file output_file diff --git a/bash/find_links_to_target.sh b/bash/find_links_to_target.sh new file mode 100755 index 0000000..c34f72c --- /dev/null +++ b/bash/find_links_to_target.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +# find all links in the fs, that link to a specific target: +find / -type l -exec readlink -nf {} ';' -exec echo " -> {}" ';' | grep "/bin/bash" diff --git a/bash/open_ports_with_telnet.sh b/bash/open_ports_with_telnet.sh new file mode 100755 index 0000000..a18dc56 --- /dev/null +++ b/bash/open_ports_with_telnet.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +# check state for specific ports on target +for i in 80 443; do echo -e '\x1dclose\x0d' | telnet google.com $i >/dev/null; echo "$i : $?"; done + diff --git a/bash/prettify_PATH.sh b/bash/prettify_PATH.sh new file mode 100755 index 0000000..15e2a03 --- /dev/null +++ b/bash/prettify_PATH.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +# prettify PATH-Output: +echo $PATH | sed s/\:/\\n/g + diff --git a/oneliners.sh b/oneliners.sh deleted file mode 100644 index 5988a3b..0000000 --- a/oneliners.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/bash - -# find single biggest file in an installed deb-pkg: -export PKG=vim; for i in $(dpkg -L $PKG) ; do if [[ -f "$i" ]] && [[ ! -L "$i" ]]; then ls -lh1 $i ;fi; done | sort -k 5 -hr | head -1 | cut -d " " -f 5,9- - -# find all links in the fs, that link to a specific target: -find / -type l -exec readlink -nf {} ';' -exec echo " -> {}" ';' | grep "/bin/bash" - -# extract base64-coded binary within a given tag in an xml (1st match) -cat file.xml | sed -n -e 's/.*\(.*\)<\/ns5:Daten>.*/\1/p' | base64 -d - -# prettify PATH-Output: -echo $PATH | sed s/\:/\\n/g - -# check for open ports on target -for i in 80 443; do echo -e '\x1dclose\x0d' | telnet google.com $i >/dev/null; echo "$i : $?"; done - -# find biggest directories in a given path without leaving the current filesystem -dir="/var/opt/gitlab"; for i in $(ls $dir); do mountpoint -q $dir/$i || du -shx $dir/$i ; done | sort -rh | head