bonrad
1
I am using find and ls to search for "warez" files on my server.
find /home/ -regex ".*\.\(avi\|mp3\|mpeg\|mpg\|iso\)" -print0 | xargs -0 ls -oh
This command produces this:
-rw-r--r-- 1 1000 3.2M Feb 18 2009 /home/user/public_html/lupus.mp3
I want to only get this
3.2M /home/user/public_html/lupus.mp3
Or even better, this output:
/home/user/public_html/lupus.mp3 | 3.2M
Would like to have some input on how to solve this problem, thanks
Try:
find /home -regex ".*\.\(avi\|mp3\|mpeg\|mpg\|iso\)" -exec ls -sh {} \;
find /home -regex ".*\.\(avi\|mp3\|mpeg\|mpg\|iso\)" -exec ls -sh {} \; |awk '{print $2" | "$1}'
Pipe it to awk and print whatever fields you want in whatver order.
| awk ' | awk '{print $8 $4}'
bonrad
4
it works, but it cannot handle filenames with whitespaces.
/usr/bin/time -o /tmp/time.txt -f %E find /home/ -regex ".*\.\(avi\|mp3\|mpeg\|mpg\|iso\|rar\)" -exec ls -sh {} \; |awk '{print $2" | "$1}' > /tmp/result.txt
It works until awk gets involved, when printing $2 the whitespaces gets lost.
rdcwayx
5
/usr/bin/time -o /tmp/time.txt -f %E find /home/ -regex ".*\.\(avi\|mp3\|mpeg\|mpg\|iso\|rar\)" -exec ls -sh {} \; |sed 's/ /|/' |awk 'BEGIN{FS=OFS="|"} {print $2,$1}'