Useful Perl One-Liners

Organizer Files by Filetype

This script will create directories based on the extensions of files and will move files into the corresponding directories (file.doc moves into the doc directory, file.jpg moves into the jpg directory)

perl -MFile::Copy -e 'foreach(glob("*.*")){/^.+\.(.*)$/;$e=lc($1);mkdir($e)if(!-d $e);rename($_,"$e/$_");}'

by Z. Bornheimer

Determine/Sort Current Directory by File Size (Descending)


perl -e'%h=map{/.\s/;99**(ord$&&7)-$`,$_}`du -h`;die@h{sort%h}'

by bellaire

Modification to get the largest offenders toward the bottom:

perl -e'%h=map{/.\s/;99**(ord$&&7)-$`,$_}`du -h`;die@h{reverse(sort%h)}'


Edit | Attach | Watch | Print version | History: r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r3 - 2016-06-18 - ZachBornheimer
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2021 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback