Copy files from subdir


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Copy files from subdir
# 1  
Old 07-04-2011
Copy files from subdir

Hey,

How can I copy files from subdirectories without copy the subdir
and copy it to a higher dir

For example:

/home/test/subdir/file1

copy file1 to /home or another dir

thanx
# 2  
Old 07-04-2011
unless I'm missing something

Code:
cp /home/test/subdir/file1 /home

will do what you want
# 3  
Old 07-04-2011
Code:
cp /home/test/subdir/* /home/

Code:
find /home/test/subdir -type f -prune -exec cp {} /home/ \;

# 4  
Old 07-04-2011
I mean for different files starting with file*

---------- Post updated at 04:30 PM ---------- Previous update was at 04:14 PM ----------

for example

/home/user/test1/subdir1/file1
/home/user/test2/subdir2/file2

I want to copy file1 & 2

when I'm in /home/user/ and copy them in home/user/lala
# 5  
Old 07-04-2011
Code:
cp /home/user/test1/subdir1/file1 /home/user/test2/subdir2/file2 ./lala/

---------- Post updated at 04:34 PM ---------- Previous update was at 04:33 PM ----------

Less restrictive :
Code:
cp /home/user/test?/subdir?/file? ./lala/

# 6  
Old 07-04-2011
but i haven't always subdirs Smilie
# 7  
Old 07-04-2011
I am afraid, we need more info about how does your tree structure look like and which files you are willing to move or not.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Echoing only once for each subdir

I have a script that runs from this: for i in * ; do (cd $i && echo $i && /test1/execute/testb);done this is testb: for file in `ls *.txt` do if && && && && && ; then echo "NO"; break 1; else echo "it is there" fi done What is happening is that I can get it to run a... (19 Replies)
Discussion started by: newbie2010
19 Replies

2. UNIX for Dummies Questions & Answers

copying the dir/subdir structure from one server to another?

Hi All, I want to copy the dir/subdir structure from SERVER-A to SERVER-B without copying all the files in each dir. Is it possible using SCP / SFTP command? For example, SERVER-A has following two dir/subdirectories and files under each subdir. ... (1 Reply)
Discussion started by: Hangman2
1 Replies

3. Shell Programming and Scripting

Move all files from dir and subdir to Archive with File name as complete path_filename

HI, I need to move all files from a dir & its all subdir to Archive folder which is indise dir only. and moved filename should changed to complete path ( Like Dir_subdir_subdir2_.._filename ). also all files names shoud capture in a file in order to mail I written below code ... (11 Replies)
Discussion started by: minijain7
11 Replies

4. Shell Programming and Scripting

Help - Script to move files to subdir depending on file extension.

Hi, First off I'm pretty new to scripting so please be gentle. I am looking for some help with a script that will move all files with a certain extension into a folder within their current location. Just for clarity I have all my photos organised in directories such as: ... (4 Replies)
Discussion started by: guinch
4 Replies

5. Shell Programming and Scripting

replace string in multiple files, dir and subdir

Hello, I have a directory www with multiple directories. Every directory has site name with .htm, .html, .php files or sub directories with .htm, .php, .html file as example - www - sitename 1 - site 1 - sitename 2 - sitename 3 What I'm looking for is a... (7 Replies)
Discussion started by: andyjill
7 Replies

6. Shell Programming and Scripting

moving dir subdir and files

I have created a directory structure and under the directory subdirectories and files are there.I need to move the entire thing to another path.How can i write a script to do that. currently the path of files is as below : /data1/serial/mcycle/archive : under this path differnt sub dir exist ... (6 Replies)
Discussion started by: dr46014
6 Replies

7. Shell Programming and Scripting

Grep in subdir, multiple files

Hi, I m trying to have script to grep a pattern in all files under a directory. I use Sun Solaris, the below want doesnt do exactly what I want. find /home/xxx/ tagHeu | while read FILE; do grep text $FILE && echo 1 grep text $FILE || echo 0 done I also tried running: find... (2 Replies)
Discussion started by: s3rro
2 Replies

8. Shell Programming and Scripting

move files and retain subdir structure

hi: I have some files like this folder1/recording1.mp3 folder1/docs/budget.doc folder2/others/misc.mp3 folder3/others/notes.doc all this folders and files are under the mp3 folder. I would like to move just the mp3s to another folder but retain the subdir structure i have. So if... (4 Replies)
Discussion started by: jason7
4 Replies

9. Shell Programming and Scripting

"find command" to find the files in the current directories but not in the "subdir"

Dear friends, please tell me how to find the files which are existing in the current directory, but it sholud not search in the sub directories.. it is like this, current directory contains file1, file2, file3, dir1, dir2 and dir1 conatins file4, file5 and dir2 contains file6,... (9 Replies)
Discussion started by: swamymns
9 Replies

10. Shell Programming and Scripting

Finding patterns through out all subdir

Hi all experts, here is a problem which i would appreciate ur expertise. I need to do this: Eg. Find a number: 1234567 which i dunno which file and which folder I do know which main folder it is in but it is hidden deep within a lot of subdir. Is it possible to find the file? + output... (4 Replies)
Discussion started by: unnerdy
4 Replies
Login or Register to Ask a Question