Unix & Linux Stack Exchange
Q&A for users of Linux, FreeBSD and other Unix-like operating systems
Latest Questions
1
votes
1
answers
66
views
Recover mis-gzipped folder / directory & files
I needed to compress/archive a folder, so I ran the following command: ``` gzip -v --rsyncable --fast -r myFolder/ -c > myFolderArchive.gz ``` ...foolishly thinking this was going to do just what I thought it would: an archive of `myFolderArchive` and its files recursively. It even had a nice output...
I needed to compress/archive a folder, so I ran the following command:
gzip -v --rsyncable --fast -r myFolder/ -c > myFolderArchive.gz
...foolishly thinking this was going to do just what I thought it would: an archive of myFolderArchive
and its files recursively. It even had a nice output:
./myFolder/file1 ... 80%
./myFolder/file2 ... 20%
...
Opening the archive later however, I only see a single file in it. A quick search led me to understand my mistake: GZip (or I guess, myself) has taken every file, compressed it, and concatenated them one by one into a single file, essentially. Losing all file/directory structure.
In the meantime, I've rm -r
'd the original folder. All I have now is myFolderArchive.gz
.
Would anyone see a way to take that archive, and potentially reconstruct the original set of files, from the myFolderArchive.gz
file's content, now that it's all mixed into a single GZipped file?
I do still have access to the original disk (for a limited time) and could potentially attempt to recover at least the original directory structure (filesystem is ext4). Technically, the content/data itself is in myFolderArchive.gz
, it would "just" need to be sliced right...
Undo
(113 rep)
Dec 22, 2024, 04:32 AM
• Last activity: Dec 23, 2024, 05:59 AM
2
votes
2
answers
12555
views
UNZIP: Cannot find or open filename.zip Error
I have a zipped file (using Winrar) and the size of it is more than 4GB from Windows 10. I've already dumped the file in Unix Server and I want to unzip the file but the error always shows: Code: `unzip filename.zip` `unzip: cannot find or open filename.zip, filename.zip.zip or filename.zip.ZIP.` No...
I have a zipped file (using Winrar) and the size of it is more than 4GB from Windows 10. I've already dumped the file in Unix Server and I want to unzip the file but the error always shows:
Code:
unzip filename.zip
unzip: cannot find or open filename.zip, filename.zip.zip or filename.zip.ZIP.
Note that the zip file contains .csv files (more than 50 files)
Kindly help me. Thanks
Ace
(65 rep)
Jul 9, 2019, 05:16 AM
• Last activity: Dec 2, 2023, 09:04 AM
0
votes
0
answers
1577
views
How to extract .gtar file?
I have a `.gtar` file, I wanted to extract it, but it is not getting extracted. Below are the methods I have tried with its output. I supposed to be contained bunch of text files. ```lang-shellsession $ gtar -xf file.gtar gtar: This does not look like a tar archive. gtar: Skipping to next header. gt...
I have a
.gtar
file, I wanted to extract it, but it is not getting extracted.
Below are the methods I have tried with its output. I supposed to be contained bunch of text files.
-shellsession
$ gtar -xf file.gtar
gtar: This does not look like a tar archive.
gtar: Skipping to next header.
gtar: Exiting with failure status due to previous errors.
$ gtar -xzf file.gtar
gzip: stdin: not in gzip format
gtar: Child returned status 1
gtar: Error is not recoverable: exiting now
$ gunzip -c file.gtar | tar xvf -
gzip: file.gtar: not in gzip format
tar: This does not look like a tar archive
tar: Exiting with failure status due to previous errors
$ tar -xzf file.gtar
gzip: stdin: not in gzip format
tar: Child returned status 1
tar: Error is not recoverable: exiting now
$ file file.gtar
file.gtar: HTML document, ASCII text, with very long lines, with no line terminators
Can anyone please suggest some method to extract it?
Subramanya Krishna
(101 rep)
Apr 10, 2023, 11:03 AM
• Last activity: Apr 11, 2023, 02:56 PM
2
votes
1
answers
1039
views
GNU parallel + gunzip (or 7z, or bsdtar, or unzip): extract every "archivename.zip" into (to-be-created) its "archivename" subfolder
As in title. I've got a lot of ZIP archives that I want to extract. All archives have their own unique name. All archives contain **files only** (inside archives there are **NOT** folder(s) at all: no parent / main folder). I'd like to process all these ZIP archives via GNU parallel. To sum up: - `a...
As in title. I've got a lot of ZIP archives that I want to extract.
All archives have their own unique name.
All archives contain **files only** (inside archives there are **NOT** folder(s) at all: no parent / main folder).
I'd like to process all these ZIP archives via GNU parallel.
To sum up:
-
archivename(s).zip
has **NOT** folder(s) inside
- extract content of archivename(s).zip
into archivename(s)/
folder (this folder needs to be created!)
- **keep** archivename(s).zip
after extracting it
- repeat this for all the ZIP archivename(s).zip
I was wondering about what utility fits best ZIP extraction: gunzip? unzip? bsdtar? 7z?
P. S.: *I'd like to take advantage of GNU parallel for speeding up the whole operation (I'm using SATA SSD devices)*.
T. Caio
(129 rep)
Jun 10, 2020, 10:49 AM
• Last activity: Feb 16, 2023, 08:33 PM
1
votes
2
answers
193
views
Gunzip all the files with a given extension in a different folder
I have a folder with 28 gz files with the extension `.gz` and 28 files with the extension `.gz.bam`. I would like to unzip all the 28 `.gz` files and send them to another folder. I was doing one by one as follows: ``` gunzip -c file1.gz > /mnt/s3/data_transfer/file1 ``` How can I specify I want the...
I have a folder with 28 gz files with the extension
.gz
and 28 files with the extension .gz.bam
.
I would like to unzip all the 28 .gz
files and send them to another folder. I was doing one by one as follows:
gunzip -c file1.gz > /mnt/s3/data_transfer/file1
How can I specify I want the .gz and not the .gz.bam?
RoyBatty279
(33 rep)
Oct 11, 2022, 10:18 AM
• Last activity: Oct 11, 2022, 10:41 AM
3
votes
2
answers
1171
views
gunzip multiple gz files with same compressed file name in multiple folders
I have a directory where there are multiple folders, each folder contains multiple .gz files with the same zipped file name "spark.log". How can I unzip all of them at once and rename them like the gz file? My data looks like this List of folders A B C D In every of them there are files as A spark.l...
I have a directory where there are multiple folders, each folder contains multiple .gz files with the same zipped file name "spark.log". How can I unzip all of them at once and rename them like the gz file?
My data looks like this
List of folders
A
B
C
D
In every of them there are files as
A
spark.log.gz
spark.log.1.gz
spark.log.2.gz
spark.log.3.gz
B
spark.log.gz
spark.log.1.gz
spark.log.2.gz
spark.log.3.gz
C
spark.log.gz
spark.log.1.gz
spark.log.2.gz
spark.log.3.gz
D
spark.log.gz
spark.log.1.gz
spark.log.2.gz
spark.log.3.gz
in each of the gz file contains
spark.log
, I'd like to be able to unzip and rename them according to their gz name. For example:
spark.log.1.gz
-> spark.log.1.log
sojim2
(143 rep)
Oct 7, 2022, 12:30 AM
• Last activity: Oct 10, 2022, 03:16 PM
1
votes
1
answers
1079
views
How Can I Pipe the Sed Command?
I have a bash script that imports wordpress dbs for me pretty reliably, but one of my sites came from a former wordpress multisite, therefore the database includes DEFINERS within the database that prevents the following code from executing correctly ``` gunzip -c $destination_path_to_wordpress/fold...
I have a bash script that imports wordpress dbs for me pretty reliably, but one of my sites came from a former wordpress multisite, therefore the database includes DEFINERS within the database that prevents the following code from executing correctly
gunzip -c $destination_path_to_wordpress/folder/db-export.sql.gz | mysql -u $destination_db_user -p$destination_db_pass $destination_db_name
The above results in ERROR 1227 (42000) at line 3224: Access denied; you need (at least one of) the SUPER or SET_USER_ID privilege(s) for this operation
If I manually export the db then run `sed 's/\sDEFINER=
[^]*
@[^
]*//g' -i db-export.sql
` and then attempt to import the db then I can successfully import the db, search-replace the user name, and site it live.
**Question:**
What is the correct syntax to to combine my current db import command and the sed command that gets rid of the definer problem? something like the following is what I would like to achieve:
clearly incorrect, but you get the gist...
gunzip -c $destination_path_to_wordpress/folder/db-export.sql.gz | sed 's/\sDEFINER=
[^]*
@[^
]*`//g' -i db-export.sql | mysql -u $destination_db_user -p$destination_db_pass $destination_db_name
any tips?
thanks
```
Time-Bandit
(218 rep)
Sep 18, 2022, 05:00 PM
• Last activity: Sep 19, 2022, 06:11 AM
0
votes
0
answers
220
views
unzip: can't set permissions of directory 'folder' : Invalid argument
I have the below script to unzip a .zip file and print out a .txt file of the files in the .zip but when I run the script, I get this output: "unzip: can't set permissions of directory 'folder' : Invalid argument" My script: ``` for file in *.zip do unzip -- "$file" [ -d "${file%%.zip}" ] cd "${file...
I have the below script to unzip a .zip file and print out a .txt file of the files in the .zip but when I run the script, I get this output:
"unzip: can't set permissions of directory 'folder' : Invalid argument"
My script:
```
for file in *.zip
do
unzip -- "$file"
[ -d "${file%%.zip}" ]
cd "${file%%.zip}"
echo -e "${file}\t$(echo $(gzip -cd ${file}|wc -l)/4|bc)" >> results.txt
done
Shortytot
(3 rep)
Aug 16, 2022, 07:47 PM
4
votes
2
answers
337
views
gunzip on Embedded machine
I'm using BusyBox 1.24.1 on my Embedded Linux machine (with kernel v3.10.31) and I get behavior I can't understand when unzipping files.  The `gunzip` command (often, but not always) fails, with no output (not even an error message), even when given a “known good” `.gz` file (i.e., one that I j...
I'm using BusyBox 1.24.1 on my Embedded Linux machine (with kernel v3.10.31) and I get behavior I can't understand when unzipping files.
The
gunzip
command (often, but not always) fails,
with no output (not even an error message),
even when given a “known good” .gz
file
(i.e., one that I just created, using a gzip
command, on the same system).
It's very hard to find a file that can actually be unzipped.
Does anyone get an "Eureka!" when looking at this?
It seems like something in the text file make the gunzip
command fail, but I can't figure out what. See below:
# ls -l
-rw------- 1 root root 65 Sep 13 10:02 cantunzip
-rw------- 1 root root 64 Sep 13 10:01 canunzip
more cantunzip
fsdgafjklsdfasdsdjfhjafasdohfkl asdfas a fsd a
2132313 12 51515
# more canunzip
fsdgafjklsdfasdsdjfhjafasdohfkl asdfas a fsd a
2132313 12 51515
# hexdump cantunzip
0000000 7366 6764 6661 6b6a 736c 6664 7361 7364
0000010 6a64 6866 616a 6166 6473 686f 6b66 206c
0000020 7361 6664 7361 6120 6620 6473 6120 0a0a
0000030 3132 3233 3133 2033 3231 3520 3531 3531
0000040 000a
0000041
# hexdump canunzip
0000000 7366 6764 6661 6b6a 736c 6664 7361 7364
0000010 6a64 6866 616a 6166 6473 686f 6b66 206c
0000020 7361 6664 7361 6120 6620 6473 6120 320a
0000030 3331 3332 3331 3120 2032 3135 3135 0a35
0000040
# gzip canunzip
# gzip cantunzip
# ls -l
-rw------- 1 root root 77 Sep 13 10:04 cantunzip.gz
-rw------- 1 root root 77 Sep 13 10:03 canunzip.gz
# gunzip canunzip.gz
# echo $?
0
# gunzip cantunzip.gz
# echo $?
1
# ls -l
-rw------- 1 root root 77 Sep 13 10:04 cantunzip.gz
-rw------- 1 root root 64 Sep 13 10:04 canunzip
Stric Matic
(41 rep)
Sep 11, 2018, 01:22 PM
• Last activity: Jul 26, 2022, 07:48 PM
0
votes
3
answers
1447
views
Gunzip extract *.gz files to another location
This code was written to extract multiple .tar files to another location and woks fine ```shell ls -1 ${short_filename} \ | while read file; do \ tar -zxvf "$file" -C ${pentaho_temp_path}/${sessionkey}; \ done ``` I want to do the same for .gz files on a Linux machine. My files have no whitespace in...
This code was written to extract multiple .tar files to another location and woks fine
ls -1 ${short_filename} \
| while read file; do \
tar -zxvf "$file" -C ${pentaho_temp_path}/${sessionkey}; \
done
I want to do the same for .gz files on a Linux machine. My files have no whitespace in their names and they look like this:
xport_RAN_Maa_LIM_10.93.217.170_20220629030929.xml.gz
xport_RAN_Maa_LIM_10.93.217.170_20220630030936.xml.gz
xport_RAN_Mau_MPU_10.188.83.138_20220629031403.xml.gz
xport_RAN_Mau_MPU_10.188.83.138_20220630031444.xml.gz
Wessley
(21 rep)
Jul 1, 2022, 09:10 AM
• Last activity: Jul 2, 2022, 09:00 PM
0
votes
0
answers
1293
views
Unable to decompress gzip file ("not in gzip format")
I've been tasked with diagnosing an issue with a webpage, and I've been able to trace the issue back to a `gzip`'ed `JavaScript` file, `jquery.min.js.gz`. To view the code, I've downloaded and attempted to unzip the file on my Linux machine. I'm met with a `not in gzip format` error. The `file jquer...
I've been tasked with diagnosing an issue with a webpage, and I've been able to trace the issue back to a
gzip
'ed JavaScript
file, jquery.min.js.gz
. To view the code, I've downloaded and attempted to unzip the file on my Linux machine. I'm met with a not in gzip format
error.
The file jquery.min.js.gz
command returns that the file is "data", and head jquery.min.js.gz
returns the attached (StackExchange seems forbids posting some of what appear to be Korean characters). Examining the file in Vim, it contains the sort of binary data I'd expect from a gzip
file.
What's going on here?
PerplexedDimension
(101 rep)
Jun 8, 2022, 02:16 AM
0
votes
1
answers
465
views
For all zips, and unzip in working directory and maintains its structure
With this command find . -name '*.zip' -exec unzip '{}' ';' we find all zip files under . (directory), then unzip them into the current working directory, **However,** the structure is gone. /backUp/pic1/1-1.zip /backUp/pic1/1-2.zip /backUp/pic2/2-1.zip /backUp/pic2/2-2.zip /backUp/pic3/3-1.zip /bac...
With this command
find . -name '*.zip' -exec unzip '{}' ';'
we find all zip files under . (directory), then unzip them into the current working directory,
**However,** the structure is gone.
/backUp/pic1/1-1.zip
/backUp/pic1/1-2.zip
/backUp/pic2/2-1.zip
/backUp/pic2/2-2.zip
/backUp/pic3/3-1.zip
/backUp/pic3/3-2.zip
/backUp/pic3/3-3.zip
Current command result:
/new/1-1
/new/1-2
/new/2-1
/new/2-2
/new/3-1
/new/3-2
/new/3-3
desired result
/new/pic1/1-1
/new/pic1/1-2
/new/pic2/2-1
/new/pic2/2-2
/new/pic3/3-1
/new/pic3/3-2
/new/pic3/3-3
Asked here, but the code doesn't work out
https://unix.stackexchange.com/questions/691527/what-should-dirname-and-basename-be-in-this-command
Maxfield
(171 rep)
Feb 23, 2022, 06:32 AM
• Last activity: Feb 23, 2022, 06:43 AM
1
votes
1
answers
721
views
What should dirname and basename be in this command?
With this command, we can recursively unzip archives in a directory and its sub-directories and remain its structure in the current working directory. ``` find ../backUp/ -name "*.zip" | xargs -P 5 -I fileName sh -c ' unzip -o -d "$(dirname "fileName")/$(basename -s .zip "fileName")" "fileName" ' ``...
With this command, we can recursively unzip archives in a directory and its sub-directories and remain its structure in the current working directory.
find ../backUp/ -name "*.zip" |
xargs -P 5 -I fileName sh -c '
unzip -o -d "$(dirname "fileName")/$(basename -s .zip "fileName")" "fileName"
'
But when I run it, all the unzipped folders keep in the original directory.
Can we hard-code basename and dirname in the bash environment?
adding example:
/backUp/pic1/1.zip
/backUp/pic2/2.zip
/backUp/pic3/3.zip
Goal:
/new/pic1/1-1.png
/new/pic1/1-2.png
/new/pic2/2-1.png
/new/pic2/2-2.png
/new/pic3/3-1.png
Maxfield
(171 rep)
Feb 21, 2022, 04:53 AM
• Last activity: Feb 21, 2022, 09:48 PM
0
votes
1
answers
97
views
Getting rid of spurious directories with tar -xzvf, while gunzipping
I want to trim the path of the gunzipped tarball so that some "spurious" leading directories are excluded. Let me explain with an example. I have the following directory structure, as outputted by the `tree` command: tree /tmp/gzip-expt /tmp/gzip-expt ├── gunzip-dir ├── gzip-dir └── repo └── src-tre...
I want to trim the path of the gunzipped tarball so that some "spurious" leading directories are excluded. Let me explain with an example.
I have the following directory structure, as outputted by the
tree
command:
tree /tmp/gzip-expt
/tmp/gzip-expt
├── gunzip-dir
├── gzip-dir
└── repo
└── src-tree
├── l1file.txt
└── sub-dir
└── l2file.txt
5 directories, 2 files
I want to gzip up src-tree in gzip-dir so this is what I do:
cd /tmp/gzip-expt/gzip-dir
tar -czvf file.tar.gz /tmp/gzip-expt/repo/src-tree
Subsequently I gunzip file.tar.gz in gunzip-dir so this is what I do:
cd /tmp/gzip-expt/gunzip-dir
tar -xzvf /tmp/gzip-expt/gzip-dir/file.tar.gz
tree /tmp/gzip-expt/gunzip-dir
shows the following output:
/tmp/gzip-expt/gunzip-dir
└── tmp
└── gzip-expt
└── repo
└── src-tree
├── l1file.txt
└── sub-dir
└── l2file.txt
However, I would like tree /tmp/gzip-expt/gunzip-dir
to show the following output:
/tmp/gzip-expt/gunzip-dir
└── src-tree
├── l1file.txt
└── sub-dir
└── l2file.txt
In other words, I don't want to see the "spurious" tmp/gzip-expt/repo part of the path.
Xin
(3 rep)
Sep 13, 2021, 08:48 AM
• Last activity: Sep 13, 2021, 09:17 AM
3
votes
2
answers
16657
views
Silence the `unknown suffix -- ignored` error
In a directory with many subdirectories, I have some `.gz` archives. I want to recursively extract all these archives using `gunzip`. Hence, I use: ``` gunzip -r myDir ``` However, this command exits with `"non-zero exit status 1"` when there are some files in `myDir` that are not archives, with the...
In a directory with many subdirectories, I have some
.gz
archives. I want to recursively extract all these archives using gunzip
. Hence, I use:
gunzip -r myDir
However, this command exits with "non-zero exit status 1"
when there are some files in myDir
that are not archives, with the errors being:
gunzip: myDir/dir1/file1.vcf.gz.tbi: unknown suffix -- ignored
Any idea how I can silence this particular error/warning?
Dr. Strangelove
(131 rep)
Jul 17, 2021, 12:11 AM
• Last activity: Jul 20, 2021, 02:28 PM
0
votes
0
answers
340
views
Trying to append a file to a tarball through a pipe
I am trying to execute a simple pipeline which should gunzip a file and send the result to stdout. This is ten piped into a tar command which to my knowledge should append the file I specify. I use a hyphen to denote the stdin decompressed tarball which I am trying to append to. gunzip -c sandbox.tg...
I am trying to execute a simple pipeline which should gunzip a file and send the result to stdout. This is ten piped into a tar command which to my knowledge should append the file I specify. I use a hyphen to denote the stdin decompressed tarball which I am trying to append to.
gunzip -c sandbox.tgz | tar rvf - hongkong.mp4
I receive the following response when I execute the command
tar: Options '-Aru' are incompatible with '-f -'
nrmad
(115 rep)
Mar 14, 2021, 03:04 PM
0
votes
1
answers
407
views
List only files and not directories in archive
I have a zip achieve like below $ unzip -l 5124.zip Archive: 5124.zip Length Date Time Name --------- ---------- ----- ---- 0 01-13-2021 09:22 u/ 0 01-13-2021 09:22 u/MyCom/ 0 01-13-2021 09:22 u/MyCom/UNX/ 0 01-13-2021 09:22 u/MyCom/UNX/scripts/ 0 01-13-2021 09:22 u/MyCom/UNX/scripts/SYNC/ 0 01-13-2...
I have a zip achieve like below
$ unzip -l 5124.zip
Archive: 5124.zip
Length Date Time Name
--------- ---------- ----- ----
0 01-13-2021 09:22 u/
0 01-13-2021 09:22 u/MyCom/
0 01-13-2021 09:22 u/MyCom/UNX/
0 01-13-2021 09:22 u/MyCom/UNX/scripts/
0 01-13-2021 09:22 u/MyCom/UNX/scripts/SYNC/
0 01-13-2021 09:22 u/MyCom/UNX/scripts/SYNC/sql/
48704 01-13-2021 01:50 u/MyCom/UNX/scripts/SYNC/sql/Load.sql
41872 01-13-2021 01:00 u/MyCom/UNX/scripts/SYNC/sql/Update1.sql
--------- -------
90576 8 files
I want to just get the filenames in the archive while ignoring the rest which in the above case is
/u/MyCom/UNX/scripts/SYNC/sql/Load.sql
/u/MyCom/UNX/scripts/SYNC/sql/Update1.sql
Note: The preceding
/
is missing from the output of unzip
this I need
/u/MyCom/UNX/scripts/SYNC/sql/Load.sql
/u/MyCom/UNX/scripts/SYNC/sql/Update1.sql
and not
u/MyCom/UNX/scripts/SYNC/sql/Load.sql
u/MyCom/UNX/scripts/SYNC/sql/Update1.sql
Any good way to get this info from any given zip ?
Ashar
(527 rep)
Jan 19, 2021, 06:52 PM
• Last activity: Jan 19, 2021, 07:51 PM
0
votes
2
answers
2452
views
Gzip of folder while retaining original timestamp
I want to do gzip of folder, and also want to retain original timestamp for that folder. Can someone suggest any way around it. i tried below mentioned code. The timestamp which i am getting the time when zip happened. ```sh tar -zcvf outputFileName folderToCompress ```
I want to do gzip of folder, and also want to retain original timestamp for that folder. Can someone suggest any way around it.
i tried below mentioned code. The timestamp which i am getting the time when zip happened.
tar -zcvf outputFileName folderToCompress
Code-x Go
(29 rep)
Dec 2, 2020, 07:35 AM
• Last activity: Dec 2, 2020, 08:09 AM
253
votes
2
answers
912400
views
Unzipping a .gz file without removing the gzipped file
I have a file `file.gz`, when I try to unzip this file by using `gunzip file.gz`, it unzipped the file but only contains extracted and removes the `file.gz` file. How can I unzip by keeping both unzipped file and zipped file?
I have a file
file.gz
, when I try to unzip this file by using gunzip file.gz
, it unzipped the file but only contains extracted and removes the file.gz
file.
How can I unzip by keeping both unzipped file and zipped file?
jack
(3933 rep)
Sep 18, 2014, 02:47 PM
• Last activity: Nov 25, 2020, 12:32 AM
0
votes
1
answers
3137
views
"xz : (stdout) : Write error: File too large" while writing a tar archive
I wanted to compress a directory whit size of about 25 GB to `.tar.xz` format using following command: tar --xz --create --verbose --file myArchive.tar.xz /patch/to/my/dir but got these error lines: xz: (stdout): Write error: file too large tar: myArchive.tar.xz: wrote only 2048 of 10240 bytes tar:...
I wanted to compress a directory whit size of about 25 GB to
.tar.xz
format using following command:
tar --xz --create --verbose --file myArchive.tar.xz /patch/to/my/dir
but got these error lines:
xz: (stdout): Write error: file too large
tar: myArchive.tar.xz: wrote only 2048 of 10240 bytes
tar: Child returned status 1
tar: Error is not recoverable: exiting now
I tried it for .tar.gz
format too and got approximately same error lines.
I am using Fedora 32 and the destination file system is W95 FAT32(LBA). The file stopped writing at about 4.3 GB. What's strange is that my disk has more than 500GB free space.
What is the problem and how can I fix it?
mmj
(119 rep)
Nov 13, 2020, 02:22 PM
• Last activity: Nov 13, 2020, 04:50 PM
Showing page 1 of 20 total questions