Extracting a Bunch of .gz Files in One Go using Bash’s For Loop While Keeping Originals

While compressing a set of single files is fairly easy (one only needs to add ‘.gz’ or similar to the end of “file name strings”) the oposite is not so easy. Nevertheless it can be done doing:

for i in *.gz; do echo extracting $i ...; sudo su -c "gzip -dc $i > ${i:0:${#i}-3}"; done && ls *xpm

sudo su -c "" is for Ubuntu systems, ${#i}-3 sais “length of i minus 3” which makes ${i:0:${#i}-3} to become each file name without trailing .gz.


  • Bash by Example
  • man 8 bash section “Parameter Expansion” -> “Substring Expansion”

1 Comment

  1. Saturday, 18th Jun 2011 at 13:23

    Thanks for giving your ideas. Something is that college students have a choice between government student loan plus a private education loan where it truly is easier to select student loan consolidating debts than in the federal education loan.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: