Welcome to the most active Linux Forum on the web.
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 09-29-2013, 10:50 PM   #1
LQ Newbie
Registered: Nov 2009
Posts: 22

Rep: Reputation: 0
Creating Batch Folders

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: and I'd like to find a way to doit with linux.

Thanks for your help.
Old 09-30-2013, 12:39 AM   #2
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

there are a bunch of ways to do this. Here is a simple one to give you an idea
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/
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.


PS. The above is of course untested.


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 > Forums > Linux Forums > Linux - Newbie

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