LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > antiX / MX Linux
User Name
Password
antiX / MX Linux This forum is for the discussion of antiX and MX Linux.

Notices


Reply
  Search this Thread
Old 07-29-2018, 02:28 PM   #1
cybervigilante
Member
 
Registered: Apr 2018
Posts: 39

Rep: Reputation: Disabled
confused about piping to ls


I seem to be confused about piping. I'm using the find command to find files in my PDF directory when I'm in home. The criteria only find one file. then I pipe to the ls -alh command to check the size, and it lists the Entire contents of my home directory instead of the one file in my PDF directory:

find Documents/PDF/*.pdf -mtime -10 -size +5000k | ls -alh
 
Old 07-29-2018, 02:43 PM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 20,803

Rep: Reputation: 5146Reputation: 5146Reputation: 5146Reputation: 5146Reputation: 5146Reputation: 5146Reputation: 5146Reputation: 5146Reputation: 5146Reputation: 5146Reputation: 5146
Quote:
Originally Posted by cybervigilante View Post
I seem to be confused about piping. I'm using the find command to find files in my PDF directory when I'm in home. The criteria only find one file. then I pipe to the ls -alh command to check the size, and it lists the Entire contents of my home directory instead of the one file in my PDF directory:

find Documents/PDF/*.pdf -mtime -10 -size +5000k | ls -alh
You're doing it backwards. Try:
Code:
ls -alh `find Documents/PDF/*.pdf -mtime -10 -size +5000k`
..instead. And those are backticks (to the left of the 1 on your keyboard), not single-quotes.
 
Old 07-29-2018, 02:49 PM   #3
paladin.michael
Member
 
Registered: Jun 2011
Location: Danbury, CT, USA
Distribution: Kubuntu, Slackware, Debian, FreePBX
Posts: 75

Rep: Reputation: 23
confused about piping to ls

ls doesn't accept piped input, you could use the -exec argument of find or pipe to xargs and have xargs run the ls commands. e.g.

find Documents/PDF/*.pdf -mtime -10 -size +5000k -exec ls -lah {} \;

Or

find Documents/PDF/*.pdf -mtime -10 -size +5000k -print0 | xargs -0 ls -lah
 
Old 07-29-2018, 02:57 PM   #4
Turbocapitalist
Senior Member
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 3,544
Blog Entries: 3

Rep: Reputation: 1580Reputation: 1580Reputation: 1580Reputation: 1580Reputation: 1580Reputation: 1580Reputation: 1580Reputation: 1580Reputation: 1580Reputation: 1580Reputation: 1580
Quote:
Originally Posted by cybervigilante View Post
I seem to be confused about piping. I'm using the find command to find files in my PDF directory when I'm in home. The criteria only find one file. then I pipe to the ls -alh command to check the size, and it lists the Entire contents of my home directory instead of the one file in my PDF directory:

find Documents/PDF/*.pdf -mtime -10 -size +5000k | ls -alh
You'd have to use xargs instead, if you want to do it that way.

Code:
find ~/Documents/PDF/ -name '*.pdf' -mtime -10 -size +5000k -print0 | xargs --null ls -lh
However, the -ls exists and the -printf option also gives you a lot of choice. See "man find"

Code:
find ~/Documents/PDF/ -name '*.pdf' -mtime -10 -size +5000k -ls
 
Old 07-29-2018, 03:58 PM   #5
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 11,602

Rep: Reputation: 3494Reputation: 3494Reputation: 3494Reputation: 3494Reputation: 3494Reputation: 3494Reputation: 3494Reputation: 3494Reputation: 3494Reputation: 3494Reputation: 3494
solution was already explained, so I would only add some info:
the original command is wrong, and actually that executes a find <args> and an ls <args> commands more or less independently. That's why you got that result.
 
Old 07-29-2018, 06:36 PM   #6
cybervigilante
Member
 
Registered: Apr 2018
Posts: 39

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by TB0ne View Post
You're doing it backwards. Try:
Code:
ls -alh `find Documents/PDF/*.pdf -mtime -10 -size +5000k`
..instead. And those are backticks (to the left of the 1 on your keyboard), not single-quotes.
So what is the purpose of the backticks?
 
Old 07-29-2018, 10:41 PM   #7
Turbocapitalist
Senior Member
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 3,544
Blog Entries: 3

Rep: Reputation: 1580Reputation: 1580Reputation: 1580Reputation: 1580Reputation: 1580Reputation: 1580Reputation: 1580Reputation: 1580Reputation: 1580Reputation: 1580Reputation: 1580
Quote:
Originally Posted by cybervigilante View Post
So what is the purpose of the backticks?
The backticks are one way of writing command substitution. A better syntax is with parenthesis:

Code:
ls -alh $(find Documents/PDF/ -name '*.pdf' -mtime -10 -size +5000k)
With either syntax, command substitution is a way of getting output from one program or set of program and using it as arguments to another program. A pipe is different in that the output of one program is used as input for the next.

However, xargs is yet another way of passing output from one program and using it as arguments (options) for the next. See "man xargs". For the command substitution see "man bash" or the corresponding manual page for whichever shell you are using (e.g. zsh) if it is not bash. Heads up that the shell's manual page is very, very long. However, it is worth learning to navigate.
 
1 members found this post helpful.
Old 07-30-2018, 01:52 PM   #8
cybervigilante
Member
 
Registered: Apr 2018
Posts: 39

Original Poster
Rep: Reputation: Disabled
Thanks. I'll try the parentheses since I usually hit the 1 key instead of the backtick
 
  


Reply


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Linux piping vs Windows piping emanabela Linux - Newbie 1 05-10-2009 01:58 PM
piping | jezz Linux - General 2 05-04-2008 05:28 AM
Piping ls Kcghost Linux - General 9 03-05-2008 08:24 PM
Piping... disruptive Programming 3 02-12-2008 02:09 PM
Confused nay Very Confused chrystlenight SUSE / openSUSE 3 08-28-2007 06:57 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > antiX / MX Linux

All times are GMT -5. The time now is 02:48 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration