Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm working on making some scripts more elegant by implementing them in a real x application etc...

At some point in the scripts we basically want to take everything from a mounted removable storage device, and copy into specified folder in a tmp work folder. When executing in the shell it works without a hitch. When executed from the code, it fails.

Copy Command:

cp -avfr /tmp/mnt221234jk/* /tmp/mnt23255/disk1/

and the error I get from native app is:

cp: cannot stat: '/tmp/mnt221234jk/*' file not found.

The strange part is that it is absolutely there, has appropriate permissions for the user running the app etc. I can both stat /tmp/mnt221234jk/* and run the cp command from the shell and both work just fine.

In addition to this, if I omit the /* from the file copy origin, it works, but creates a new folder in the destination with name mnt221234jk which is not what I am looking for.

A couple of side notes: my code to execute shell commands absolutely works, and works well. But there very well may be something funky about needing work paths or something like that.

Does failing to stat based on file not existing error ring any bells with anyone?

I'd be willing to attempt to achieve this differently if there are alternative shell commands to effectively copy a file structure recursively with permissions etc.

share|improve this question
Give a minimal example that fails for you. – Faheem Mitha Nov 11 '11 at 19:11
To be clear, you actually have a file called /tmp/mnt221234jk/*?! Really? – David Schwartz Nov 12 '11 at 6:13

The call in the script where you're having the problem isn't globbing the files, but the shell does. I'm not quite clear on how you're calling it, but you'll need to either find a way to glob or loop over the files.

share|improve this answer

Well I apologize in advance, the real problem was actually really quite simple... it was a problem with globbing files, but not because my shell had explicitly disabled it, or relative pathing.

I was launching "shell scripts" and shell commands but outside the context of bash/sh/tcsh etc. Executing cp directly is gonna just be problematic as far as that goes.


/bin/bash -c "cp /blah/* /someotherdir/"

worked fantastically. Appreciate the clues!

share|improve this answer
That's the answer I was looking for! Quick and working! – alex May 16 '15 at 15:45

There's a bug in your script. We can't tell where because you haven't shown your script.

Given your limited description, it seems that the shell is not expanding /tmp/mnt221234jk/* to a list of files, even though the cp command, which is running with the same privileges, can traverse the directory. So a likely explanation is that you've turned off globbing with set -f or set -o noglob at some point. Turn in back on with set +f.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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