Uncompress several tar.gz files inside several folders
Hi,
I need to uncompress sevral tar.gz files that are located insides sevral folders using a shell script.
Folder tree looks like this :
Inside each folder dossier (001,002,003) we can find 1 or several tar.gz files.
I've scripted something like this :
Issue:
This scripts only works with one tar.gz file inside the folder.
When it finds more then one tar.gz file it crashes the message tar : <path/file.tar.gz> : not found in archive
Some other tests:
-I've tested the code below inside one folder(001) containing several tar.gz.file :
It works.
I try to run it inside my script without success. To many loops I guess
Any "good" ideas are welcome.
Thank you
Last edited by shellX; 07-10-2018 at 11:08 AM..
Reason: Added CODE & ICODE tags
Wold you be better with the find command? You can ask it to locate files of the name format you need and call a command for each one found.
Perhaps this will get you started:-
Beware that if the files found contain full path archives, you might overwrite any file on your server. Additionally, if you are extracting, you might find that your current directory gets all the extracted files into it if they use relative paths. I have set the command to just list the contents for now so you can check what it will try to do.
What is your operating system and shell used ?
Gnu find printf option can be of help if you operating system supports it.
Following should fill you requirement regardless of the paths used in archives (absolute or relative).
You can match folders with regex or input them along each other.
More portable solution could include a awk program which will generate those commands instead of gnu find printf or some xargs magic possibly.
Be sure to get back, if you do not have gnu find.
This solution would be great for a small number of folders.
But unfortunnatelly "for me" I've something like 1000 sub-folders with tar.gz files to uncompress.
I cannot type the names of 1000 folders and subfolders in a script.
That's why my idea in the beggining was to accept a variable "$1"to store the path to the folders containing the tar.gz files
This way the script could be executed automatically for each folder,
(e.g.) below
Moderator's Comments:
Please wrap all code, files, input & output/errors in CODE tags (or ICODE tags for in-line snippets)
It makes it far easier to read and preservers spaces for indenting and/or fixed-width data.
Last edited by rbatte1; 07-11-2018 at 12:53 PM..
Reason: Added CODE tags
Assuming that your code actually starts #!/bin/bash then you can actually simplify this to:-
The shell will expand the directory name with wildcard to make a long list for your for loop.
I've assumed French language for output from your use of ficher. Apologies if that is incorrect.
Does that help?
Robin
Last edited by rbatte1; 07-11-2018 at 01:01 PM..
Reason: Added a debug line to show progress through the file list
hi,
i have a requirement to delete all the files from all the directories except some specific directories like archive and log.
for example:
there are following directories such as
A B C D Archive E Log F
which contains some sub directories and files. The requirement is to delete all the... (7 Replies)
Here is expected output:-
For each file with following file name pattern we need to look at position 1 inside first file matching our search criteria if first letter of the line is 5 then position 88-94 will be 0000001 then look for line immediately after 5 which starts with i.e. position 1 = 8... (6 Replies)
Hi guys,
I'm new to the forums and putting my foot in the door with SED and AWK. I was wondering if someone could help me as I think I'm making this harder than it needs to be...
I have a list of folders named as urls, inside these are log files and possibly a 'status' file. I'm trying to get... (6 Replies)
Hi ,
I have a file which contains few file names. I need to tar those files but am unable to do inside the script. Any help will be useful.
cat /tmp/test
aa.txt
bb.txt
cc.txt
I have tried the below code but its not working.
for i in `cat /tmp/test';do tar -cvf TEST.tar $i;done (9 Replies)
Hi all,
I have a tar file and inside that tar file is a folder with additional tar.gz files. What I want to do is look inside the first tar file and then find the second tar file I'm looking for, look inside that tar.gz file to find a certain directory. I'm encountering issues by trying to... (1 Reply)
i Have 150 tar.gz files and i need to uncompress and extract all the files from those 150 tar.gz and i will have 150 files on daily basis.
could any one help me out with the script to uncompress tar.gz files. (5 Replies)
I've downloaded the tomcat from http://archive.apache.org/dist/jakarta/tomcat-5/v5.0.30/bin/
at window 2000 and then ftp to Solaris 5.9 in binary mode.
gunzip -c jakarta-tomcat-5.0.30.tar.gz | tar -xvf -
tar: directory checksum error
if try this one,
gzip -d jakarta-tomcat-5.0.30.tar.gz... (2 Replies)
i want know how to compress and uncompress file using unix,
compress uncompress,zip,unzip,rar,unrar,how its work and more about this.:confused: (1 Reply)
Hello,
how can I send a compressed file (file.tar.Z) on another server ans uncompresse and extract it there ? My code which is like this
uncompress *tar.Z | rsh serveurB -l user1 "cd /d15/store/; tar xf -"
does not function.
Many thanks before. (4 Replies)
I get a compressed file for linux and I want to uncompress it in Unix. Is that possible?
I try with te command uncompress but it didn´t work.
T.hanks (3 Replies)