gzip files with extension

Hi,

I have 1000 of files in a folder with the file extension as .csv
In this some of the files are already zipped and its looks like filename.csv.gz

Now i need to zip all the files in the folder to free some disk space. When i give gzip *.csv

It prompts me to overwrite filename.csv.gz files which are already zipped.

Is there any way to exclude the already zipped files and zip only the files with .csv extension which are not zipped.

Thanks in Advance.

ls *.csv | egrep -v $(ls *.gz | sed "s/.gz/.csv/" | tr '\n' '|' |sed "s/|$//")

Verify the output of above command and then use that in gzip command

Hi.

Another option:

false | gzip *.csv

try this it will not prompt for anything---

ls -1 *.csv | gzip * 2>/dev/null

Are you sure?

What would gzip * expand to?

$ echo blah | tee xxxxx.csv > yyyyy
$ ll
total 16
drwxr-xr-x   4 scott  staff   136 22 Jul 19:43 .
drwxr-xr-x  43 scott  staff  1462 22 Jul 19:41 ..
-rw-r--r--   1 scott  staff     5 22 Jul 19:43 xxxxx.csv
-rw-r--r--   1 scott  staff     5 22 Jul 19:43 yyyyy
$ ls *.csv | gzip *
$ ll
total 16
drwxr-xr-x   4 scott  staff   136 22 Jul 19:43 .
drwxr-xr-x  43 scott  staff  1462 22 Jul 19:41 ..
-rw-r--r--   1 scott  staff    35 22 Jul 19:43 xxxxx.csv.gz
-rw-r--r--   1 scott  staff    31 22 Jul 19:43 yyyyy.gz

---------- Post updated at 07:54 PM ---------- Previous update was at 07:39 PM ----------

(the "Are you sure" question was related to whether it worked, not whether it would prompt you for anything. But it neither works nor prompts you, so you were half right :))

  1. below command can help you directly. It will only compress the .csv file.
gzip *.csv 
  1. Even there are gzip files already, gzip command will not touch them:
$ ls |grep csv
file1.csv.gz
file2.csv.gz
xxx.csv

$ gzip *.csv

$ ls *.csv
file1.csv.gz
file2.csv.gz
xxx.csv.gz