[SOLVED] excluding a folder from "rm -r" in solaris
Solaris / OpenSolarisThis forum is for the discussion of Solaris, OpenSolaris, OpenIndiana, and illumos.
General Sun, SunOS and Sparc related questions also go here. Any Solaris fork or distribution is welcome.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
How can I remove all folders in a specific directory except one folder (solaris)?
for example I have these folders:
/home/mahmood/a
/home/mahmood/b
/home/mahmood/c
/home/mahmood/d
/home/mahmood/e
How can I use "rm -r" to remove b/ c/ d/ e/ but preserve a/ ??
there is no --exclude-dir o something similar.
bash-3.00# ls
a b c d e
bash-3.00# find ./ ! -path "a" | xargs -Ideleteme rm -rf deleteme
find: bad option -path
find: [-H | -L] path-list predicate-list
bash-3.00#
Indeed the -path predicate is not available in Solaris, but you can use -name as well and the -prune predicate to exclude an entire branch of the directory tree:
Code:
find /home/mahmood/* -type d -name a -prune -o -exec echo rm -r {} \;
Beware that it will remove any file and directory under a.
Yes you are right
Quote:
Originally Posted by colucix
Indeed the -path predicate is not available in Solaris, but you can use -name as well and the -prune predicate to exclude an entire branch of the directory tree:
Code:
find /home/mahmood/* -type d -name a -prune -o -exec echo rm -r {} \;
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.