Skip to content

Instantly share code, notes, and snippets.

@jaredlwong
Last active August 29, 2015 14:05
Show Gist options
  • Save jaredlwong/e8b0764ebb755f9e8f1f to your computer and use it in GitHub Desktop.
Save jaredlwong/e8b0764ebb755f9e8f1f to your computer and use it in GitHub Desktop.
Useful Oneliners
# delete each file from stdin delimited by space or newline
xargs -n1 rm
# delete each file found using find (ex w/ .ds_store)
find . -name .DS_STORE | xargs -n1 rm
# for each url in urls run curl, grep some other url and then download each
# of these urls
cat urls | xargs -n1 -I{} sh -c "curl -s {} | grep $OTHERURL" | xargs -n1 wget
# replace one or more numbers with an underscore, good for aggregating when
# only thing changing is numbers
sed -s 's/[0-9]\+/_/'
# same thing but with perl regexes which are far better
perl -pe ‘s/[0-9]+/_/g’
# set a watch every 2 seconds to tail last 20 lines of every file matching
# /mnt/log/logs* and aggregate and sort them to see top 10
watch tail "-f -n 20 /mnt/log/logs* | sed -s 's/[0-9]\+/_/' | sort | uniq -c | sort -n | tail -n 10"
# nice ps format
ps -o user,group,pid,pgid,comm,args -u jwong
# kill process group
kill -- -$PGID
# for stuborn groups
kill -9 -- -$PGID
# echo without newline
echo -n "something"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment