• 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

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

    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

    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

    Follow the below links for more tutorials

    Step by Step Linux Boot Process Explained In Detail
    Tutorial for Monitoring Tools SAR and KSAR with examples in Linux
    How to secure Apache web server in Linux using password (.htaccess)
    How to register Red Hat Linux with RHN (Red Hat Network )
    15 tips to enhance security of your Linux machine
    How does a DNS query works when you type a URL on your browser?
    How to create password less ssh connection for multiple non-root users
    How to create user without useradd command in Linux
    How to unlink/delete a symbolic in Linux
    How to give normal user root privileges using sudo in Linux/Unix
    How to do Ethernet/NIC bonding/teaming in Red Hat Linux
    How to install/uninstall/upgrade rpm package with/without dependencies
    Why is Linux more secure than windows and any other OS
    What is the difference between "su" and "su -" in Linux?
    What is swappiness and how do we change its value?

    Deepak Prasad

    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?

    Become an author and be a part of our GoLinuxHub Team, 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.