LinuxQuestions.org
Help answer threads with 0 replies.
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 09-29-2013, 10:50 PM   #1
kilee
LQ Newbie
 
Registered: Nov 2009
Posts: 22

Rep: Reputation: 0
Creating Batch Folders


Hi
I've merged tons of files from different backups with rsync. (found how to do it with help from great people around here.
Now I'd like to split all these files into folders depending on the extension.
All gifs in one folder, all .doc in another folder an so on.
All files are in a hdd1, so I want to move them to another hdd2.
So the idea is moving every single document in hdd1 to hdd2/"extension folder"

Is it possible to do something like this?
I've tried using a mac program named the big mean folder machine, but it just hangs for days.

THe program is this: http://www.publicspace.net/BigMeanFolderMachine/ and I'd like to find a way to doit with linux.

Thanks for your help.
 
Old 09-30-2013, 12:39 AM   #2
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,753

Rep: Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288
Hi,

there are a bunch of ways to do this. Here is a simple one to give you an idea
Code:
dirs=$(echo /path/to/hdd1/*.* |tr ' ' '\n' | cut -f2 -d'.' | sort | uniq)
for d in $dirs ; do
  mkdir /path/to/hdd2/$d
  mv /path/to/hdd1/*.${d} /path/to/hdd2/$d/
done
To understand this you need to understand about piping commands and you need to know the cut, sort, uniq, mkdir and mv commands. It would be a good idea to read some "introduction to bash scripting" type tutorials.

You'll need to use the correct paths for your source and destination files and note that the above little bit of code this expects filenames to have at most on "." in them.

Hope this helps to get you started.

Evo2.

PS. The above is of course untested.
 
  


Reply

Tags
backup, folders, move


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
creating folders and permissions SGID TechJay Linux - Newbie 4 03-05-2013 02:37 AM
creating a batch file barathan Linux - Newbie 6 06-14-2012 06:53 PM
Can you verify my syntax for creating multiple users in a batch file? grayceworks Linux - Newbie 5 03-03-2011 03:04 AM
Creating Folders JJV Linux - Newbie 7 02-21-2008 10:44 AM
Creating Batch Commands? reefadt Linux - Newbie 3 08-17-2003 10:46 AM


All times are GMT -5. The time now is 09:21 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