Zip error nothing to do linux

zip error — Nothing to do

The issue is that you have not provided a name for the zip-files it will create.

find /home/user/rep/tests/data/archive/* -maxdepth 0 -type d -exec zip -r "<>" "<>" \; 

This will create separate zipped directories for each of the subfolders tmp tmp_dkjg and tmp_dsf

To create a zipfile:

  • From a list of files, zip myZippedImages.zip alice.png bob.jpg carl.svg . You need to specify both
    • the zipfile (output), and
    • the files you will zip (input).

    To make it clearer than Alex’s answer, to create a zip file, zip takes in a minimum of 2 arguments. How do I know, because when you use man zip , you get its man page, part of which is:

    zip [-aABcdDeEfFghjklLmoqrRSTuvVwXyz!@$] [--longoption . ] [-b path] [-n suffixes] [-t date] [-tt date] [zipfile [file . ]] [-xi list] 

    and when you typed zip in the command line, you get:

    zip [-options] [-b path] [-t mmddyyyy] [-n suffixes] [zipfile list] [-xi list] 

    In both cases, notice [zipfile list] or [zipfile [file . ]] . The square brackets indicate something being optional. If you’re not saving to a zipfile, then the list argument is not required.

    If you want to save into a zipfile (choosing the [zipfile list] option, you need to also provide list , because it is within the square brackets. For this reason, I prefer the output of zip instead of man zip . (The man page might be confusing)

    Источник

    `zip` works in shell but not in Python script

    According to this post I’m calling the zip command using os.system() in Python. At the command line it works:

    zip -r /Backups/backups/20152011-120209
    zip error: Nothing to do! (/Backups/backups/20152011-122909) 

    What am I doing wrong? I want to zip a directory (including its content) to a zip file with the same name at the same place (a script dumps my MySQL databases to *.sql files and I want to zip the files after that).

    Not at home right now, but using os.system at all is a really bad idea. Outdated and deprecated. Use subprocess.call() or subprocess.Popen() intead.

    1 Answer 1

    Before getting to the problem, I’ll quote Jacob Vlijm’s comment under this answer (thanks for the comment and for the link):

    [. ] using os.system at all is a really bad idea. Outdated and deprecated. Use subprocess.call() or subprocess.Popen() intead.

    Here’s the first (or one of the first) deprecation proposal, dated back to 2010.

    So you should really use subprocess.Popen() instead of os.system() .

    When you run os.system() the command is executed in Dash ( /bin/sh ), while when you run the command in a terminal the command is executed in Bash ( /bin/bash );

    Dash doesn’t support brace expansion and interprets literally;

    Run the command in Bash: change

    os.system("bash -c 'zip -r " + PATH + "'") 

    Or anyway as Darael suggests FWIW passing /Backups/backups/20152011-120209 to expand /Backups/backups/20152011-120209 to /Backups/backups/20152011-120209.zip and /Backups/backups/20152011-120209 you might as well just pass the paths directly avoiding to spawn another shell:

    os.system("zip -r " + PATH + ".zip " + PATH) 

    Источник

    How to fix zip error — nothing to do in Bash?

    The «Nothing to do» error message when using the zip command in a bash shell can occur when there are no files to compress or archive. The error message is displayed when there is no argument or files specified for the zip command. This error can also occur when the specified files or directories do not exist or are invalid. To fix this issue, there are several methods that can be used to ensure that the correct files and directories are being compressed or archived.

    Method 1: Verify the Files Exist

    To fix the «Nothing to do» error in Bash when trying to zip files, you can use the «Verify the Files Exist» method. This involves checking if the files you want to zip actually exist before attempting to zip them. Here’s how you can do it:

    #!/bin/bash file1="file1.txt" file2="file2.txt" file3="file3.txt" if [ -f "$file1" ] && [ -f "$file2" ] && [ -f "$file3" ]; then # If all files exist, zip them zip myfiles.zip "$file1" "$file2" "$file3" echo "Files zipped successfully" else # If any file does not exist, show an error message echo "Error: One or more files do not exist" fi

    In this example, we first define the files we want to zip. Then, we use the -f flag to check if each file exists. If all files exist, we use the zip command to zip them into a file called «myfiles.zip». Otherwise, we show an error message.

    Note that you can modify this code to suit your specific needs. For example, you can change the names of the files or the name of the output zip file. Just make sure to include all the necessary files in the zip command.

    Overall, this method is a simple and effective way to fix the «Nothing to do» error in Bash when trying to zip files.

    Method 2: Use Absolute Paths

    To fix the «Bash: how to fix zip error — Nothing to do?» error, you can use absolute paths. Here’s how to do it in a few simple steps:

    zip /path/to/newfile.zip file1.txt file2.txt
    zip -f /path/to/existingfile.zip file1.txt file2.txt

    Using absolute paths ensures that the zip command knows exactly where to find the files you want to zip, regardless of your current working directory.

    Method 3: Check for Read Permissions

    To fix the «Bash: how to fix zip error — Nothing to do?» error with «Check for Read Permissions», you can use the following steps:

    Here is an example code snippet that implements the above steps:

    ls -l file.zip chmod +r file.zip ls -l file.zip zip archive.zip file.zip

    By following these steps, you should be able to fix the «Bash: how to fix zip error — Nothing to do?» error with «Check for Read Permissions».

    Method 4: Specify the Compression Level

    To fix the «Nothing to do» error in Bash when trying to zip a file, you can specify the compression level. This error occurs when the zip command is unable to find any files to add to the archive. By specifying the compression level, you can force the command to create the archive even if there are no files to add.

    Here are the steps to fix the error:

    1. Open your terminal or command prompt.
    2. Navigate to the directory where the file you want to zip is located.
    3. Run the following command:

    That’s it! You have successfully fixed the «Nothing to do» error in Bash when zipping a file by specifying the compression level.

    Источник

    Why does `zip` in a for loop work when the file exists, but not when it doesn’t?

    I have a directory that contains several sub-directories. There is a question about zipping the files that contains an answer that I ever-so-slightly modified for my needs.

    for i in */; do zip "zips/$.zip" "$i*.csv"; done 

    However, I run into a bizarre problem. For the first set of folders, where zips/.zip does not exist, I get this error:

    zip error: Nothing to do! (zips/2014-10.zip) zip warning: name not matched: 2014-11/*.csv 
    for i in */; do echo zip "zips/$.zip" "$i*.csv"; done 

    Then run the echoed command ( zip zips/2014-10.zip 2014-10/*.csv ), it works fine and zips up the folder. Then the fun part about that is that subsequent runs of the original command will actually zip up folders that didn’t work the first time! To test this behavior yourself:

    cd /tmp mkdir -p 2016-01 2016-02 2016-03 zips for i in 2*/; do touch "$i"/one.csv; done for i in 2*/; do touch "$i"/two.csv; done zip zips/2016-03.zip 2016-03/*.csv for i in 2*/; do echo zip "zips/$.zip" "$i*.csv"; done for i in 2*/; do zip "zips/$.zip" "$i*.csv"; done 
    zip zips/2016-01.zip 2016-01/*.csv zip zips/2016-02.zip 2016-02/*.csv zip zips/2016-03.zip 2016-03/*.csv 
     zip warning: name not matched: 2016-01/*.csv zip error: Nothing to do! (zips/2016-01.zip) zip warning: name not matched: 2016-02/*.csv zip error: Nothing to do! (zips/2016-02.zip) updating: 2016-03/one.csv (stored 0%) updating: 2016-03/two.csv (stored 0%) 

    So it’s actually updating the zip file with the .csv s where the zip file exists, but not when the zip file is created. And if you copy one of the zip commands:

    $ zip zips/2016-02.zip 2016-02/*.csv adding: 2016-02/one.csv (stored 0%) adding: 2016-02/two.csv (stored 0%) 
    for i in 2*/; do zip "zips/$.zip" "$i*.csv"; done 
    . ├── 2016-01 │ ├── one.csv │ └── two.csv ├── 2016-02 │ ├── one.csv │ └── two.csv ├── 2016-03 │ ├── one.csv │ └── two.csv └── zips ├── 2016-02.zip └── 2016-03.zip 
    zsh -c "$(for i in 2*/; do echo zip "zips/$.zip" "$i*.csv"; done)" 

    Источник

    Читайте также:  Обновить репозитории linux debian
Оцените статью
Adblock
detector