Skip to content

Instantly share code, notes, and snippets.

@apolloclark
Last active January 7, 2019 21:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save apolloclark/75487cbf4ff4a6136a14 to your computer and use it in GitHub Desktop.
Save apolloclark/75487cbf4ff4a6136a14 to your computer and use it in GitHub Desktop.

Bash One-Liners

A collection of various moderate to very complex one-liners I use occasionally. I have a collection of various Bash commands here:

count number of lines, all files in a folder, sort

find . -type f -print0 | wc -l --files0-from=- | sort -n
replace line 5 in a text file
sed -i '5s/.*/ replacement_string /' file{1..4}.txt
replace string "foo" with string "bar", in a file
sed -i -- 's/foo/bar/g' *
whois lookup, of all entries in access.log

Tweet

for i in `cat access.log | cut -d" " -f1 | sort -u`; do
  whois -h http://whois.cymru.com  $i | egrep -v "AS|whois" >> results.txt;
done
bash alias, do a git commit, force to master

Tweet

alias yolo='git commit -am "DEAL WITH IT" && git push -f origin master'
find a string, in files, in a folder
grep -nr yourString* .
print a sequence of numbers, into a file
seq -s $'\n' 1 100 > numbers.txt
print virtualbox version

Post

 lsmod | grep -io vboxguest | xargs modinfo | grep -iw version
curl, print GET response headers
curl -s -D - <url> -o /dev/null/
nmap, scan all open TCP, UDP ports
nmap -vv -O -Pn -sTUV -p - --host-timeout 5m -oA "filname_prefix" <ip_add>

# https://svn.nmap.org/nmap/docs/nmap.usage.txt
-v: Increase verbosity level (use -vv or more for greater effect)
-O: Enable OS detection
-Pn: Treat all hosts as online -- skip host discovery
-sT: TCP Connect()
-sU: UDP Scan
-sV: Probe open ports to determine service/version info
-p <port ranges>: Only scan specified ports
  Ex: -p22; -p1-65535; -p U:53,111,137,T:21-25,80,139,8080,S:9
--host-timeout <time>: Give up on target after this long
-oA <basename>: Output in the three major formats at once
list size of sub-directores

http://stackoverflow.com/a/14749369

du -a -h --max-depth=1 | sort -hr
copy files from remote server
scp <username>@<remote_ip>:/file/to/send /where/to/put
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment