aretips's profile picture. Ahmed's Tips

ahmed's tips

@aretips

Ahmed's Tips

`for i in $(cat file); do whatever $i; done` let's you do an action on each line in a file in #bash


on linux/osx, when `file` doesn't show image dimensions, you can run `identify foo.jpg` to get the dimensions using #imagemagick


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


`curl -u login:pass -F key=value -F key2=value2 http://url` helps in testing POST to webservices from the command line using #curl


`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


`select * from t into outfile 'a.csv' fields terminated by ',' enclosed by '"' lines terminated by '\n'` #mysql to csv - http://ur1.ca/jlka


`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


base conversion using bc - `echo "ibase=16;obase=A;CAFE" | bc` to convert 0xCAFE to base 10. #bc


`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


coworker pointed out that with a recent coreutils, you can also do `date -d @1207784720` on linux when date -r doesn't exist. #date


perl -e 'print scalar localtime 1207784720;' can be used when date -r doesn't exist (ie linux). courtesy of my coworker. #date #perl


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


`sudo tcpdump -n dst port 80 -c 5 -A -s 0` dump entire packets heading to port 80 (stopping after 5 packets) #tcpdump


generate histogram data from a data set using `cat file | sort | uniq -c`. add a -g to sort if your data contains numbers. #data


use `awk '{temp = $1; $1 = $2; $2 = temp; print;}'` to swap two columns of data. #awk


`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.


Loading...

Something went wrong.


Something went wrong.