Zip command creating a directory while unzipping the file

The name of the pictureThe name of the pictureThe name of the pictureClash 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.







share|improve this question



























    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.







    share|improve this question























      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.







      share|improve this question













      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.









      share|improve this question












      share|improve this question




      share|improve this question








      edited Jul 28 at 4:30









      Filipe Brandenburger

      2,894417




      2,894417









      asked Jul 28 at 4:28









      New_user

      6




      6




















          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.






          share|improve this answer

















          • 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










          Your Answer







          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "106"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );








           

          draft saved


          draft discarded


















          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






























          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.






          share|improve this answer

















          • 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














          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.






          share|improve this answer

















          • 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












          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.






          share|improve this answer













          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.







          share|improve this answer













          share|improve this answer



          share|improve this answer











          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












          • 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












           

          draft saved


          draft discarded


























           


          draft saved


          draft discarded














          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













































































          Popular posts from this blog

          How to check contact read email or not when send email to Individual?

          Displaying single band from multi-band raster using QGIS

          How many registers does an x86_64 CPU actually have?