Copy files from Terminal command line result - macos

With the find-command in OS X Terminal. The files and folders I'm getting I would like to copy to another folder. The problem is that files are after copying outside of their folder. The command line is
find ~/Library/Safari -exec cp -R {} ~/Music/ \;
Has anyone another solution?
Thanks a lot!
EDIT: The paths of the Safari-Library and the Music-Folder are only examples.

Related

Copy command in Mac Terminal fails with "No such file or directory"

This should be straightforward, but I'm getting weird results.
I have a folder with subfolders containing ~4000 files. I'm trying to copy just the files of a certain filetype to another folder, while preserving the subfolder hierarchy.
Command:
cp -R /Users/Steve/Desktop/Hardscapes/*.LOB /Users/Steve/Desktop/Temp
fails with the message:
"/Users/Steve/Desktop/Hardscapes/*.LOB: No such file or directory".
I created the command by typing cp -R then dragging the source folder to the terminal window, adding *.LOB after the /, and dragging the destination folder to the terminal window.
Troubleshooting:
replacing *.LOB with *.* gives the same error.
cp -R /Users/Steve/Desktop/Hardscapes/ /Users/Steve/Desktop/Temp copies the entire Hardscapes folder to Temp, with all its subfolders and files.
Thanks for your help and suggestions.
EDIT: The folder Hardscapes contains only other folders. If I run the command above using one of those folders as the source, the contents are copied faithfully. The folder Hardscapes itself contains no .LOB files - they're only in the subfolders.
So maybe that's the issue, cp can't find any files corresponding to Hardscapes/*.LOB? But I thought the -R switch was supposed to tell it to look through all the subfolders.
Next I put a file named Test.LOB in the Hardscapes folder. The command above copies only that file and none of the subfolders. It looks like the -R switch is not doing its job. Do I have the syntax right?
Try this:
rsync -a --prune-empty-dirs --include '*/' --include '*.LOB' --exclude '*' /Users/Steve/Desktop/Hardscapes/ /Users/Steve/Desktop/Temp
As you already mentioned, directory Hardscapes itself contains no .LOB files. That's why your mask /Users/Steve/Desktop/Hardscapes/*.LOB results in matching no files at all.

Windows Shell Script to scan folder & copy file

I would like to loop throught folder & its subfolders & start scnanning and copying a file to specific location within each folder
Regards,
Sorry, can't comment with less than 50 reputation, have to answer instead.
Are you looking for a certain file type to copy or you want to copy everything from one folder to another? Or, if you find a file of interest, you want to create a new folder and copy it to there?
If you could specify these things, it will be a little easier to provide an answer.
Thanks, Tim.
As per my understanding you have to copy a specific file or file type into a specific dir.
You can try find command with copying specific file into your directory .
find /source_dir/ -type f -name "filename_or_type" -exec cp -t /destination_dir/ {} \;

mac osx copy command for copying only files with a given subname?

I want to copy (and overwrite) files and folders from a directory hierarch, only if they have a common string in name like 'fabrik'.
Example directory: com_fabrik, example file: fabriklist.php
Which terminal command should I use to execute this copy?
Use find
find /your/directory -name="*.php" -exec cp -R {} ../otherfolder \;

Mac OS X command or script to zip all subfolders with a particular name

I have a folder containing many files and subfolders multiple levels deep. I'm looking for a command or script that will zip any subfolder called "fonts", resulting in a fonts.zip file at the same level as the fonts folder.
The fonts folders should remain after creation of their zip files (no delete).
If there is a fonts folder inside another fonts folder (unlikely case), only the top-level fonts folder should result in a fonts.zip file (ideal, but not mandatory).
If there is already a fonts.zip file at the same level as the fonts folder, it should be replaced.
I'll admit, I'm a Mac newbie. Hopefully there can be a simple terminal command to accomplish this. But I'm open to other ideas how to accomplish this.
Thanks,
-Matt
Using Kevin Grant's suggestion as a starting point, I was able to put together a terminal command that works the way I needed:
find . -type d -iname '*fonts' -execdir ditto -c -k -X --rsrc {} fonts.zip \;
I referred to the man pages for the find and ditto commands and their switches. I chose to use ditto over zip because it is supposed to be more compatible with HFS and resource forks under Mac OS X. Next I'll find out if StuffIt has a command line tool. If so, I'll use it instead of ditto.
This was also helpful.

copy files across directories using terminal in mac

How to copy all files with an specific extension .SAV from one directory (including all subdirectories within that directory) to another one? I am using the terminal from mac. I have tried
/Users/tournillon/my_directory/research_projects/dissertation_related/inequality
Antonio-P-Tournillon-Ramoss-iMac:inequality tournillon$ ls
Brazil dhs_dados imr201101app.pdf
GHME_Education_final.pptx dhs_sav_files
Antonio-P-Tournillon-Ramoss-iMac:inequality tournillon$ dhs_dados /*.SAV/ dhs_sav_files/
I would assume this is a trivial task but I just can't get the syntax right.
Many thanks,
Antonio Pedro.
find /source/directory -iname \*.sav -exec cp {} /destination/directory/ \;
If you mean a UNIX copy,
cp -R <dirA>/*.sav <dirB>/
I'm not sure what dhs_dados is in your question..
Why not just use cp *.SAV directory

Resources