LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 08-05-2010, 02:00 AM   #1
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,088

Rep: Reputation: 45
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.

Last edited by stf92; 08-05-2010 at 02:10 AM.
 
Old 08-05-2010, 02:20 AM   #2
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,695
Blog Entries: 5

Rep: Reputation: 241Reputation: 241Reputation: 241
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
 
Old 08-05-2010, 02:31 AM   #3
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,088

Original Poster
Rep: Reputation: 45
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.
 
Old 08-05-2010, 02:40 AM   #4
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,695
Blog Entries: 5

Rep: Reputation: 241Reputation: 241Reputation: 241
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.
 
1 members found this post helpful.
Old 08-05-2010, 02:50 AM   #5
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,088

Original Poster
Rep: Reputation: 45
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.
 
Old 08-05-2010, 07:42 AM   #6
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713
Quote:
Originally Posted by stf92 View Post
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.
 
1 members found this post helpful.
Old 08-06-2010, 05:23 AM   #7
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,088

Original Poster
Rep: Reputation: 45
Thank you very much. Regards.
 
  


Reply

Tags
args, ls


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
A doubt about -print0 GNUism in find and other utilities crisostomo_enrico Solaris / OpenSolaris 6 08-05-2007 01:22 PM
LXer: Using 'ls' and 'xargs' to manage large numbers of files LXer Syndicated Linux News 0 02-15-2007 06:16 AM
File name expansion with {} in gnu find and xargs anamericanjoe Linux - Software 2 09-16-2006 03:31 PM
backup file *.htm --> * .htm.bak rvoigt Linux - General 4 06-25-2005 04:39 PM
error with find . | xargs cbonar Linux - Newbie 7 12-09-2004 11:22 AM


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

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration