LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-21-2007, 03:48 PM   #1
Marinus
LQ Newbie
 
Registered: Aug 2005
Distribution: Debian Etch
Posts: 20

Rep: Reputation: 0
Move files from several subdirectories one level back


Hi,

I hope you can help me with this issue. I'm trying to move a lot of files, currently located in numbered subdirectories, one level back. The subdirectories are named as

../invoices/invoice00001/
../invoices/invoice00002/
etc.

They all contain one file (invoicexxxxx.odt).
And all these files should all go to the folder directly above those directories, '/invoices/.

Is it possible to do that via a shell script? To do it manually would take me probably all day!

Thanks for any help,

Marinus.

Last edited by Marinus; 01-21-2007 at 05:14 PM.
 
Old 01-21-2007, 05:32 PM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
Easy to do but not sure if you mean you want to move the files in invoice001 and invoice002 to invoices or if you mean invoices/invoice001 and invoices/invoice002 to the directory above invoices. Process is the same but off course details are different.

So within the directory invoices:

Code:
for DIR in `ls -d invoice*`
do cp -p $DIR/* .
done
The above would copy find invoice001, invoice002 etc... can copy all contents to the current directory (. = current directory) which is invoices.

If you want to go to the parent directory above invoices just use .. instead of . (.. = parent directory of current directory).
 
1 members found this post helpful.
Old 01-21-2007, 05:59 PM   #3
Marinus
LQ Newbie
 
Registered: Aug 2005
Distribution: Debian Etch
Posts: 20

Original Poster
Rep: Reputation: 0
Hi J.,

that's exactly what I was looking for!
Thanks very much.

Marinus.
 
  


Reply



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
emacs in run level 3 then switch to X (level 7) then back to level 3 dsoliver Slackware 3 09-01-2006 03:31 AM
LXer: Red Hat Again Tries to Move Beyond OS Level LXer Syndicated Linux News 0 04-17-2006 09:21 PM
loop move files up one directory level Melsync Programming 8 12-19-2005 10:51 PM
move files in tar.gz back to into original folders GUIPenguin Linux - General 1 05-09-2005 12:11 PM
move files to a series of subdirectories acid2000 Linux - General 1 09-01-2003 05:44 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:33 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
Open Source Consulting | Domain Registration