Solved

'find' linux command - filter out directories

Posted on 2006-06-08
6
907 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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

In my business, I use the LTS (Long Term Support) versions of Linux. My workstations do real work, and so I rarely have the patience to deal with silly problems caused by an upgraded kernel that had experimental software on it to begin with from a r…
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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…

749 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