Ahmed's Tips (aretips)
-
`for i in $(cat file); do whatever $i; done` let's you do an action on each line in a file in #bash
about 8 months ago from web -
on linux/osx, when `file` doesn't show image dimensions, you can run `identify foo.jpg` to get the dimensions using #imagemagick
about 8 months ago from web -
escape a var in #bash or #zsh with ${i} - ex `for i in 32; do convert foo.jpg -resize ${i}x${i} out.${i}px.jpg; done` - http://ur1.ca/418y7
about 10 months ago from web -
`curl -u login:pass -F key=value -F key2=value2 http://url` helps in testing POST to webservices from the command line using #curl
Saturday, 29-May-10 02:33:15 UTC from web -
`diff -qr dirA dirB` | grep -v -e .git -e .svn | sort` to diff two directories (via http://bit.ly/eerIO)
-
`curl -O -u login:pass "https://twitter.com/statuses/user_timeline.xml?count=100&page=[1-32]"` backs up #twitter #curl - http://is.gd/6CC3g
-
`csplit -k file 20 \{*\}` will split file into as many 20 line parts as possible #csplit
-
`cmd > >(tee out.log) 2> >(tee err.log >&2)` runs cmd and outputs std{out,err} to {out,err}.log, respectively - http://ur1.ca/k3h8 #tee
Monday, 18-Jan-10 11:15:00 UTC from web -
`select * from t into outfile 'a.csv' fields terminated by ',' enclosed by '"' lines terminated by '\n'` #mysql to csv - http://ur1.ca/jlka
Monday, 11-Jan-10 18:06:02 UTC from web -
`echo -e "GET / HTTP/1.0\r\nHost: subdomain.domain.com\r\n\r\n" | nc domain.com 80` really helps in testing #webserver config changes! #nc
Sunday, 03-Jan-10 17:45:45 UTC from web -
base conversion using bc - `echo "ibase=16;obase=A;CAFE" | bc` to convert 0xCAFE to base 10. #bc
Sunday, 03-Jan-10 17:45:02 UTC from web -
`i=foo.jpg echo ${i/.jpg}` would remove the .jpg extension from i, thus returning foo. useful for renaming file extensions in a loop. #bash
Sunday, 03-Jan-10 17:44:42 UTC from web -
coworker pointed out that with a recent coreutils, you can also do `date -d @1207784720` on linux when date -r doesn't exist. #date
Sunday, 03-Jan-10 17:44:10 UTC from web -
perl -e 'print scalar localtime 1207784720;' can be used when date -r doesn't exist (ie linux). courtesy of my coworker. #date #perl
Sunday, 03-Jan-10 17:42:44 UTC from web -
to empty a file while preserving the actual file and permissions, use `cat /dev/null > filename` #rm
-
`awk '{s+=$1} END {print s}'` sums a list of numbers - really useful. #awk
Friday, 18-Dec-09 16:39:56 UTC from web -
`sudo tcpdump -n dst port 80 -c 5 -A -s 0` dump entire packets heading to port 80 (stopping after 5 packets) #tcpdump
Friday, 18-Dec-09 16:39:39 UTC from web -
generate histogram data from a data set using `cat file | sort | uniq -c`. add a -g to sort if your data contains numbers. #data
Friday, 18-Dec-09 16:39:15 UTC from web -
use `awk '{temp = $1; $1 = $2; $2 = temp; print;}'` to swap two columns of data. #awk
Friday, 18-Dec-09 16:38:43 UTC from web -
`hdiutil makehybrid -udf -udf-volume-name "dvd name" -o out.iso dir/` (where dir contains a VIDEO_TS folder) to make a #dvd #iso in osx.
Friday, 18-Dec-09 16:37:56 UTC from web