Super User is a question and answer site for computer enthusiasts and power users. 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
ls -al ../public-back
drwxrwxr-x  4 apache   apache     4096 Apr 19 03:32 templates

ls -al ../public-back/templates

drwxrwxr-x  2 apache   apache    4096 Apr 19 03:33 content
drwxrwxr-x  2 apache   apache   20480 Apr 20 06:14 images
drwxrwxr-x  2 apache   apache    4096 Apr 19 03:35 video

ls -al /public

drwxrwxr-x  4 apache   apache     4096 Apr 20 09:49 templates

ls -al /public/templates

drwxrwxr-x  2 apache   apache    4096 Apr 20 09:50 content
drwxrwxr-x  2 apache   apache    4096 Apr 20 09:50 images
drwxrwxr-x  2 apache   apache    4096 Apr 20 09:50 video

How do I move the contents of /public-back/templates recursively with permissions into /public/templates ?

share|improve this question

migrated from stackoverflow.com Apr 20 '11 at 13:56

This question came from our site for professional and enthusiast programmers.

    
mv ../public-back/templates/* public/templates/ – Vlad Khomich Apr 20 '11 at 10:28
    
mv -R ../public-back/templates/* public/templates/ I'd still vote to move the question. – Vladislav Zorov Apr 20 '11 at 10:33
    
mv: invalid option -- R @Vladislav Zorov – Frank D Apr 20 '11 at 11:12
2  
i did cp -a ../public-back/templates/ public/ – Frank D Apr 20 '11 at 11:20

Unless I am misunderstanding the question wouldn't this work?

mv /public-back/templates/* /public/templates

also, unless you have a huge list of files adding -i will ask before it overwrites anything, which add some safety when using wildcards like *.

share|improve this answer
    
+1 This answer should be accepted. – I Like to Code Apr 23 '14 at 20:22
3  
This does not move hidden files. – Arda Sep 26 '14 at 23:34
    
See askubuntu.com/a/259386/358964 for setting dotglob so hidden files will also be moved. – mkobit Aug 21 '15 at 13:58
1  
Note: This will not overwrite files in subdirectories. You will get a Directory not empty message. – Armstrongest Oct 16 '15 at 18:34
    
Seems that it flattened the directory hierarchy. Did not preserve folders within the original folder for me. All files ended up in the same folder, rather than literally moving the original folder with the same structure. – Robert Noack Jan 24 at 17:33

The man page for cp states:

-p same as --preserve=mode,ownership,timestamps
-r same as --recursive=copy directories recursively

Try;

cp -rp /public-back/templates/* /public/templates/
share|improve this answer
4  
mv is for move, while cp is for copy – a semantical/etymological distinction. – Marius Butuc Mar 19 '13 at 17:34

mv doesn't seem to do this. But you can use this little trick, works like a charm:

tar cf - . |(cd /targetdir; tar xvf -)

and preserves permissions and all.

Note: none of the above worked for me, that's why this workaround.

share|improve this answer

When moving items from my thumb drive to my OSMC system, I've found the following very useful:

find /media/Pi\ Hard\ 16GB/ -name '*' -exec mv -v {} /media/External\ HDD/Videos/ \;

Explanation on how it works below.

BTW, Don't forget to add a backslash before any spaces in the source or destination directory names (see above).

find  finds all files and folders in the destination path.

/media/Pi Hard 16GB/ is the path searched. Escape special char such as spaces.

-name '*' filters on names. If you do not escape or quote this then 
          the shell will expand it before find sees it.

-exec     Executes a command, in our case mv

-v        Verbose, so you can see what's happening (optional)

{}        is replaced by the name of the found object.

Effectively, you are finding all files and all folders and moving them one by one (or if a directory gets found first, you are moving that directory and the contents in it). This starts a new process for each move and is very inefficient. Only use this when the regular commands fail.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .