LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 03-03-2012, 08:21 AM   #1
Micky12345
Member
 
Registered: Feb 2012
Posts: 58

Rep: Reputation: Disabled
find command


i have written a code
Code:
find . -type f | ls -l
my aim is to list only the files

but i am getting all the files and directories

why so???
 
Old 03-03-2012, 08:24 AM   #2
T3RM1NVT0R
Senior Member
 
Registered: Dec 2010
Location: Internet
Distribution: Linux Mint, SLES, CentOS, Red Hat
Posts: 2,385

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
@ Reply

Hi Micky12345,

That is because you are piping the output of find command to ls -l and thus it is display files and directories. If you only want to display files then:

Code:
find . -type f
will suffice.
 
Old 03-03-2012, 09:57 AM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Code:
find . -type f -ls
if you want details. Use the -printf predicate to get even more details.

Regarding your first attempt, you actually need xargs to execute the ls command over the output of find:
Code:
find . -type f | xargs ls -l
 
1 members found this post helpful.
Old 03-04-2012, 04:18 AM   #4
rng
Senior Member
 
Registered: Aug 2011
Posts: 1,198

Rep: Reputation: 47
Good linux commands.

How can we use -printf here?
 
Old 03-04-2012, 08:23 AM   #5
prowla
Member
 
Registered: Feb 2011
Location: UK
Distribution: RHEL 5 & 6, Ubuntu 10
Posts: 93

Rep: Reputation: 3
find . -type f -exec ls -ld {} \;
 
Old 03-04-2012, 11:53 AM   #6
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Quote:
Originally Posted by rng View Post
How can we use -printf here?
For example, if you want to reproduce something similar to the output of ls -l (on OpenSuSE):
Code:
find . -type f -printf "%M %n %u %g %8s %Ty-%Tm-%Td %TH:%TM %f\n"
A lot of other format specifiers are available. Please, see man find for details.
 
Old 03-04-2012, 07:00 PM   #7
rng
Senior Member
 
Registered: Aug 2011
Posts: 1,198

Rep: Reputation: 47
Thanks.
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Find a file in directories without using find command sikanders Linux - Newbie 14 08-06-2010 08:47 PM
Find/grep/wc command to find matching files, print filename and word count dbasch Linux - Newbie 10 09-14-2009 05:55 PM
Single find command to find multiple files? thok Linux - Newbie 7 01-31-2009 04:45 PM
Using a single "Find" Command to find files bases on multiple criteria roboxooo Linux - Newbie 6 01-15-2009 04:13 AM
can't find my find command! how to replace? dave247 Debian 4 11-19-2008 10:51 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 08:17 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