解压缩和删除目录中的所有.gz-Linux

我有一个目录。它有大约500K。 gz 的文件。

如何解压缩该目录中的所有.gz 并删除.gz 文件?

155186 次浏览
for foo in *.gz
do
tar xf "$foo"
rm "$foo"
done

There's more than one way to do this obviously.

    # This will find files recursively (you can limit it by using some 'find' parameters.
# see the man pages
# Final backslash required for exec example to work
find . -name '*.gz' -exec gunzip '{}' \;


# This will do it only in the current directory
for a in *.gz; do gunzip $a; done

I'm sure there's other ways as well, but this is probably the simplest.

And to remove it, just do a rm -rf *.gz in the applicable directory

This should do it:

gunzip *.gz

Extract all gz files in current directory and its subdirectories:

 find . -name "*.gz" | xargs gunzip

@techedemic is correct but is missing '.' to mention the current directory, and this command go throught all subdirectories.

find . -name '*.gz' -exec gunzip '{}' \;

Try:

ls -1 | grep -E "\.tar\.gz$" | xargs -n 1 tar xvfz

Then Try:

ls -1 | grep -E "\.tar\.gz$" | xargs -n 1 rm

This will untar all .tar.gz files in the current directory and then delete all the .tar.gz files. If you want an explanation, the "|" takes the stdout of the command before it, and uses that as the stdin of the command after it. Use "man command" w/o the quotes to figure out what those commands and arguments do. Or, you can research online.

If you want to extract a single file use:

gunzip file.gz

It will extract the file and remove .gz file.