How to copy file preserving directory path in Linux?

The switch you need is –parents, e.g.: jim@prometheus:~$ cp –parents test/1/.moo test2/ jim@prometheus:~$ ls -la test2/ total 42 drwxr-xr-x 3 jim jim 72 2010-09-14 09:32 . drwxr-xr-x 356 jim jim 43136 2010-09-14 09:32 .. drwxr-xr-x 3 jim jim 72 2010-09-14 09:32 test jim@prometheus:~$ ls -la test2/test/1/.moo -rw-r–r– 1 jim jim 0 2010-09-14 09:32 test2/test/1/.moo

MySQL: Cloning a MySQL database on the same MySql instance

As the manual says in Copying Databases you can pipe the dump directly into the mysql client: If you’re using MyISAM you could copy the files, but I wouldn’t recommend it. It’s a bit dodgy. Integrated from various good other answers Both mysqldump and mysql commands accept options for setting connection details (and much more), like: Also, if the new database is not … Read more

PG COPY error: invalid input syntax for integer

ERROR: invalid input syntax for integer: “” “” isn’t a valid integer. PostgreSQL accepts unquoted blank fields as null by default in CSV, but “” would be like writing: and fail for the same reason. If you want to deal with CSV that has things like quoted empty strings for null integers, you’ll need to feed it to PostgreSQL via … Read more

Is there a function to make a copy of a PHP array to another?

In PHP arrays are assigned by copy, while objects are assigned by reference. This means that: Will yield: Whereas: Yields: You could get confused by intricacies such as ArrayObject, which is an object that acts exactly like an array. Being an object however, it has reference semantics. Edit: @AndrewLarsson raises a point in the comments … Read more

Java Copy Constructor ArrayLists

Note: Cloning the lists, isn’t the same as cloning the elements in the list. None of these approaches work the way you want them to: The approaches above will fill people such that it contains the same elements as other.people. However, you don’t want it to contain the same elements. You want to fill it with clones of … Read more

How to copy a char array in C?

You can’t directly do array2 = array1, because in this case you manipulate the addresses of the arrays (char *) and not of their inner values (char). What you, conceptually, want is to do is iterate through all the chars of your source (array1) and copy them to the destination (array2). There are several ways to … Read more