Solved how to cp -a /* /mnt/

I'm trying to copy all the local files to a remote partition - /mnt/ but when running cp -a /* /mnt/ I get recursive copying of /mnt/. Looking a cp() I though '-x' was my solution but it wasn't.

Any suggestions?
 
You might also want to keep in mind that certain directories are special like /dev, /media, /net, and /tmp. For example, if you have an 8 GiB USB drive that was auto-mounted at /media/usb8G, you probably don't want to copy that directory at all, nevermind its contents!
 
If you don't want to throw them all on the command line, use a text file and specify tar -X file to parse the file and skip the directories/files listed in it.

Or, if you're set on using cp etc. why not just a little shell script:

Code:
#!/bin/sh

exempt="mnt/ dev/ media/"

cd /
for dir in `ls -d */` ; do
        skip=0
        for skipdir in $exempt; do
                if [ $skipdir = $dir ]; then
                        skip=1
                        break
                fi
        done
        if [ $skip -eq 0 ]; then
                cp -a $dir /mnt/
        fi

done
 
Back
Top