Penguin
Diff: BashOneLiners
EditPageHistoryDiffInfoLikePages

Differences between version 19 and predecessor to the previous major change of BashOneLiners.

Other diffs: Previous Revision, Previous Author, or view the Annotated Edit History

Newer page: version 19 Last edited on Tuesday, June 21, 2005 4:51:19 am by AristotlePagaltzis Revert
Older page: version 10 Last edited on Saturday, May 1, 2004 8:57:48 pm by PerryLorier Revert
@@ -1,26 +1,62 @@
-!! Sort a directory of mp3s into directories like Artist/Album Name/ 
+! !! Sort a directory of [MP3]s into directories like <tt> Artist/Album Name/</tt>  
  
-<verbatim>  
-for file in *.mp3; do \  
- eval $( id3tool "$file" | sed 's/^[^:]* //; s/:[\t ]*/="/; s/[[:cntrl:]]//g; /./!d; s/ *$/"/' ) \  
- { [ "$Artist" -o "$Album" ] && dir="$Artist/$Album/" ; } || { [ "$Artist" ] && dir="$Artist/" ; } || continue ; \  
- mkdir -p "$dir" ; mv "$file" "$dir/" ; \  
-done  
-</verbatim> 
+ <verbatim>  
+ for file in *.mp3; do  
+ eval $( id3tool "$file" | sed 's/^[^:]* //; s/:[\t ]*/="/; s/[[:cntrl:]]//g; /./!d; s/ *$/"/' )  
+ { [ "$Artist" -o "$Album" ] && dir="$Artist/$Album/" ; } || { [ "$Artist" ] && dir="$Artist/" ; } || continue  
+ mkdir -p "$dir" ; mv "$file" "$dir/"  
+ done  
+ </verbatim> 
  
 It uses [id3tool | http://nekohako.xware.cx/id3tool/] to read the [ID3] tag, instructs [SED] to massage the information into something that looks like [Shell] script, executes that to put values into variables, checks which variables are set, and if at least an artist name (optionally also album name) is given, moves the file into that directory. (It's rather a mouthful for a oneliner, but hey.) 
  
-!! Refresh the all [GPG] keys from the [ KeyServer] without flooding it:  
-<verbatim>  
- for uid in ` gpg --with-colons --list-keys| grep " ^pub" | awk -F: '{print $5}'` ; do gpg --refresh $uid; sleep 5; done  
-</verbatim>  
-Alter the number after sleep(1) to change the speed of the refresh.  
-[Paid surveys | http ://www.paidsurveysforall.com]  
-[BPO services | http ://www.thuriam.com]  
-[BPO services | http ://www .isourceindia.com]  
-[Media Transcription | http ://media -transcription.thuriam.com]  
-[BPO India | http: //www .thuriam .com]  
-[Data Processing | http ://bpo.thuriam.com /data_processing.html]  
-[Technical Writing | http: //technical-writing .thuriam.com]  
-[Seo Services | http ://seo -services.thuriam.com]  
-[Callcenter India | http ://call -centre.thuriam.com]  
+----  
+  
+! !! Refresh the all [GPG] keys from the KeyServer without flooding it  
+  
+ <verbatim>  
+ for uid in $( gpg --with-colons --list-keys | grep ^pub | awk -F: '{print $5}' ) ; do gpg --refresh $uid ; sleep 5 ; done  
+ </verbatim>  
+  
+Alter the number after sleep(1) to change the speed of the refresh. This is equalivent to the slightly more understandable :  
+  
+ <verbatim>  
+ for uid in $( gpg --with-colons --list-keys | grep ^pub | awk -F : '{print $5}' ) ; do  
+ gpg --refresh $uid  
+ sleep 5  
+ done  
+ < /verbatim>  
+  
+__Notes by AristotlePagaltzis :__  
+  
+This is a useless use of grep(1) . Better written as follows:  
+  
+ <verbatim>  
+ for uid in $( gpg --with-colons --list-keys | awk -F : ' /^pub /{ print $5 }' ) ; do gpg --refresh $uid ; sleep 5 ; done  
+ < /verbatim>  
+  
+Correcting self: this is still a useless use of backticks . As with most <tt>for f in $( ... )</tt> loops it is better written with a <tt>while</tt> loop:  
+  
+ <verbatim>  
+ gpg --with-colons --list-keys | awk -F : ' /^pub /{ print $5 }' | while read uid ; do gpg --refresh $uid ; sleep 5 ; done  
+ < /verbatim>  
+  
+''This applies to seq(1)-based loops too -- <tt>seq 1 10 | while read i< /tt> is better than <tt>for i in $( seq 1 10 )< /tt> .''  
+  
+This could be abbreviated as  
+  
+ <verbatim>  
+ gpg --with-colons --list-keys | awk -F : ' /^pub /{ print $5 }' | xargs -ri sh -c 'gpg --refresh {} ; sleep 5'  
+ </verbatim>  
+  
+but since xargs(1) doesn't offer any speed controls itself, it requires an ugly roundabout via [Shell].  
+  
+----  
+  
+!!! Getting a random string  
+  
+From the ChoosingPasswords page (see that page for an explanation) :  
+  
+ <verbatim>  
+ tr -dc ' -~' < /dev /urandom | head -c 20  
+ </verbatim>