Copying files (specifically photos) from a macbook

2019-09-15 16:19发布

问题:

Copying files (specifically photos) from a macbook to a USB. Ps. i am new to bash and shell and all that, so a description on how to do it too is very much appreciated (sorry if bad english)

回答1:

Here are some things to get you started...

You can get the mount point of an external, physical drive like this:

diskutil list -plist external physical | plutil -p - | awk -F\" '/"MountPoint"/{print $(NF-1)}'

So, if you want that in a variable do:

usb=$(diskutil ...)
echo $usb 

Sample Output

/Volumes/MUSIC

You can get a list of JPG/jpg/JPEG/jpeg/PNG/png files in the users' HOME directories with:

find /Users -iname \*.jpg -o -iname \*.jpeg -o -iname \*.png

Simplistically, you could now exec cp for each file you find to copy it to your USB drive. However, there are some issues with that - what if you have a file called a.jpg in two different directories - only the second one to be copied will end up on your USB.

find /Users -iname   ...   -exec cp {} "$usb" \;


标签: bash shell