-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Content-ID: <alpine.LNX.2.00.1304040442080.21805@Telcontar.valinor> On Thursday, 2013-04-04 at 00:33 +0200, Carlos E. R. wrote:
But it took too long:
real 134m50.851s user 56m45.657s sys 3m7.112s
If is only analyzing inside bash scripts, why did it took so long?
I'll time it. time find / -type f -print0 | xargs -0 file | awk '/Bourne-Again/{print $1}' | tr -d ':' | xargs -r grep -e "mkfs.ext4 -L test_" +++···························· Telcontar:~ # time find / -type f -print0 > listadeficheros find: `/home/cer/.gvfs': Permission denied real 8m0.449s user 0m2.167s sys 0m29.063s Telcontar:~ # ····························++- That was reasonable. The listing has 184M. Next phase: +++···························· Telcontar:~ # time cat listadeficheros | xargs -0 file > lista.file_output real 129m13.901s user 56m40.918s sys 3m5.739s Telcontar:~ # ····························++- Wow, so it is the 'file' command that is slow! Seeing if a file is a script is easy, you only need to see the start of the first "line" (the shebang). But of course, we ask file to find what type it is, not to find only one particular type. Some files probably are harder to identify. +++···························· Telcontar:~ # time cat lista.file_output | awk '/Bourne-Again/{print $1}' > lista.awk_output real 0m2.866s user 0m1.457s sys 0m0.508s Telcontar:~ # ····························++- +++···························· Telcontar:~ # time cat lista.awk_output | tr -d ':' > lista.tr_output real 0m0.027s user 0m0.000s sys 0m0.002s Telcontar:~ # ····························++- +++···························· Telcontar:~ # time cat lista.tr_output | xargs -r grep -e "mkfs.ext4 -L test_" grep: /other/test_a2/home/cer/Documents/Recuerdos/Caricaturas: No such file or directory grep: /other/test_a2/home/cer/Documents/Recuerdos/Caricaturas: No such file or directory ... /data/storage_b/Backups_parciales_particiones_test/Bombadil_sda1/root/bin/test_hd_make: #mkfs.ext4 -L test_$X /dev/sdb$X /data/storage_b/Backups_parciales_particiones_test/Bombadil_sda1/root/bin/test_hd_make~: #mkfs.ext4 -L test_$X /dev/sdb$X real 0m18.306s user 0m0.014s sys 0m0.348s Telcontar:~ # ····························++- The final grep has errors because I have files and directories with spaces in the names, and the strings were truncted at the spaces. Well, in the sample above, a directory, which has one script inside. In the end, it did not matter because I found what I wanted. Sizes: +++···························· Telcontar:~ # ls -lh listadeficheros lista.file_output lista.awk_output lista.tr_output - -rw-r--r-- 1 root root 249K Apr 4 04:44 lista.awk_output - -rw-r--r-- 1 root root 346M Apr 4 04:41 lista.file_output - -rw-r--r-- 1 root root 245K Apr 4 04:46 lista.tr_output - -rw-r--r-- 1 root root 184M Apr 4 02:06 listadeficheros Telcontar:~ # ····························++- I still think it is faster than a brute force grep on the entire filesystem... I guess... - -- Cheers, Carlos E. R. (from 12.1 x86_64 "Asparagus" at Telcontar) -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.18 (GNU/Linux) iEYEARECAAYFAlFc7eQACgkQtTMYHG2NR9V89gCeIoxY9JNxuv2uexxzuVJW45wZ ayUAoJiSk0+8xoPuKHGwmz7O9ZLymZrw =dMWl -----END PGP SIGNATURE-----