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 01-25-2012, 12:24 PM   #1
sjaak538
LQ Newbie
 
Registered: Jan 2012
Posts: 3

Rep: Reputation: Disabled
moving many dirs /dir1/samenamedir1/files 1 level up


Hi

After many google searching can't find a solution.

I have many dirs like :

/root/john/john/files
/root/jim/jim/files
/root/harry/harry/files

/root/dira/dirb/files



I like to move up the files 1 level to dira and delete the dirb.

dira does not allways have the same name as dirb.

I'm getting crazy.
Must be possible with bash script or....

Thks

Last edited by sjaak538; 01-25-2012 at 03:40 PM. Reason: forget the thanks
 
Old 01-25-2012, 12:36 PM   #2
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4853Reputation: 4853Reputation: 4853Reputation: 4853Reputation: 4853Reputation: 4853Reputation: 4853Reputation: 4853Reputation: 4853Reputation: 4853Reputation: 4853
Code:
mv /dir1/dir2/* /dir1/
rm -r /dir1/dir2
For more info on those commands try
Code:
man mv
man rm
 
Old 01-25-2012, 03:36 PM   #3
sjaak538
LQ Newbie
 
Registered: Jan 2012
Posts: 3

Original Poster
Rep: Reputation: Disabled
Yes I know this but i dont like to do it for :
`ls -l|wc -l` = 1870
 
Old 01-25-2012, 06:02 PM   #4
sjaak538
LQ Newbie
 
Registered: Jan 2012
Posts: 3

Original Poster
Rep: Reputation: Disabled
Got it
Maybe not elegant but is works fine
Thanks


#!/bin/sh

find . -name *.html|cut -f2,3 -d/|sort|uniq > filelist
while read A
do

DIR1=`echo $A| cut -f1 -d/`
DIR2=`echo $A| cut -f2 -d/`

mv /tera3/http/"$DIR1"/"$DIR2"/* /tera3/http/"$DIR1"/
rmdir /tera3/http/"$DIR1"/"$DIR2"/
done < filelist

Quote:
No warranty for anyone !! :-)

Last edited by sjaak538; 01-25-2012 at 06:03 PM.
 
  


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
[SOLVED] Apple gcc: Insert include dirs between -I dirs and -isysroot dirs f.barker Programming 1 11-11-2011 11:19 AM
proftpd problem: files are not readable, files show as dirs Altvod Linux - Server 0 06-23-2011 06:59 AM
copy only new files from dir1 to dir2 using c++ on Linux miamagoo Programming 23 08-18-2010 12:00 PM
cp -al dir1/ dir2/ but skip some dir1/subdir Meson Linux - General 1 09-28-2008 02:39 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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