LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 07-22-2013, 08:12 AM   #1
jdepp
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, 01:33 PM   #2
jdepp
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, 02:27 PM   #3
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian Jessie / sid
Posts: 1,471

Rep: Reputation: 444Reputation: 444Reputation: 444Reputation: 444Reputation: 444
Quote:
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'

Code:
find . -name "*datareader_F*" -exec mv "{}" /mnt/data1/sqlbackup/DataFiles/RawFiles/DataReaderFRaw/ \;
you might also like to limit to -type f ( type is file )
Code:
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

Code:
#!/bin/bash
# sqlbackup.sh
File=$1
BackupDir=$2
Dir=$(dirname $File)
BackupDir=${BackupDir}/${Dir}

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


Reply


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 03:37 PM
Help with sorting folders ncube22 Linux - Newbie 5 12-19-2012 01:43 PM
[SOLVED] Moving files from folders and subfolders to a specific folder mrj2 Linux - Newbie 12 08-22-2010 01:40 PM
moving files and folders thru command line JROCK1980 Linux - General 2 02-16-2004 07:55 PM
Sorting mail into folders? cli_man Linux - Software 4 11-07-2003 11:20 AM


All times are GMT -5. The time now is 12:50 PM.

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