Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 19
Like Tree1Likes
What are the Linux commands to find directories and/or files that may be or may not be in the current directory? If possible, please go into details on how to ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Sep 2012
    Posts
    19

    How to find folders/files?


    What are the Linux commands to find directories and/or files that may be or may not be in the current directory? If possible, please go into details on how to use them and what are their pro(s) and con(s).

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,709
    The "find" command is the main tool used for that. See the man page for details on use: man find
    Example code:
    Code:
    # to find a directory
    find start-dir -type d -name 'dirname'
    # to find a file
    find start-dir -type f -name 'filename'
    # to find anything with 'foo' in the name
    find start-dir -iname '*foo*'
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  3. #3
    Just Joined!
    Join Date
    Sep 2012
    Posts
    19
    Quote Originally Posted by Rubberman View Post
    The "find" command is the main tool used for that. See the man page for details on use: man find
    Example code:
    Code:
    # to find a directory
    find start-dir -type d -name 'dirname'
    # to find a file
    find start-dir -type f -name 'filename'
    # to find anything with 'foo' in the name
    find start-dir -iname '*foo*'
    Let's say I am currently in food/fruit/apple/seeds directory. For the start-dir, if I used fruit, it will automatically know I meant the folder to be outside of my current directory?

    What is "-type"? Is that that options?
    What is "d" or "f"?
    What is "-name"?
    What is "-iname"?

  4. $spacer_open
    $spacer_close
  5. #4
    Trusted Penguin Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    3,425
    As Rubberman already said, the man page describes the details.
    Code:
    man find
    You must always face the curtain with a bow.

  6. #5
    Just Joined!
    Join Date
    Sep 2012
    Posts
    19
    Quote Originally Posted by Irithori View Post
    As Rubberman already said, the man page describes the details.
    Code:
    man find
    I currently do not have access to a Linux server. That is why I asked. Examples are always better explained by people interacting with each other rather than some typed up.

  7. #6
    Trusted Penguin Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    3,425
    I am afraid I have to disagree here.
    man pages are usually well written, maintained, complete, (if appropiate) with examples and also have pointers to further man pages.

    It is therefore legitimate to point to this source of knowledge, instead of attempting to rewrite it for no reason.

    Most man pages are also available online.
    find(1) - Linux man page
    You must always face the curtain with a bow.

  8. #7
    Linux Engineer hazel's Avatar
    Join Date
    May 2004
    Location
    Harrow, UK
    Posts
    1,260
    This looks like a homework question to me!
    "I'm just a little old lady; don't try to dazzle me with jargon!"
    www.hrussman.entadsl.com

  9. #8
    Just Joined!
    Join Date
    Sep 2012
    Posts
    19
    @Irithori
    I am afraid I will have to disagree with you disagreeing with me. Based on past experience, people interacting with each other and using examples are definitely a better way to learn. With that being said, it is my opinion. It is based on preference.

    You are not rewriting it for no reason. There are multiple sources for everything because they are better. Not everyone wants to know everything about something, they only want the basics and the importance of it.

    Thanks for the site.

    @hazel
    Your assuming everyone is only trying to learn about Linux because they have to and not that they want to.

  10. #9
    Trusted Penguin Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    3,425
    Your questions about -type, -name and -iname can be easily read.

    For the fruit/apple/seeds question.
    Just try it. Unless you use the -delete or -exec switch, nothing bad can happen.

    If you then have specific questions, with the command you tried and the error or unexpected behaviour you get,
    we can surely help.
    You must always face the curtain with a bow.

  11. #10
    Just Joined!
    Join Date
    Sep 2012
    Posts
    19
    Quote Originally Posted by Irithori View Post
    Your questions about -type, -name and -iname can be easily read.

    For the fruit/apple/seeds question.
    Just try it. Unless you use the -delete or -exec switch, nothing bad can happen.

    If you then have specific questions, with the command you tried and the error or unexpected behaviour you get,
    we can surely help.
    I figured out what they meant. I assume they are options. I am used to options being 1 letter.

    Quote Originally Posted by dalawh View Post
    I currently do not have access to a Linux server. That is why I asked.
    <--

    ^^^

Page 1 of 2 1 2 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •