Skip to content

Instantly share code, notes, and snippets.

@madeingnecca
Last active July 14, 2017 00:48
Show Gist options
  • Save madeingnecca/4160553 to your computer and use it in GitHub Desktop.
Save madeingnecca/4160553 to your computer and use it in GitHub Desktop.
BASH utils
#!/bin/bash
# Cleans directory from cvs dir/files.
# http://snippets.dzone.com/posts/show/934
find "$1" -name 'CVS' -exec rm -rf '{}' \; -print
# Generate fake file with a specific size (useful for uploads)
head -c 3000000 /dev/urandom > upload_test_3MB.zip
# Extracts count per page name in an access_log Apache file
awk -F'[ "]+' '{ pagecount[$7]++ } END { for (i in pagecount) { printf "%d - %15s\n", pagecount[i], i } }' access_log
# Get only response headers of a webpage.
curl -s -D- -onul "http://www.google.it"
# Fetch a webpage, returning only its body.
wget -qO- "http://www.google.it"
# Search files modified on the latest 2 days
find . -mtime -2
# Copy last command with its output.
# Usage:
# $ <COMMAND> | pbcopy
# $ pbcopylast
function pbcopylast {
last=$(history 2 | head -1)
(
echo -n $last | sed "s/^[ ]*[0-9]*[ ]*/\$ /g" | sed "s/[ ]*\|[ ]*pbcopy$//g"
echo ""
pbpaste
) | pbcopy
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment