Like gzip, each file is separately inside the folder, and then if the source file is successfully deleted

I use the following command to simply copy each file to a folder:

for file in *; do gzip "$file"; done

But it saves the source files. I want to know if there is a way to delete files automatically after they are successfully gzipped.

Thank.

+3
source share
3 answers

I do not understand the question you have. According to the gzip man page :

If possible, each file is replaced with one with the extension .gz, while maintaining the same ownership, access time and modification.

: . , , gzipping. gzip Operation not permitted, gzip , . - , , .

+5

+1 @Tim Pote .

for, , : , . , find :

find . -maxdepth 1 -type f ! -name '*.gz' -exec gzip "{}" \;

, , gzip . ({}) , .

+3

If you have several thousand files, to prevent an "argument list too long", use

find . -maxdepth 1 -type f ! -name '*.gz' | while read file; do
    gzip "$file"
done
0
source

All Articles