File name expansion with {} in gnu find and xargs
I was thinking about suggesting a second possible solution to a problem posted at http://www.linuxquestions.org/questi...d.php?t=483730 when I discovered a problem of my own.
I believe that it is possible to use find to traverse a file system, select only certain types of files (such as *.txt files) and copy those files to one central location. I thought that gnu find would do the trick -- maybe piped to xargs if necessary (although I see no reason why I couldn't just use the exec flag...) I ran into problems with I realized that I needed to place the name of the file find was currently proccessing in the middle of a command, as in: Code:
find . -type f -name '*.txt' -exec cp current_file_name /tmp \; Quote:
Code:
find . -type f -name '*.txt' -exec cp {} /tmp \; Code:
find . -type f -name '*.txt' -exec cp '{}' /tmp \; Code:
find . -type f -name '*.txt' -exec cp \{\} /tmp \; Code:
cp {} /tmp path/to/current_file_name |
I'm not having any trouble. In the following example I execute an ls command in the current directory. In that directory the backup, experiment, and testdisk-6.5-WIP listings are directories. The fix.file.permissions.sh listing is a regular file.
Code:
$ cd bin When I'm using the find command with the -name option I never use single or double quotes. I have found that the behavior of the find command seems to vary from one specific situation to the next when using -name '*' type parameters. Instead of using the quotes I use the \ escape character. So where you entered Code:
find . -type f -name '*.txt' -exec cp {} /tmp \; Code:
find . -type f -name \*.txt -exec cp {} /tmp \; |
OK, I think I know what I was doing wrong.
My find has an option similar to -exec: -ok. The man page says: Quote:
The output of the -ok command really threw me off. The -exec flag works exactly as it should. |
All times are GMT -5. The time now is 01:48 AM. |