I need a hint for reading manpage (I did rtfm really) of cpio to do this task as in the headline described. I want to put all files of a certain type, lets say all *.txt files or any other format. Spread in more than hundreds of subdirectories in one directory I would like to select them and just move, copy them all in one directory. As using the following comand it gets me some trouble, may someone could give me a hint.
which would create hardlinks to all the files in the target directory. Use the -s option of man ln (linux) if the target directory is in a different filesystem.
If you need to make a copy of the files:
TMPDIR=$(mktemp -d)
trap "rm -f ${TMPDIR}" EXIT
find /.../sourcedir -type f -name '*.txt' -print0 | xargs -0 ln -s -t ${TMPDIR}
cd ${TMPDIR}
ls -1fA | cpio -pLvum /.../targetdir
Be advised that nothing is being done for filename collisions.
You also specified find /path/to/folder .*.txt . The -name option is missing, and use single-quotes. Otherwise the shell globbing expansion may give you a surprise.
No. Always use the quotes for every -name or -iname primary operand. (You can get by without it under certain circumstances and with the lack of files matching a pattern in your current working directory; but when you try the same script later after some files have been added or when you run it in a different directory, your script with stop working. Even when the quotes aren't required, adding them will never cause you a problem.)