copying all files except those with certain extension

Hi,

I have a root directory which has a big number of other subdirectories and contains a big number of files. I want to copy all these files and directories to another folder except files with certain extension, say .txt, files - how may I do this?

Thanks,

faizlo

this will list all the files which don't have .txt extention...

then you can use cpio command to copy them...
go through the man page...

Thanks vidyadhar85,

But cpio is for archived files. I just want to copy all files and folders from source to destination, keeping the oder, without files with extension .exe, say. I do have some tar files in the source directory but I want to copy them as they are.

faizlo

cpio can copy as well, e.g.

find / \( ! -name "*.txt" \) -type f | cpio -vdump /path/to/destination

Thanks for this thread and for this forum. I loved it the first time I browsed it.
I tried Annihilannic reply and it worked like a charm. I tried to do this, but it did not work:

find /some/work/area/ \( ! -name "*.txt" \) -type f | scp user@www.domain.com:/home/user/some_folder

It did not work. I think I am missing an option or something, is there a solution for this situation?

eager

That doesn't work because scp does not accept a list of filenames from standard input.

To copy the files to another system it's better to convert the files into a stream format of some kind, such as a cpio or tar archive, pipe them through an ssh connection, and then extract them from the stream at the other end, e.g.

cd /some/work/area/ && find . \( ! -name "*.txt" \) -type f | cpio -o | ssh user@www.domain.com 'cd /home/user/some_folder && cpio -ivdm'

Note that I used cd to change into the respective directories so that the paths stored in the cpio archive are relative, not full paths.

Thank you man, it really worked like a charm!
I have another question for all you people here: How can one know all that about computers!?

eager

I had an error message with some files that said: truncating inode number, so I tried to add an option to cpio to be cpio -oc, the error disappeared.

eager

I've been playing with them for 23 years and I'm still learning. :o