LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   xargs undesired behaviour. (https://www.linuxquestions.org/questions/linux-software-2/xargs-undesired-behaviour-824286/)

stf92 08-05-2010 02:00 AM

xargs undesired behaviour.
 
Kernel 2.6.21.5, GNU (Slackware 12.0).
find 4.2.31
xargs 4.2.31
ls 6.9
bash 3.1.17

Hi:
Code:

find . -name *.htm* -print0|xargs -0 ls
outputs file name f2.

Clearly, '*.htm*' can't be matched by 'f2'. In the dir I'm running the command in, find does not find any matching file. In turn, then, xargs delivers 0 arguments to ls which makes ls to output the whole directory listing. But the intended command purpose I think is evident. I only need to rule out the particular case just described. Any suggestions? Regards.

ghostdog74 08-05-2010 02:20 AM

what exactly are you trying to do? I am sure you are not just printing the listing out right?
if that's the case, the -ls switch will do
Code:

find . -iname "*htm" -ls

stf92 08-05-2010 02:31 AM

Thanks for your reply. I think this will describe it:
Quote:

I want to search an entire subtree of /, in the file system, for all files, with extension html, created on the hard disk. In addition, these have to be the last five created.

I think I could split the problem into two parts: (a) Forget about the last condition. Then this is a job for the find command. (b) Sort the output of find using the date as the key, then use 'head' to print the desired output.

But even two such simple steps are enough to justify the writing of a shell script. And here lies my weakness. My script writing knowledge is rudimentary.

What's the final purpose? Well, I lately saved four or five LQ pages onto disk containing information I consider valuable to me. But I don't exactly remember where on the disk. So...

Then: either the problem posed is really of a very simple nature or it is not, in the latter case a script being mandatory. Any suggestion will be welcome. Thank you for reading.

EDIT: one of the algorithm drawbacks (the one described above) is that find may be running a great deal of time. My machine resources (RAM and CPU speed are low) are scarce and there possible are a large number of HTML files on the disk.
I see you've added an action to the find command. If the subtree in question is small enough then the command will terminate execution after a few minutes [but what command?]. Regards.

ghostdog74 08-05-2010 02:40 AM

Code:

find . -printf "%TH%TM%TS:%p\n" | sort -n | tail -5
check the find man page for what those printf specifiers mean. Of course that's just an example. Tweak it according to your wish.

stf92 08-05-2010 02:50 AM

Yes. After receiving post #2 I limited myself to describe the scenario but I did not do any thinking. But after sending #3 I saw find was enough to do the main job. Now I'll play a little under the guidelines given by you. Thanks a lot.

MTK358 08-05-2010 07:42 AM

Quote:

Originally Posted by stf92 (Post 4056416)
Code:

find . -name *.htm*

You want to enclose the wildcard in quotes, so they will be passed to find instead of being interpreted by bash.

stf92 08-06-2010 05:23 AM

Thank you very much. Regards.


All times are GMT -5. The time now is 05:12 AM.