Did you know LQ has a Linux Hardware Compatibility List?
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


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

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


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


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,


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

Rep: Reputation: 847Reputation: 847Reputation: 847Reputation: 847Reputation: 847Reputation: 847Reputation: 847
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:

for DIR in `ls -d invoice*`
do cp -p $DIR/* .
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, 06:59 PM   #3
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.



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

All times are GMT -5. The time now is 11:46 AM.

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