Sponsored Content
Top Forums Shell Programming and Scripting Bash to move specific files from folders in find file Post 302981647 by cmccabe on Friday 16th of September 2016 11:35:34 AM
Old 09-16-2016
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:
Code:
Folder1
Folder2

within each of those folders there are 3 .bam files to move to the new directory/home/cmccabe/Desktop/NGS/API/$DATE. Thank you Smilie.

Code:
#!/bin/bash

cd /home/cmccabe/nfs/exportedReports
find . -maxdepth 1 -type d | cut -c 3- | awk -F _ 'NF > 1' > out.txt

DATE=`date +%-m-%-d-%Y` 
        mkdir -p /home/cmccabe/Desktop/s5/$DATE

MY_DIR="/home/cmccabe/nfs/exportedReports/out.txt"
DEST="/home/cmccabe/Desktop/NGS/API/$DATE"
FILEEXT=".bam"

NEWEST=`ls -tr1d "${MY_DIR}/"*.${FILEEXT} 2>/dev/null | tail -1`

if [ -z "${NEWEST}" ] ; then
    echo "No file to copy"
    exit 1
elif [ -d "${NEWEST}" ] ; then
    echo "The most recent entry is a directory"
    exit 1
else
    echo "Copying ${NEWEST}"
    cp -p "${NEWEST}" "${DEST}"
fi

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Move folders containing certain files

Hello, How can I move just the folders that contains files modified n days ago? Source tree: |-- SourceFolder | |-- Subfolder1 | | |-- file1.dat | | `-- file2.dat | |-- Subfolder2 | | |-- filea.dat | | `-- fileb.dat Destination tree: |-- ... (3 Replies)
Discussion started by: xavix
3 Replies

2. Shell Programming and Scripting

Move files to Folders

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)
Discussion started by: diva_thilak
5 Replies

3. Shell Programming and Scripting

Find file that matches today's date in filename and move to /tmp in bash

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)
Discussion started by: jamesi
1 Replies

4. Shell Programming and Scripting

How to find a word and move it a specific location in xml file using perl?

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)
Discussion started by: harpal singh
3 Replies

5. Shell Programming and Scripting

Bash to download specific files and save in two folders

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)
Discussion started by: cmccabe
7 Replies

6. Shell Programming and Scripting

Move specific folders and subfolders in a directory

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)
Discussion started by: cmccabe
6 Replies

7. Shell Programming and Scripting

Move multiple files 4rm Source to different target folders based on a series num in the file content

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)
Discussion started by: phani333
17 Replies

8. Shell Programming and Scripting

How can i move folders and its content if folder is older than 1,5 days and keep subdirs in bash?

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)
Discussion started by: ZerO13
1 Replies

9. UNIX for Advanced & Expert Users

Find files in specific folders

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)
Discussion started by: JackJinu
4 Replies

10. Shell Programming and Scripting

Bash to move specific files to directory based on match to file

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)
Discussion started by: cmccabe
4 Replies
FBAUTOSTART(1)							fbautostart Manual						    FBAUTOSTART(1)

NAME
fbautostart - Autostart all XDG applications SYNOPSIS
fbautostart [options] DESCRIPTION
fbautostart(1) is an XDG complaint startup tool. This will go through the directories set up by the spec, and start all applications that match it's current identifier. You may change that identifier with the FBXDG_DE env var. This tool has almost no library dependencies and was written to be smart about that sort of stuff. There is a greater then average chance that you will find a bug, since it is a from-scratch implementation of the .desktop spec. Pleas report bugs. Please. FILES
~/.config/autostart This folder contains the default user XDG dot-desktop files that will be run ( unless it's overridden by an ENV variable ) /etc/xdg This folder contains the default system XDG dot-desktop files that will be run ( unless it's overridden by an ENV variable ) OPTIONS
Sadly, there are no flags in this particular release. ENVIRONMENT VARIABLES
XDG_CONFIG_HOME The XDG root directory for the user's startup files, which may override the global startup files. XDG_CONFIG_DIRS The root XDG directory, where global XDG files are maintained. FBXDG_DE Development environment that we should act upon. This defaults to "FLUXBOX", since this is a fluxbox project, after all. Please note this is case sensitive. FBXDG_EXEC This dictates if we should execute the application that we've been told to or not. This is particularly useful for debugging the app. HOME The location of one's home directory, such that ~/ will be expanded to /home/user/ EXAMPLE
fbautostart AUTHORS
Paul Tagliamonte <paultag@ubuntu.com[1]> for fbautostart 2.718281 SEE ALSO
fluxbox(1) AUTHOR
Paul Tagliamonte <paultag@ubuntu.com> Author. NOTES
1. paultag@ubuntu.com mailto:paultag@ubuntu.com fbautostart.txt 7th September 2011 FBAUTOSTART(1)
All times are GMT -4. The time now is 03:10 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy