Bash to move specific files from folders in find file
I have a directory /home/cmccabe/nfs/exportedReports that contains multiple folders in it. The find writes the name of each folder to out.txt. A new directory is then created in a new location /home/cmccabe/Desktop/NGS/API, named with the date. What I am trying to do, unsuccessfully at the moment, is copy each specific file type .bam from each folder in out.txt to the new date folder in /home/cmccabe/Desktop/NGS/API/$DATE.
For example, after the find command out.txt:
within each of those folders there are 3 .bam files to move to the new directory/home/cmccabe/Desktop/NGS/API/$DATE. Thank you .
Above code is not doing what you explained in your post.
You need to read line by line in out.txt file then find / list the files with *.bam extension , copy etc.
It may be done in oneliner , if you can add more description about structure of Folder1,Folder2 and /home/cmccabe/nfs/exportedReports with clear example.
if not, try like this:
Sample code written here to update your script.
Last edited by greet_sed; 09-16-2016 at 01:56 PM..
Reason: Add sample code
The below is all most working, there are sub-directories in each folder and the find and cp doesn't need to search these, as the .bam files are all in the main folder. Thank you .
I am getting an error:
--- this is a subdirectory that can be excluded from the find, but I am not sure how.
If I understood your requirement correctly(though I am not sure) it is to copy a specific extension files from source folder to target folder, so could you please try following and let me know if this helps you(not tested though).
So in above code you could put .*bamfiles in place of test*and could put location in place of /tmpabove(destination dire I have put echo(in bold and underline) for testing purposes, so if you are happy with above command's result you could remove that echo. You could set the value of maxdepthas per your requirements too.
Please do let us know how it goes then.
Thanks,
R. Singh
Last edited by RavinderSingh13; 09-16-2016 at 02:50 PM..
This User Gave Thanks to RavinderSingh13 For This Post:
In your post#3 I saw you asked how to exclude any directory or sub-directory in findcommand then following could help you in same. To exclude a directory and only print all the file names following may help you in same.
If you are happy with above command then you could copy files to the destination directory by following command.
So in above codes change values of again_test*to that directory which you want to exclude, test*with those file extensions/names which you want to find here,/tmpwith your destination path please. Change maxdepthvalue as per your need here. Kindly do test the same and please do let us know how it goes for this.
Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
I am trying to mv each of the .vcf files in the variants folder to the folder in /home/cmccabe/f2 that the .vcf id is found in file. $2 in file will always have the id of a .vcf in the variants folder. The line in blue staring with R_2019 in file up to the -v5.6 will always be an exact match to a... (4 Replies)
Hi Team,
I am new to the linux commands and I really need help . I would be really thankful if I can get some inputs.
I have below folders in the path "/home/temp"
20170428
20170427
20170429
changes
tempI need to get the files generated in the last 15 mins in all the above folders... (4 Replies)
Hello all,
do you know any way i can i move folders and its content if folder is older than 1,5 days in bash?
I tried:
find /home/xyz/DATA/* -type d -ctime +1.5 -exec mv "{}" /home/xyz/move_data_here/ \;All i got was that Files from DATA /home/xyz/DATA/* ended messed up in... (1 Reply)
Dear Experts
my scenario is as follows...
I have one source folder "Source" and 2 target folders "Target_123456" & "Target_789101". I have 2 series of files. 123456 series and 789101 series. Each series has got 3 types of fiels "Debit", "Refund", "Claims".
All files are getting... (17 Replies)
I am trying to move specific folders and subfolders within a directory using the below. I can see the folders to move and they are at the location, but I am getting an error. Thank you :).
mv -v /home/cmccabe/Desktop/NGS/API/6-10-2016{bam/{validation,coverage},bedtools /media/cmccabe/"My... (6 Replies)
I am trying to download all files from a user authentication, password protected https site, with a particular extension (.bam). The files are ~20GB each and I am not sure if the below is the best way to do it. I am also not sure how to direct the downloaded files to a folder as well as external... (7 Replies)
Hi friends,
I have one XML file having below structure :-
INput XML file :-
<?xml version="1.0" encoding="UTF-8"?>
<START>
<A=value1>
<attr name1="a1">
</A>
<B=value2>
<attr name2="b1">
<attr name3="c1">
</B>
</START>
output xml file should be
=== (3 Replies)
I'm having problems with my bash script. I would like to find a file matching today's date in the filename, i.e. my_file_20120902.txt and then move it to a different directory, i.e. /tmp. Thanks. (1 Reply)
Hi Friends,
Below is my requirement and i am not clear how to approach this issue in unix programming.
I have a folder with 2500 files. The files are in below format.
1234_name1.txt
1234_name123.txt
4567_name1.txt
4567_name123.txt
and i need a program which will read each file from this... (5 Replies)