copy files across directories using terminal in mac - macos

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

Related

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/ {} \;

Copy files from Terminal command line result

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.

How to move files of "specific extension" ( from directories ) to a new location while maintaining full directory structure ?

I have following directory structure :
/home/dir1/abc.jpg
/home/dir1/abc.pdf
/home/dir1/dir2/abc.jpg
/home/dir1/dir2/abc1.jpg
/home/dir1/dir2/dir3/abc.jpg
and I want to copy jpg files from them to a new folder which will have same directory structure, for eg.:
/home/newdir1/abc.jpg
/home/newdir1/dir2/abc.jpg
/home/newdir1/dir2/abc1.jpg
/home/newdir1/dir2/dir3/abc.jpg
How to achieve it using rsync or any other software ?
Please help, Many Thanks !!
From the looks of what you've included in your question, there are a couple of things you might try.
You've specified that you want to "move" files. That means you either use the mv command, or use rsync's --remove-source-files option. For example:
mv /source1/* /source2/* /path/to/targetdir/
or
rsync -a /source1/ /source2/ /path/to/targetdir/
You've no doubt already read the part of rsync's man page that explains the difference between source dirs with and without their trailing slash. If not, read up, because it's important.
If your "thousands of source files [with] similar names" need to be matched from within your source directories, leaving some other files behind, you need to determine whether your "similar names" can be differentiated using pathname expansion or if you should use a regular expression. If the former, then adding the pathname expansion to your sources with either mv or rsync should be sufficient. If you need to use a regex, then find may be a better option:
find /source1/ /source2/ -regex ".*/file[A-F][0-9][0-9].txt" -exec mv "{}" /targetdir/ \;
If these don't solve the problem, then you'll need to supply more detail in your question.
I would try a little shell script like this:
#!/bin/sh
cd /home/dir1
JPEGS=`find . -name "*.jpg"`
tar cf - $JPEGS | (cd /home/newdir1 ; tar xf -)
This first gets the list of all your jpg files with their relative paths, then writes a tar file of them to a pipe into a subshell which changes to the new directory, and then extracts the tar from its stdin.

Collect files from all subdirectories

I have a directory with about 5,000 subdirectories in it.
Each subdirectory contains one file each.
I'd like to collect those files and put them in the same folder somewhere.
Is there a way to do that by Mac OSX terminal command? Or should I write a, say, python script to do that?
Something like,
find . -type f -exec echo mv {} /path/to/dst/dir/ \;
You'll have to tweak this according to your circumstances, of course. See man find for details. Remove the echo when you're ready to run for real (preferably after taking a backup).

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 \;

Resources