Bash One-Liners

Date February 4, 2009

I love one-liners1 to make my life easier.  Today I decided to clean up a directory full of CSV files, and compress them down.  After all, a 2MB CSV file can be reduced quite substantially, and I had 300 of them.

Here it is, quite simply loops through the directory of CSVs, and zips the file up, keeping the name the same.


for i in `ls -1 *.csv`; do zip -m ${i%csv}zip ${i}; done

This all goes on a single line, but can easily be written out over multiple lines, like this:


for i in `ls -1 *.csv`;
do
  zip -m ${i%csv}zip ${i}
done

Doing this reduced the folder size down from 600MB, to about 70MB, about an eighth the size.

  1. a script that can be written onto a single line, and executed[]

Technorati Tags: ,

2 Responses to “Bash One-Liners”

  1. Weesa says:

    One-liners are awesome! :-)

  2. efaistos says:

    in zsh :

    for i in **/*csv; do zip csv.zip $i

    This will find all csv files even in subdirectories and add them to the zip file ;)

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>