Home > Linux, Work > Bash One-Liners

Bash One-Liners

February 4th, 2009 Leave a comment Go to comments

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[]
Categories: Linux, Work Tags: ,
  1. Weesa
    February 5th, 2009 at 13:17 | #1

    One-liners are awesome! :-)

  2. July 6th, 2009 at 18:15 | #2

    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 ;)

  1. No trackbacks yet.