ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
This will will search for any file called "/home/user/test". There will be only one file found: /home/user/test.
So you could expect the the file containing the list of file ("list.txt") would be truncate to zero-length! But you were lucky this did not happen, because of another error:
When redirecting to {} , the -exec option does not replace {} with the files found by "find". So /dev/null is catted to a file called "{}". I bet you have a an empty file now in your directory called "{}".
Code:
xargs -i cat /dev/null > {}
The same problem here with redirecting to {}.
Also, "xargs" will put as many arguments from its standard input (stdin) as possible. So the command actually executed will be something like:
Code:
cat /dev/null > file1 file2 file3 file4
...which isn't what you were expecting.
Sorry to ask the question again, actually, I noticed something in Hko's reply which I didn;t before.
Hko, you are right I do see file '{}' in my directory.
But, then why does the command
Code:
find ./ -type f -exec less {} \;
works fine. Also in man find, they actually do say that {} is replaced by the name of the files found in the directory from which you run the find command.
???
Last edited by kushalkoolwal; 01-26-2006 at 07:28 PM.
works fine. Also in man find, they actually do say that {} is replaced by the name of the files found in the directory from which you run the find command.
This is because of a limit of the "-exec" option of "find": "find" doesn't do the replacement after a '>'. The redirecting to a file is done before replacing '{}'.
So you could do:
Code:
find ./ -type f -exec cat {} > /dev/null \;
# '{}' before '>'
But not:
Code:
find ./ -type f -exec cat /dev/null > {} \;
# '{}' after '>'
There may be a "hack" to do it work around it. But I don't know off any.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.