Solved

'find' linux command - filter out directories

Posted on 2006-06-08
6
876 Views
Last Modified: 2008-03-03
I'm running this command:
find . > tmp.txt

but it also includes the directory names it finds along the way. Is there a way to filter out the directories?

Thanks
0
Comment
Question by:MaritimeSource
6 Comments
 
LVL 8

Expert Comment

by:Autogard
ID: 16865219
There is a "type" option in find...

=== From the man page for find ===

-type c
              File is of type c:
              b      block (buffered) special
              c      character (unbuffered) special
              d      directory
              p      named pipe (FIFO)
              f      regular file
              l      symbolic link (never true if the -L option or the -follow option is in effect, unless the symbolic link is broken).
              s      socket
              D      door (Solaris)
==============================

So try "find -type f > tmp.txt" (or something similar).
0
 
LVL 8

Accepted Solution

by:
Autogard earned 500 total points
ID: 16865253
My post above will tell it to find just regular files.  But actually if you want to find anything BUT directories then try one of these...

"find ! -type d > tmp.txt"
or
"find \! -type d > tmp.txt"

(source: http://lists.debian.org/debian-user/1996/09/msg00474.html)
0
 
LVL 5

Expert Comment

by:ranadastidar
ID: 16867439
try with locate tmp.txt
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 51

Expert Comment

by:ahoffmann
ID: 16878214
Autogard's comment is the answer to the question, locate is (horrible) unreliable.
0
 
LVL 1

Expert Comment

by:ico2
ID: 16892722
locate is faster than find though
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 16892755
<off-topic>
doesn't matter how fast imagination is, I'll wait for the truth ;-)
</off-topic>
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question