System Administration
cancel
Showing results for 
Search instead for 
Did you mean: 

find to exclude sub directory

SOLVED
Go to solution
Sunny Jaisinghani
Trusted Contributor

find to exclude sub directory

Hello,

I want exclude all files under following directories

/var/sam/lp/
/etc/lp/
/var/spool/lp/

and exclude

/var/spool/lp/request/

I want create a cpio dump of these files

find /var/spool/lp /var/sam/lp /etc/lp -print | cpio -ocv .......


How should i edit the above command to exclude the directory /var/spool/lp/request/

I know it can be done by -prune or -depth but i am not able to put a correct syntax on board.

Thanks
Sunny
7 REPLIES
Sunny Jaisinghani
Trusted Contributor

Re: find to exclude sub directory

i want to include

all files under following directories

/var/sam/lp/
/etc/lp/
/var/spool/lp/


i made a typo
T G Manikandan
Honored Contributor

Re: find to exclude sub directory

find . -type d \( -name /var/sam/lp -o -name /etc/lp \) -prune -o -print

Sunny Jaisinghani
Trusted Contributor

Re: find to exclude sub directory

It did not work for me.


My requirements are different.

I want to include all files under

/var/sam/lp/
/etc/lp/
/var/spool/lp/

and exclude all files under

/var/spool/lp/request/

along with the directory /var/spool/lp/request/



Sunny Jaisinghani
Trusted Contributor

Re: find to exclude sub directory

example

to include

/var/spool/lp
/var/spool/lp/smodel
/var/spool/lp/sinterface
/var/spool/lp/seqfile
/var/spool/lp/lpd.log
/var/spool/lp/pstatus
/var/spool/lp/FIFO
/var/spool/lp/interface
/var/spool/lp/model
/var/spool/lp/member
/var/spool/lp/info
/var/spool/lp/log
/var/spool/lp/cinterface
/var/spool/lp/SCHEDLOCK
/etc/lp
/etc/lp/cinterface
/etc/lp/cinterface/TEC73060
/etc/lp/cinterface/TECSB1
/etc/lp/cinterface/pr003604
/etc/lp/cinterface/pr011341
/etc/lp/cinterface/TOTO
/etc/lp/cinterface/pr011774
/etc/lp/cinterface/pr051499
/etc/lp/cinterface/pr078378
/etc/lp/cinterface/FLTPRN0003
/etc/lp/cinterface/prmex022
/etc/lp/cinterface/prmex023
/etc/lp/cinterface/prmex0fx
/etc/lp/cinterface/prsing02
/etc/lp/cinterface/TECGM1
/etc/lp/cinterface/prsing04
/etc/lp/cinterface/sigprt01
/etc/lp/cinterface/TECLR1
/etc/lp/cinterface/kyoc2050
/etc/lp/cinterface/TECPM1
/var/sam/lp
/var/sam/lp/member
/var/sam/lp/member/AUS_PQ_53
/var/sam/lp/member/Aficio3045
/var/sam/lp/member/BARPRN00001
/var/sam/lp/member/BARPRN00002
/var/sam/lp/member/BURPRN00001
/var/sam/lp/member/BURPRN00001_1
/var/sam/lp/member/COTPRN13526
/var/sam/lp/member/COTPRN78507
/var/sam/lp/member/COTPRN78508
/var/sam/lp/member/COTPRN78510
/var/sam/lp/member/COTPRN78512
/var/sam/lp/member/FARPRNUKT
/var/sam/lp/member/FHMPRN00001
/var/sam/lp/member/FHMPRN00010
/var/sam/lp/member/FLTPRN0001
/var/sam/lp/member/FLTPRN0003
/var/sam/lp/member/FLTPRN0007
/var/sam/lp/member/FLTPRN0008
/var/sam/lp/member/FLTPRN0010




to exclude

/var/spool/lp/request
/var/spool/lp/request/PR023562
/var/spool/lp/request/SIGPRT03
/var/spool/lp/request/TEC73060
/var/spool/lp/request/TEC73060/tA4209ggeuxp11
/var/spool/lp/request/TEC73060/dA4209ggeuxp11
/var/spool/lp/request/TEC73060/.remotesending
T G Manikandan
Honored Contributor
Solution

Re: find to exclude sub directory

find /var/sam/lp /etc/lp /var/spool/lp \( -name request \) -prune -o -print


This is not the right command , it excludes request subdirectory from all directory path but would work for you.
Sunny Jaisinghani
Trusted Contributor

Re: find to exclude sub directory

Thanks Manikandan

It works for me

You are right; since the directories /etc/lp/ and /var/sam/lp/ does not have "request" sub directory; it gives me desired output

Thanks
Dennis Handly
Acclaimed Contributor

Re: find to exclude sub directory

>T G Manikandan: it excludes request subdirectory from all directory path

You can use "-path /var/spool/lp/request" to exclude that specific directory.