Let's assume that I have a file with extension of .7z and I have a crontab that extracts this file. But the name is unknown, only the extension is known, is it possible to extract it from crontab?

Here is my crontab:

2 * * * * root cd /var/path_to_directory && 7za x ".7z*"-p'abc'

This however, does not work and results in: there is no such archive

Any ideas?

  • Try cd /var/path_to_directory && 7z x "*.7z" -p'abc'
    – heemayl
    Sep 17 '15 at 10:28
  • Why did you put * after .7z extension? If you don't know the name, you have to put asterisk before. @heemayl gave you correct answer.
    – obohovyk
    Sep 17 '15 at 12:31

You ran the command 7za with the two arguments x and .7z*-pabc. The file name and the -p option need to be separate arguments. Furthermore .7z* would match file names that begin with .7z, not file names that end with .7z.

7za x "*.7z" -p'abc'

Note that the fact that you can pass *.7z to the 7za command (or more precisely that it does something meaningful with that argument) is specific to that command. Normally, wildcards are expanded by the shell, so if you wanted to extract a file from foo.7z which is the only .7z file in the current directory, you'd need to write 7za x *.7z -p'abc'; the shell would pass the arguments x, foo.7z and -p'abc' to the 7za command. That would work; but 7za does its own wildcard processing (because it's a port of DOS software, and DOS didn't do wildcard processing), so you can also write 7za x "*.7z" -p'abc', where the second argument to 7za is the string *.7z.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.