Command line
Download all specified extension files from an html page:
1 | wget -r -t1 -N -np -A.mp3 http: //google .com /music/audio/ |
-np dont ascend to parent
-r recursive
-l1 level DONT NEED
-N timestamping
-nd no directories DONT NEED
-t 1 = tries
-H span across hosts
To remove quotas, edit /etc/fstab and remove grpquota,usrquota,
then execute the remount, replacing /home with the name:
1 | mount -o remount /home |
Convert unix timestamp to readable format in Bash
1 | date -d @1280565192 |
Kill multiple processes using grep:
1 | kill -9 ` ps aux | grep perl | grep nobody | awk '{print $2}' ` |
Xargs: handle spaces and punctuation properly:
1 | xargs -0 |
Using ack and sed, edit files in place
1 | sed -i 's/replacestring/replacedwiththis/g' `~ /bin/ack --php "searchstring" -l` |
Rename doesn’t support renaming with a dash/hyphen, so we must use this forloop/mv hack:
1 | for i in ./*foo*; do mv -- "$i" "${i//test test2/test - test2}" ; done |
Find Command
COPY files less than 24 hours old to /some/other/directory
1 | find . - type f -ctime -1 | xargs -I {} cp {} /some/other/directory |
MOVE files less than 24 hours old to /some/other/directory
1 | find . - type f -ctime -1 | xargs -I {} mv {} /some/other/directory |
Scan files for certain text
1 | find dir / -name "*.txt" - exec grep -Hn "md5_func" {} \; |
Find all directories and sub-directories that are empty.
1 | find ./ - type d -empty |
MySQL
Using mysql from command line, here’s how to save results to an outfile (in interactive mode):
1 | SELECT * INTO outfile '/tmp/sql.out' FROM tablename WHERE condition = '1' ; |
Using mysql from command line, here’s how to save resultset to an outfile (using a sql file):
1 | mysql database -u username -p < batch.sql > sql.out |