2

When I try to copy cp -rf mydir/* .../mydir/. I get next error:

cp: cannot stat 'mydir/*': No such file or directory

But there are files in this directory.

Please help me to find out reason of it.

Dmitro
  • 133

1 Answers1

4

If the shell cannot find anything to expand * into, then it leaves it untouched. So if there are no files or directories in mydir (except hidden/dot files/directories), then mydir/* is passed as it is to cp. And cp cannot find any file called mydir/*, as the error says.

For example:

$ ls /srv -l
total 0
$ ls /srv/*
ls: cannot access /srv/*: No such file or directory

Unless you're trying to exclude hidden files and folders you should simply do:

cp -r mydir ../
terdon
  • 100,812
muru
  • 197,895
  • 55
  • 485
  • 740