How do I gunzip to a different destination directory?
--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Puzzle Game 3
--
Chapters
00:00 How Do I Gunzip To A Different Destination Directory?
00:15 Answer 1 Score 1
00:25 Accepted Answer Score 151
00:50 Answer 3 Score 4
01:18 Thank you
--
Full question
https://superuser.com/questions/139419/h...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#linux #unix #gunzip
#avk47
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Puzzle Game 3
--
Chapters
00:00 How Do I Gunzip To A Different Destination Directory?
00:15 Answer 1 Score 1
00:25 Accepted Answer Score 151
00:50 Answer 3 Score 4
01:18 Thank you
--
Full question
https://superuser.com/questions/139419/h...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#linux #unix #gunzip
#avk47
ACCEPTED ANSWER
Score 151
Ask gunzip
to output to standard output and redirect to a file in that directory:
gunzip -c file.gz > /THERE/file
zcat
is a shortcut for gunzip -c
.
If you want to gunzip multiple files iterate over all files:
for f in *.gz; do
STEM=$(basename "${f}" .gz)
gunzip -c "${f}" > /THERE/"${STEM}"
done
(here basename
is used to get the part of the filename without the extension)
ANSWER 2
Score 4
If you need to extract a single file and write into a root-owned directory, then use sudo tee
:
zcat filename.conf.gz | sudo tee /etc/filename.conf >/dev/null
If the file is coming from a remote source (i.e., ssh
, curl https
, etc), you can do it like this:
ssh remoteserver cat filename.conf.gz | zcat | sudo tee /etc/filename.conf >/dev/null
(Note that these examples only work for a single file, unlike the example *.gz, which is all gzipped files in the directory.)
ANSWER 3
Score 1
You can try with > to redirect the result to the place you want.