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
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
unless I'm missing something
cp /home/test/subdir/file1 /home
will do what you want
cp /home/test/subdir/* /home/
find /home/test/subdir -type f -prune -exec cp {} /home/ \;
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
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 :
cp /home/user/test?/subdir?/file? ./lala/
but i haven't always subdirs
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.
ok,
/home/user/dir1/subdir1/file1
/homer/user/dir2/file2
/home/user/file3
copy these files to /home/user/lala
---------- Post updated at 05:04 PM ---------- Previous update was at 05:00 PM ----------
ok,
/home/user/dir1/subdir1/file1
/home/user/dir1/subdir2/file2
home/user/dir2/subdir35/file3
home/user/file45
copy these files 'starting with file' to home/user/lala
ksh
cd /home/user
find /home/user -type f -name "file*" | while read f
do
echo cp $f /user/lala/${f##*/}
done
Try this, if it displays what you expect, then remove the "echo" so the "cp" command will apply for real
The echo is fine
but when i try to copy it gives me an error:
He says that he can't make the normal file because it doesn't exists
But it does ...
You mean when you run the following :
ksh
cd /home/user
find /home/user -type f -name "file*" | while read f do
cp $f /user/lala/${f##*/}
done
You get some error message ?
could you please copy/paste the message you get ?
Could you please also paste the result you get when running the following 2 commands :
find /home/user -type f -name "file*" -ls
ls -ld /user/lala
It's ok i gave the wrong destination directory sorry!
It works now thanks