Results 1 to 10 of 10
|
|
Enjoy an ad free experience by logging in. Not a member yet? Register.
|
|
-
07-25-2006 #1Just Joined!
- Join Date
- May 2006
- Posts
- 47
How do you exclude files in the find command
I am using the find command and I am trying to to exclude any files that start with the . in front of them such as .bash_history
-
07-25-2006 #2
I think there is not a way to explicitly exclude that files, but you can use the -regex or -iregex flag to match only the files that not begin with '.'
Regards
-
07-25-2006 #3
-regex matches the entire path, so -name and -iname are probably better, since they only match the actual filename.
-
07-25-2006 #4Linux Engineer
- Join Date
- Apr 2006
- Location
- Saint Paul, MN, USA / CentOS, Debian, Slackware, {Free, Open, Net}BSD, Solaris
- Posts
- 1,465
Hi.
Here's one way:
Which produces:Code:#!/bin/sh # @(#) s3 Demonstrate removal of display of dot-names. FILES="t1 .t1 t2 .t2" rm -f $FILES touch $FILES echo " Files present:" ls -al echo echo " Files listed:" find . -type f -print | grep -v '/[.]
cheers, drlCode:% ./s3 Files present: total 12 drwxr-xr-x 2 drl drl 216 Jul 25 14:31 . drwxr-xr-x 4 drl drl 104 Jul 25 14:06 .. -rw-r--r-- 1 drl drl 0 Jul 25 14:31 .t1 -rw-r--r-- 1 drl drl 0 Jul 25 14:31 .t2 -rwxr--r-- 1 drl drl 79 Jul 25 14:09 s1 -rwxr--r-- 1 drl drl 131 Jul 25 14:13 s2 -rwxr--r-- 1 drl drl 212 Jul 25 14:30 s3 -rw-r--r-- 1 drl drl 0 Jul 25 14:31 t1 -rw-r--r-- 1 drl drl 0 Jul 25 14:31 t2 Files listed: ./s1 ./s2 ./s3 ./t1 ./t2
Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
We look forward to helping you with the challenge of the other 10%.
( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )
-
07-25-2006 #5
One thing to look out for is that drl's solution will also skip files in hidden directories. So if there's a non-hidden file in a hidden directory, it won't display.
That may be what you want, but you should just beware of that.
-
07-25-2006 #6Linux Engineer
- Join Date
- Apr 2006
- Location
- Saint Paul, MN, USA / CentOS, Debian, Slackware, {Free, Open, Net}BSD, Solaris
- Posts
- 1,465
Hi.
Good catch, Cabhan!
We'd need to find if chrchcol wanted to ignore everything hidden. I'll fool around with the RE. I't's probably necessary to make sure that the / is a final separator (ihmmm, ignoring perhaps the pathological case of a dot-name empty directory) ... cheers, drlWelcome - get the most out of the forum by reading forum basics and guidelines: click here.
90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
We look forward to helping you with the challenge of the other 10%.
( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )
-
07-25-2006 #7Linux Engineer
- Join Date
- Apr 2006
- Location
- Saint Paul, MN, USA / CentOS, Debian, Slackware, {Free, Open, Net}BSD, Solaris
- Posts
- 1,465
Hi.
Here's a revision and test ... cheers, drl
Results:Code:#!/bin/sh # @(#) s4 Demonstrate removal of display of dot-names. FILES="t1 .t1 t2 .t2" rm -rf $FILES .hidden touch $FILES mkdir .hidden touch .hidden/t1 .hidden/.t1 echo " Files present:" ls -AR echo echo " Files listed:" find . -type f -print | grep -v '/[.][^/]*$'
Code:% ./s4 Files present: .: .hidden .t1 .t2 s4 t1 t2 ./.hidden: .t1 t1 Files listed: ./s4 ./t1 ./t2 ./.hidden/t1
Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
We look forward to helping you with the challenge of the other 10%.
( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )
-
08-04-2006 #8Just Joined!
- Join Date
- Sep 2005
- Location
- New delhi
- Posts
- 22
Originally Posted by chrchcol
find /root/ -not -name ".*" -name *.conf
Simple.
-
08-04-2006 #9Linux Engineer
- Join Date
- Apr 2006
- Location
- Saint Paul, MN, USA / CentOS, Debian, Slackware, {Free, Open, Net}BSD, Solaris
- Posts
- 1,465
Hi, amitsharma_26.
Thanks for posting this solution. The first part of this, namely:
Originally Posted by amitsharma_26
does seem to work (adjusting "/root/" appropriately), and I like the simplicity, but the addition ofCode:find /root/ -not -name ".*"
seemed to inhibit the display of everything. What is it supposed to do? ... cheers, drlCode:-name *.conf
Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
We look forward to helping you with the challenge of the other 10%.
( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )
-
08-06-2006 #10Just Joined!
- Join Date
- Sep 2005
- Location
- New delhi
- Posts
- 22
Dear drl,
Initial query is itself a bit confusing in the same regards. Though we can relate a same scenario like..
How about searchin for all the mp3 files with excluding all those who are starting by alphabet "A" ?
Or Even how about searchin for all the mp3 files with excluding all those who are smaller than 3 MB of size ?
With both of the two of above queries we can use the same method of excluding particular criteria.
find /mp3 -not -iname "A*" -iname "*.mp3"
& find /mp3 -not -size -3M -iname "*.mp3"
Though the later one can also be written as find /mp3 -size +3M -iname "*.mp3" , but it was just to correlate the way of excluding some particular criteria suited files.
Regards
Amit sharma..
p.s. My way of searchin *.conf did not really meant for that command to look really effective though later part of that command really didnt what i was concentrated.


Reply With Quote