LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-02-2016, 05:40 AM   #1
llee4131
LQ Newbie
 
Registered: Sep 2006
Posts: 5

Rep: Reputation: 0
Xargs problem


I have no files on my current directory and three sub directories.

If I do
find . -maxdepth 0 -type f
predictably there is no output since there are no files.

But if I do
find . -maxdepth 0 -type f | xargs ls -isl
this produces list of the three sub directories.

I clearly stated -type f so why is this listing the sub directories?
 
Old 05-02-2016, 06:05 AM   #2
wpeckham
LQ Guru
 
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, VSIDO, tinycore, Q4OS,Manjaro
Posts: 5,623

Rep: Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695
Things do exactly what they are designed to. darn it!

Since the find is generating an empty list, xargs receives the empty list and runs the ls against it. Think: what does the ls command return if run in that folder without additional parameters?
 
1 members found this post helpful.
Old 05-02-2016, 06:16 AM   #3
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 21 MATE
Posts: 8,048
Blog Entries: 5

Rep: Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925
find . -maxdepth 0 -type f | xargs -r ls -isl

-r: If the standard input does not contain any nonblanks, do not run the command.
 
Old 05-02-2016, 06:21 AM   #4
llee4131
LQ Newbie
 
Registered: Sep 2006
Posts: 5

Original Poster
Rep: Reputation: 0
nice!
 
Old 05-02-2016, 07:04 AM   #5
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,307
Blog Entries: 3

Rep: Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721
Quote:
Originally Posted by wpeckham View Post
Since the find is generating an empty list, xargs receives the empty list and runs the ls against it. Think: what does the ls command return if run in that folder without additional parameters?
You can see this more clearly if you run xargs a few times with the -t option using different input.
 
1 members found this post helpful.
Old 05-02-2016, 07:11 AM   #6
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,791

Rep: Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201
Like xargs -r but safer regarding special characters in filenames is
Code:
find . -maxdepth 1 -type f -exec ls -isl {} +
 
  


Reply



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
[SOLVED] Secure remove (srm) every log file excluding a certain directory, xargs problem... archh Linux - Security 1 09-30-2014 09:05 AM
xargs: unmatched single quote; by default quotes are special to xargs unless you use Raakh5 Linux - Newbie 7 05-21-2014 07:26 PM
Problem using sed with variable created using xargs - unterminated error wrankin Programming 5 11-14-2011 07:53 PM
[SOLVED] xargs problem... adrian89 Linux - Newbie 4 06-17-2011 04:50 PM
xargs yawe_frek Linux - Software 1 04-15-2007 04:26 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:21 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration