Zip command creating a directory while unzipping the file
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
0
down vote
favorite
Am creating a zip file in the script, when I run the script and go to the target folder and unzip the zip file I created in script, it's creating a directory and unzipping the file in that directory.
Below is the code in the script.
for fname in `cat $Filenm`
do
echo $fname
fnme=$(echo $fname|awk -F/ 'print $8')
echo $fnme>>$scriptLog
tofilename="$date_new_$fnme"
zip -r $tofilename.zip $fileDir/$fnme
rm $fileDir/$fnme
mv $tofilename.zip $todir
When I go to $todir
after the script execution and unzip $tofilename.zip
, it's creating the $fileDir
in the $todir
and unzipping the file there, so in $todir
I have to go into like 5 sub directories to see my text file.
I want the text file in the zip file to be unzipped into the $todir
, but not the way its happening.
Thanks in advance.
shell zip
add a comment |Â
up vote
0
down vote
favorite
Am creating a zip file in the script, when I run the script and go to the target folder and unzip the zip file I created in script, it's creating a directory and unzipping the file in that directory.
Below is the code in the script.
for fname in `cat $Filenm`
do
echo $fname
fnme=$(echo $fname|awk -F/ 'print $8')
echo $fnme>>$scriptLog
tofilename="$date_new_$fnme"
zip -r $tofilename.zip $fileDir/$fnme
rm $fileDir/$fnme
mv $tofilename.zip $todir
When I go to $todir
after the script execution and unzip $tofilename.zip
, it's creating the $fileDir
in the $todir
and unzipping the file there, so in $todir
I have to go into like 5 sub directories to see my text file.
I want the text file in the zip file to be unzipped into the $todir
, but not the way its happening.
Thanks in advance.
shell zip
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Am creating a zip file in the script, when I run the script and go to the target folder and unzip the zip file I created in script, it's creating a directory and unzipping the file in that directory.
Below is the code in the script.
for fname in `cat $Filenm`
do
echo $fname
fnme=$(echo $fname|awk -F/ 'print $8')
echo $fnme>>$scriptLog
tofilename="$date_new_$fnme"
zip -r $tofilename.zip $fileDir/$fnme
rm $fileDir/$fnme
mv $tofilename.zip $todir
When I go to $todir
after the script execution and unzip $tofilename.zip
, it's creating the $fileDir
in the $todir
and unzipping the file there, so in $todir
I have to go into like 5 sub directories to see my text file.
I want the text file in the zip file to be unzipped into the $todir
, but not the way its happening.
Thanks in advance.
shell zip
Am creating a zip file in the script, when I run the script and go to the target folder and unzip the zip file I created in script, it's creating a directory and unzipping the file in that directory.
Below is the code in the script.
for fname in `cat $Filenm`
do
echo $fname
fnme=$(echo $fname|awk -F/ 'print $8')
echo $fnme>>$scriptLog
tofilename="$date_new_$fnme"
zip -r $tofilename.zip $fileDir/$fnme
rm $fileDir/$fnme
mv $tofilename.zip $todir
When I go to $todir
after the script execution and unzip $tofilename.zip
, it's creating the $fileDir
in the $todir
and unzipping the file there, so in $todir
I have to go into like 5 sub directories to see my text file.
I want the text file in the zip file to be unzipped into the $todir
, but not the way its happening.
Thanks in advance.
shell zip
edited Jul 28 at 4:30
Filipe Brandenburger
2,894417
2,894417
asked Jul 28 at 4:28
New_user
6
6
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
2
down vote
You can use the -j
option to zip
(-j
for "junk paths") which will discard the name of the directory and keep only the file name.
Also, you don't need the -r
option (-r
for "recurse into directories") since you're passing it a single file name (the -r
option is useful when you want to store a whole directory tree into the zipfile.)
So this line should be enough to store the file in the zipfile without the directory name:
zip -j $tofilename.zip $fileDir/$fnme
Another option is to keep storing the full directory path in the zipfile and simply discarding it when you unpack it, by passing the unzip
command the -j
option, which works similarly to how this option works when zipping.
1
Thanks a lot Filipe Brandenburger , i changed it to zip -j $tofilename.zip $fileDir/$fnme , it worked.
â New_user
Jul 28 at 5:22
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
You can use the -j
option to zip
(-j
for "junk paths") which will discard the name of the directory and keep only the file name.
Also, you don't need the -r
option (-r
for "recurse into directories") since you're passing it a single file name (the -r
option is useful when you want to store a whole directory tree into the zipfile.)
So this line should be enough to store the file in the zipfile without the directory name:
zip -j $tofilename.zip $fileDir/$fnme
Another option is to keep storing the full directory path in the zipfile and simply discarding it when you unpack it, by passing the unzip
command the -j
option, which works similarly to how this option works when zipping.
1
Thanks a lot Filipe Brandenburger , i changed it to zip -j $tofilename.zip $fileDir/$fnme , it worked.
â New_user
Jul 28 at 5:22
add a comment |Â
up vote
2
down vote
You can use the -j
option to zip
(-j
for "junk paths") which will discard the name of the directory and keep only the file name.
Also, you don't need the -r
option (-r
for "recurse into directories") since you're passing it a single file name (the -r
option is useful when you want to store a whole directory tree into the zipfile.)
So this line should be enough to store the file in the zipfile without the directory name:
zip -j $tofilename.zip $fileDir/$fnme
Another option is to keep storing the full directory path in the zipfile and simply discarding it when you unpack it, by passing the unzip
command the -j
option, which works similarly to how this option works when zipping.
1
Thanks a lot Filipe Brandenburger , i changed it to zip -j $tofilename.zip $fileDir/$fnme , it worked.
â New_user
Jul 28 at 5:22
add a comment |Â
up vote
2
down vote
up vote
2
down vote
You can use the -j
option to zip
(-j
for "junk paths") which will discard the name of the directory and keep only the file name.
Also, you don't need the -r
option (-r
for "recurse into directories") since you're passing it a single file name (the -r
option is useful when you want to store a whole directory tree into the zipfile.)
So this line should be enough to store the file in the zipfile without the directory name:
zip -j $tofilename.zip $fileDir/$fnme
Another option is to keep storing the full directory path in the zipfile and simply discarding it when you unpack it, by passing the unzip
command the -j
option, which works similarly to how this option works when zipping.
You can use the -j
option to zip
(-j
for "junk paths") which will discard the name of the directory and keep only the file name.
Also, you don't need the -r
option (-r
for "recurse into directories") since you're passing it a single file name (the -r
option is useful when you want to store a whole directory tree into the zipfile.)
So this line should be enough to store the file in the zipfile without the directory name:
zip -j $tofilename.zip $fileDir/$fnme
Another option is to keep storing the full directory path in the zipfile and simply discarding it when you unpack it, by passing the unzip
command the -j
option, which works similarly to how this option works when zipping.
answered Jul 28 at 4:40
Filipe Brandenburger
2,894417
2,894417
1
Thanks a lot Filipe Brandenburger , i changed it to zip -j $tofilename.zip $fileDir/$fnme , it worked.
â New_user
Jul 28 at 5:22
add a comment |Â
1
Thanks a lot Filipe Brandenburger , i changed it to zip -j $tofilename.zip $fileDir/$fnme , it worked.
â New_user
Jul 28 at 5:22
1
1
Thanks a lot Filipe Brandenburger , i changed it to zip -j $tofilename.zip $fileDir/$fnme , it worked.
â New_user
Jul 28 at 5:22
Thanks a lot Filipe Brandenburger , i changed it to zip -j $tofilename.zip $fileDir/$fnme , it worked.
â New_user
Jul 28 at 5:22
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f458992%2fzip-command-creating-a-directory-while-unzipping-the-file%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password