Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 07-22-2013, 07:12 AM   #1
LQ Newbie
Registered: Mar 2013
Posts: 12

Rep: Reputation: Disabled
sorting through folders and moving files

I have an archive server I need to cleanup. Basically it consists of millions of folders with subfolders and tons of files. I had a script in windows visual studio that was attempting to scan through these folders but with some folders it cannot even access because of the number of files within that folder. I thought of changing the script to use mono tools so it can run on linux but not sure if thats worth the effort. Is there anyway to manually do this on the linux server?

for any files that name.contain "datareader_F"
move to this folder
elseif any files that name.contains "DataWriter"
move to this folder

I am still new to linux so forgive me if this question is out of scope here.
Old 07-22-2013, 12:33 PM   #2
LQ Newbie
Registered: Mar 2013
Posts: 12

Original Poster
Rep: Reputation: Disabled
find . -name "datareader_F*" -exec mv "{}" /mnt/data1/sqlbackup/DataFiles/RawFiles/DataReaderFRaw \;
Old 07-22-2013, 01:27 PM   #3
Senior Member
Registered: Oct 2008
Distribution: Debian Jessie / sid
Posts: 1,471

Rep: Reputation: 444Reputation: 444Reputation: 444Reputation: 444Reputation: 444
Originally Posted by jdepp View Post
find . -name "datareader_F*" -exec mv "{}" /mnt/data1/sqlbackup/DataFiles/RawFiles/DataReaderFRaw \;
yes, that will do it
Well nearly, you described the criteria as 'contains', your find is 'starts with'

find . -name "*datareader_F*" -exec mv "{}" /mnt/data1/sqlbackup/DataFiles/RawFiles/DataReaderFRaw/ \;
you might also like to limit to -type f ( type is file )
find . -type f -name "*datareader_F*" -exec mv "{}" /mnt/data1/sqlbackup/DataFiles/RawFiles/DataReaderFRaw \;
But you do have a couple of drawbacks with this,
You will not be preserving the directory structure
You will overwrite files with duplicate named files ( same name but were in different directory )

depending on what you need, it might be better to write a small script to create the needed directories, and move to those

Dir=$(dirname $File)

mkdir -p ${BackupDir}
mv $File ${BackupDir}/
So now your find
find . -type f -name "*datareader_F*" -exec bash /path/to/ {} /mnt/data1/sqlbackup/DataFiles/RawFiles/DataReaderFRaw \;
But I might have over complicated it


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Moving files between Folders in Remote directory Saratha Linux - Newbie 5 03-29-2013 02:37 PM
Help with sorting folders ncube22 Linux - Newbie 5 12-19-2012 12:43 PM
[SOLVED] Moving files from folders and subfolders to a specific folder mrj2 Linux - Newbie 12 08-22-2010 12:40 PM
moving files and folders thru command line JROCK1980 Linux - General 2 02-16-2004 06:55 PM
Sorting mail into folders? cli_man Linux - Software 4 11-07-2003 10:20 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:47 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration