6
$ ls -la /tee/mysql
total 28675
drwxrwxrwx 1 root root      448 Jun 25 13:52 .
drwxrwxrwx 1 root root     2896 Jun 25 12:12 ..
-rwxrwxrwx 1 root root 18874368 Jun 25 13:19 ibdata1
-rwxrwxrwx 1 root root  5242880 Jun 25 13:52 ib_logfile0
-rwxrwxrwx 1 root root  5242880 Jun 25 13:19 ib_logfile1
drwxrwxrwx 1 root root      984 Jun 25 11:23 mysql
$ sudo ls -la /var/lib/mysql.old
total 88887336
drwx------  6 mysql mysql        4096 Jun 25 11:23 .
drwxr-xr-x 41 root  root         4096 Jun 25 13:15 ..
-rw-r--r--  1 mysql mysql           0 Apr 26 11:10 debian-5.5.flag
-rw-rw----  1 mysql mysql 91010105344 Jun 25 12:12 ibdata1
-rw-rw----  1 mysql mysql     5242880 Jun 25 12:12 ib_logfile0
-rw-rw----  1 mysql mysql     5242880 Jun 25 11:23 ib_logfile1
drwx------  2 mysql mysql        4096 Jun 20 17:22 m
drwx------  2 mysql mysql        4096 Apr 26 11:10 mysql
-rw-rw----  1 mysql mysql           6 Apr 25 06:40 mysql_upgrade_info
drwx------  2 mysql mysql        4096 Apr 26 11:10 performance_schema
drwx------  2 mysql mysql        4096 Feb 12 16:22 test
$ sudo cp -p -f -r /var/lib/mysql.old /tee/mysql
$ sudo ls -la /tee/mysql
total 28676
drwxrwxrwx 1 root root      552 Jun 25 14:09 .
drwxrwxrwx 1 root root     2896 Jun 25 12:12 ..
-rwxrwxrwx 1 root root 18874368 Jun 25 13:19 ibdata1
-rwxrwxrwx 1 root root  5242880 Jun 25 13:52 ib_logfile0
-rwxrwxrwx 1 root root  5242880 Jun 25 13:19 ib_logfile1
drwxrwxrwx 1 root root        0 Jun 25 11:23 mysql
drwxrwxrwx 1 root root      984 Jun 25 11:23 mysql.old
$ df |grep tee # blocks used available percent-used mounted
/dev/sda1                       2930232316 186242116 2743990200   7% /tee
$ cd
$ touch test
$ ls test*
test
$ cp -n test test2 # test whether cp works at all
$ ls test*
test  test2

Why doesn't sudo cp -p -f -r /var/lib/mysql.old /tee/mysql copy the entire contents of mysql.old into mysql?

msh210
  • 115
  • 1
  • 1
  • 12

3 Answers3

4

Actually, you copied the mysql.old directory into /tee/mysql:

cp

But I think that this is not what you wished. I assume that maybe you wished to copy all subdirectories and files from mysql.old directory to /tee/mysql. To do so, use the following command:

sudo cp -p -f -r /var/lib/mysql.old/* /tee/mysql

So, don't forget about /* at the end of the source directory. Generally, for this purpose, use:

cp -pfr <SourceDirectory>/* <DestinationDirectory>

See man cp for more about the cp command.

msh210
  • 115
  • 1
  • 1
  • 12
Radu Rădeanu
  • 166,822
  • 48
  • 327
  • 400
  • I tried that and got `cp: cannot stat â/var/lib/mysql.old/*â: No such file or directory`. – msh210 Jun 25 '13 at 22:49
  • Check if you still have something inside `/var/lib/mysql.old` directory or if this directory exist anymore: `ls /var/lib/mysql.old` – Radu Rădeanu Jun 26 '13 at 05:18
  • It's nonempty. (See also http://askubuntu.com/questions/312674/why-does-cp-not-copy-files/312701?noredirect=1#comment395119_312687 .) – msh210 Jun 26 '13 at 05:27
  • @msh210 Just check again! This is a common issue: [Ubuntu copying file problem (cannot stat file)](http://askubuntu.com/questions/259763/ubuntu-copying-file-problem-cannot-stat-file) – Radu Rădeanu Jun 26 '13 at 06:07
0

You'll see this message if you accidentally try to copy a directory to its current location. So look for a missing ../ or any inaccuracies in the paths.

E.g. I got the message when I accidentally had this

cp -R ../myapp/.git .
cp: ./.git and ../myapp/.git are identical (not copied).

(hadn't gone back far enough), so I changed to this:

cp -R ../../myapp/.git .

Then it worked.

stevec
  • 113
  • 3
0

I just tried the command that you used, and it worked. But go ahead and try this one:

sudo cp -r -fHip -- <Source_Directory> <Target_Directory>

Here is what I did:

sudo cp -r -fHip -- /home/mitch/Test/* /home/mitch/test1

and it copied all files and folders to the destination.

Mitch
  • 106,657
  • 24
  • 210
  • 268
  • I don't see anything about `--` in the `man` page. Can you clarify what it does, please? Also, the example you give includes a trailing `/*` on the source directory whereas the normative code just above it does not. – msh210 Jun 25 '13 at 23:09
  • ...but `sudo cp -r -fHip -- /var/lib/mysql.old /tee/mysql` worked (on that directory. It looks as though I'll have to do subdirectories separately). – msh210 Jun 26 '13 at 05:27