How to remove similar folder from multiple locations in terminal - terminal

I have a folder 'reg_standard' nested within 68 different folders that I want to remove. The path to this folder looks something like:
/Volumes/.../sub-???/run_?.feat/reg_standard
How can I remove this folder and all its contents efficiently? Do I use rm -r?
Thank you!

I propose using regex:
find "/Volumes/**/sub-\d\d\d/run_\d\.feat/reg_standard" -delete

Related

Copying a list of files with wildcards into a new folder

I don't have much experience with the command line, but essentially I have a list of files in a single folder as follows:
file1_a_1
file1_a_2
file2_b_1
file2_b_2
file3_c_1
file3_c_2
And I also have a text file with the files I want. However, this list does not have the full file path, instead, it looks like this:
file1_a file3_c
because I want to move all files that start with 30 or so specific codes (i.e. everything that starts with file1_a and file1_c for all the files that start with this).
I have tried:
cp file1_a* file3_c* 'dir/dest'
but this does not work. I have also tried the find command. I think I have to use a loop to do this but I cannot find any help on looping through files with a wildcard on the end.
Thanks in advance! I am working on a linux machine in bash.
you can use the xargs command with find command and a pipe
find / -name xxxxx | xargs cp /..

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

rename multiple files bash in a subdir

I am trying to use rename but I have several subdirs. The expression I am trying to use is this:
rename 's/ZAUQ-F24MS-SC12-F01-5C\/R44.wav/wav\/2012.wav/' *.wav
I want to rename the file ZAUQ-F24MS-SC12-F01-5C/R44.wav to wav/2012.wav and all files are *.wav files.
I am able to do this from inside the directory but I have multiple directories and a mapped to and from list. Can rename do this or should I be using something else?
Apparently you are moving a file from one directory (ZAUQ-F24MS-SC12-F01-5C) to another (wav). Why not mv then:
mv ZAUQ-F24MS-SC12-F01-5C/R44.wav wav/2012.wav

How to Copy Files Without Overwriting Any Files in Bash Script

I am trying to write a script that finds all my files that are .jpg, and copies them do a new directory. It currently looks like this:
find ~/Pictures -iname \*.jpg -exec cp {} ...newDirectory \;
The problem is that some of my older files have the same name as newer files, when the IMG_#### reset back to 0001 and started counting again.
Is there a way to find the .jpgs and copy without overwriting the files? Ideally giving them a new name in the process.
EDIT
I ended up learning about rsync, which in its own way does exactly what I was looking for. Thanks for the help!
Use -n parameter for cp, that means: do not overwrite an existing file.
To prevent identical names, you could just name all of them unique.
Example:
$ touch screenshot.jpg
$ cp screenshot.jpg screenshot-$(date "+%s").jpg
So basically, mass rename the new files you want to copy to the same name+date.
That will make them different from what's already there, sice the older ones are unnamed or (if you repeat this later) will have different dates.

Script to find files in subdirectories

I need a script that will find and get me all files in all subdirectories (and leave them in the folder structure as they are now). I know how to find and print that files:
find . -name "something.extension"
The point is, in those directories are lots files that was used before, but I don't want to get those, so the script should only find me files that matches some kind of path pattern which is:
xxx/trunk/xxx/src/main/resources
xxx is different everytime, and after resources there are still some folders that directories are different based on xxx.
Every top xxx folder contains folder named 'tags' (the same level as trunk) that stores previous releases of module (and every release has files that name I am looking for, but I don't want outdated files).
So I want to find all that files in subdirectories of that path pattern that I specified and copy to new location but leave folder structure as it is right now.
I am using Windows and cygwin.
Update
I combined answer commands that 'that other guy' posted below, and it works. Just to be clear I have something like this:
find */trunk/*/src/main/resources -name "something.extension" -exec mkdir -p /absolute/target/path/{} \; -exec cp {} /absolute/target/path/{} \;
Thanks.
Instead of searching under the entire current directory (.), just search under the directories you care about:
find */trunk/*/src/main/resources -name "something.extension"

Resources