Fllatten directory tree


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Fllatten directory tree
# 1  
Old 02-03-2009
Fllatten directory tree

Hi there,

I have a filestore that is just two levels:

dir/
file1
file2
file3
...
subdir1/
file4
file5
file6
subdir2/
file7
file8
file9
...

I am looking for acommand or scrip that will flatteb this tree and copy all the files into a single directory:

newdir/
file1
file2
file3
file4
file5
file6
file7
file8
file9

Could anybody please help? Thanks.
# 2  
Old 02-03-2009
A Script?

Code:
man mkdir
man mv
man rm

# 3  
Old 02-03-2009
?????
# 4  
Old 02-03-2009
For the steps you listed, you don't need a script, usually. Just use the commands I've listed to create the dir, mv the files from the old dirs and remove the then empty dirs. Or is there something more behind it?
# 5  
Old 02-03-2009
No that's fine, thanks. Except that there are aabout 250 subdirectories and about 3500 files in total. I could do the above but it would take some time. I was knd of thinking there may be a way to automate it.

Cheers,
# 6  
Old 02-03-2009
Code:
find /tedirabove -type f -exec mv {} /newdir \;

For deleting the then empty directories you can use the same above, changing f vs d for directories and mv against rm -r.

Maybe try it 1st with -print instead of -exec if you get the files you want to move.

Remember, that if there are different files with the same name, they will be overwritten in /newdir of course.
# 7  
Old 02-03-2009
Many, MANY thanks!
L
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

To do directory tree search

Hello Everyone, I need to find the file / directory with the maximum timestamp in a directory tree having many files / directories. Could you please help. Thanks, H squared (3 Replies)
Discussion started by: H squared
3 Replies

2. Shell Programming and Scripting

Specific directory parsing in a directory tree

Hi friends, Hello again :) i got stuck in problem. Is there any way to get a special directory from directory tree? Here is my problm.." Suppose i have one fix directory structure "/abc/xyz/pqr/"(this will be fix).Under this directory structure i have some other directory and... (6 Replies)
Discussion started by: harpal singh
6 Replies

3. UNIX for Dummies Questions & Answers

How to copy a tree of directory

Mi question is how can you copy only de three of directory and not the files in it. Only a need the three of directorys not the files (6 Replies)
Discussion started by: enkei17
6 Replies

4. UNIX for Dummies Questions & Answers

directory tree with directory size

find . -type d -print 2>/dev/null|awk '!/\.$/ {for (i=1;i<NF;i++){d=length($i);if ( d < 5 && i != 1 )d=5;printf("%"d"s","|")}print "---"$NF}' FS='/' Can someone explain how this works..?? How can i add directory size to be listed in the above command's output..?? (1 Reply)
Discussion started by: vikram3.r
1 Replies

5. Shell Programming and Scripting

creating a directory tree

Hi all, I'd like to create a directory tree, and define from stdin how many levels deep and how many directories in each level should be created. What I wrote does not work properly:#!/bin/bash #set -x read -p " What root directory? " rootDir && { /bin/rm -R $rootDir; mkdir $rootDir; } ||... (2 Replies)
Discussion started by: NBaH
2 Replies

6. UNIX for Dummies Questions & Answers

Move all files in a directory tree to a signal directory?

Is this possible? Let me know If I need specify further on what I am trying to do- I just want to spare you the boring details of my personal file management. Thanks in advance- Brian- (2 Replies)
Discussion started by: briandanielz
2 Replies

7. UNIX for Dummies Questions & Answers

Protecting the directory tree

Hello, I am hoping someone maybe able to help me. I have set up an Apache web server on my sun server with user accounts in the main htdocs directory. My question is how to stop these users searching up the directory tree when they ftp/telnet to the server. Also is it possible to restrict the... (2 Replies)
Discussion started by: rooneyl
2 Replies

8. Shell Programming and Scripting

directory tree

Hi all, The following is a script for displaying directory tree. D=${1:-`pwd`} (cd $D; pwd) find $D -type d -print | sort | sed -e "s,^$D,,"\ -e "/^$/d"\ -e "s,*/\(*\)$,\:-----\1,"\ -e "s,*/,: ,g" | more exit 0 I am trying to understand the above script.But... (3 Replies)
Discussion started by: ravi raj kumar
3 Replies

9. Programming

directory as tree

hi i have modified a program to display directory entries recursively in a tree like form i need an output with the following guidelines: the prog displays the contents of the directory the directory contents are sorted before printing so that directories come before regular files if an entry... (2 Replies)
Discussion started by: anything2
2 Replies

10. Programming

Directory tree search???

Hi all, I've got a problem, what function do i use to list the contents of all the directory tree (simular to "find")? Any other suggestions? Thank you all (3 Replies)
Discussion started by: solvman
3 Replies
Login or Register to Ask a Question