• VMware

    Learn about VMware virtualization for its products like vsphere ESX and ESXi, vCenter Server, VMware View, VMware P2V and many more

  • Linux

    Step by step configuration tutorials for many of the Linux services like DNS, DHCP, FTP, Samba4 etc including many tips and tricks in Red Hat Linux.

  • Database

    Learn installation and configuration of databases like Oracle, My SQL, Postgresql, etc including many other related tutorials in Linux.

  • How to exclude some directories from find command in Linux

    There can be cases where you are searching for a file but you want to exclude some particular directories from the search.

    -prune is used to ignore files and directories from your search

    Lets see some examples

    Exculde "work" directory in your search to find "myfile" document.
    NOTE: I have placed the same copy inside "deepak" and "work" directory

    The below command will lookout for all the files with name "myfile" inside /root/
    # find /root/ -name myfile -type f
    /root/deepak/myfile
    /root/work/myfile

    To exclude "work" directory
    # find /root/ -path '/root/work' -prune -o -name myfile -type f -print
    /root/deepak/myfile

    Also if you don't want to give complete path of the excluded directory, you can use the -name argument





    # find /root/ -name 'work' -prune -o -name myfile -type f -print
    /root/deepak/myfile

    In the above case any directory with name "work" would be excluded from the find command

    Excluding multiple directories from your search

    Exclude any directory with name work and home
    # find .  \( -name work -o -name home \)  -prune -o -name myfile -type f -print
    NOTE: You can use -o argument in the shown format multiple times as many directories you want to exclude

    To learn more about find command follow the below link
    10 Practical Examples for using FIND Command in Linux

    Related Articles
    10 practical examples to use USERADD command in linux
    Tutorial for Monitoring Tools SAR and KSAR with examples in Linux
    Tutorial for SYSLOG with Examples in Red Hat Linux
    9 examples to help you understand top command usage in Unix/Linux


    Deepak Prasad

    is a techie and an author who is still trying to survive in this IT generation with very little knowledge he has on Linux/Unix, VMware, SAN Storage, Automation, networking etc

    You can follow him on Facebook or Google+


    Do you also have something to share here?
    Join GoLinuxHub Team as an Author, Click here for more information
    How to exclude some directories from find command in Linux How to exclude some directories from find command in Linux Reviewed by Deepak Prasad on Wednesday, May 14, 2014 Rating: 5

    No comments:

    Powered by Blogger.