LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 05-16-2009, 02:43 AM   #1
UltraSoul
Member
 
Registered: Dec 2004
Location: Japan
Distribution: REDHAT9.0, Mandrake10.1
Posts: 404

Rep: Reputation: 31
How to exclude certain path from find command.


Hi, I have the following mounted filesystem on my RHEL4 U4.

# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 7.9G 4.8G 2.8G 64% /
none 506M 0 506M 0% /dev/shm
/dev/sdb1 7.9G 2.1G 5.5G 28% /shared_fs

I use the following command to find file size which is over 100MB on root filesystem.

# find / -size +102400k -exec du -hs {} \;

The command above will search /shared_fs. But I do not want to search /shared_fs because many small files is under /shared_fs. So, I wonder whether there is a way to exclude search path from find command. Now,
I am using the following command but the following command just limit the
command output not to show the files beginning with /shared_fs. Any better idea?

# find / -size +102400k -exec du -hs {} \; | grep -v "/shared_fs"
 
Old 05-16-2009, 03:11 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981
Code:
find / -wholename /shared_fs -prune -o -size +102400k -exec du -hs {} \;

Last edited by colucix; 05-16-2009 at 03:13 AM.
 
Old 05-16-2009, 06:30 AM   #3
UltraSoul
Member
 
Registered: Dec 2004
Location: Japan
Distribution: REDHAT9.0, Mandrake10.1
Posts: 404

Original Poster
Rep: Reputation: 31
HI, colucix

# more /etc/redhat-release
Red Hat Enterprise Linux AS release 4 (Nahant Update 5)

# find / -wholename /shared_fs -prune -o -size +102400k -exec du -hs {} \;
find: invalid predicate `-wholename'

==> I got the error above, Any idea?
 
Old 05-16-2009, 11:49 AM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981
What version of find? I didn't know that -wholename was a recent addition. Does the following work?
Code:
find / -path /shared_fs -prune -o -size +102400k -exec du -hs {} \;
 
Old 05-16-2009, 01:02 PM   #5
UltraSoul
Member
 
Registered: Dec 2004
Location: Japan
Distribution: REDHAT9.0, Mandrake10.1
Posts: 404

Original Poster
Rep: Reputation: 31
# rpm -qa | grep find
findutils-4.1.20-7.el4.1

# find / -path /opt -prune -o -size +10240k -exec du -hs {} \;
13M /usr/share/fonts/zh_TW/TrueType/bsmi00lp.ttf
21M /usr/share/comps/i386/hdlist2
28M /var/lib/rpm/Packages
20G /home/com/com/top.log
31M /share/savlinux/talpa/talpa-redhat/combined.tgz
11M /share/savlinux/talpa/talpa-ubuntu/combined.tgz
32M /share/savlinux/talpa/talpa-suse/combined.tgz
17M /share/savlinux/talpa/talpa-asianux/combined.tgz
897M /proc/kcore
find: /proc/20994/task/20994/fd/4: No such file or directory


-path is my desired command option, thank u. I also have a problem
if I can use -path to exculde multiple directories for search list.
For example, I want to search all files > 10MB but /proc and /opt is not needed to find. Is there a way to do it.kindly please advise.
 
Old 05-16-2009, 01:15 PM   #6
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981
Code:
find / \( -path /opt -o -path /proc \) -prune -o -size +10240k -exec du -hs {} \;
The syntax highlighted in red is for alternative (logical or).
 
Old 05-16-2009, 01:57 PM   #7
UltraSoul
Member
 
Registered: Dec 2004
Location: Japan
Distribution: REDHAT9.0, Mandrake10.1
Posts: 404

Original Poster
Rep: Reputation: 31
HI,colucix

It works fine, thank you very much.

I also tried to find the file modified within last day by the following command. I found if I do not use -type f option, find command output will give me some un-desired result as the second command output. I wonder what the reason is. Any Advices?


<1> # find / \( -path /proc -o -path /sys \) -prune -o -type f -daystart -m time -1 -exec ls -al {} \;
-rw-r--r-- 1 ntp ntp 8 May 17 02:03 /var/lib/ntp/drift
-rw-r--r-- 1 root root 871 May 17 02:33 /var/lib/nfs/rmtab
-rw------- 1 root root 133187 May 17 02:33 /var/log/messages
-rw------- 1 root root 22095 May 17 02:01 /var/log/cron
-r-------- 1 root root 292876 May 17 01:15 /var/log/lastlog
-rw-rw-r-- 1 root utmp 384 May 17 01:15 /var/log/wtmp
-rw------- 1 root root 214 May 17 01:15 /var/log/secure
-rw-rw-r-- 1 root utmp 4608 May 17 01:15 /var/run/utmp

<2> # find / \( -path /proc -o -path /sys \) -prune -o -daystart -mtime -1 -exec ls -al {} \;
total 20
drwxr-xr-x 2 ntp ntp 4096 May 17 02:03 .
drwxr-xr-x 23 root root 4096 Jun 3 2008 ..
-rw-r--r-- 1 ntp ntp 8 May 17 02:03 drift
-rw-r--r-- 1 ntp ntp 8 May 17 02:03 /var/lib/ntp/drift
total 36
drwxr-xr-x 4 root root 4096 May 17 02:33 .
drwxr-xr-x 23 root root 4096 Jun 3 2008 ..
-rw-r--r-- 1 root root 334 Mar 19 10:32 etab
-rw-r--r-- 1 root root 0 Jul 11 2008 export-lock
-rw-r--r-- 1 root root 871 May 17 02:33 rmtab
drwxr-xr-x 7 root root 0 Mar 19 10:31 rpc_pipefs
drwx------ 4 rpcuser rpcuser 4096 Jun 2 2008 statd
-rw------- 1 root root 0 May 24 2006 state
-rw-r--r-- 1 root root 0 Mar 19 10:32 xtab
-rw-r--r-- 1 root root 871 May 17 02:33 /var/lib/nfs/rmtab
-rw------- 1 root root 133187 May 17 02:33 /var/log/messages
-rw------- 1 root root 22095 May 17 02:01 /var/log/cron
-r-------- 1 root root 292876 May 17 01:15 /var/log/lastlog
-rw-rw-r-- 1 root utmp 384 May 17 01:15 /var/log/wtmp
-rw------- 1 root root 214 May 17 01:15 /var/log/secure
-rw-rw-r-- 1 root utmp 4608 May 17 01:15 /var/run/utmp
crw-rw-rw- 1 root tty 5, 2 May 17 02:49 /dev/ptmx
crw--w---- 1 com tty 136, 1 May 17 02:49 /dev/pts/1sdfsdf
 
Old 05-16-2009, 02:06 PM   #8
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981
If you don't use -type f, the find command will return also the directories modified in the last day and their content will be listed from -exec ls -al.

Take in mind that the modification time of a directory depends on the time stamp of the more recent file. If one of these files have been modified in the last day, the directory has been modified as well and the find commands find it. Hence, executing
Code:
ls -al /path/to/dir
lists the content of the directory as usual (older files included).
 
Old 05-16-2009, 07:26 PM   #9
UltraSoul
Member
 
Registered: Dec 2004
Location: Japan
Distribution: REDHAT9.0, Mandrake10.1
Posts: 404

Original Poster
Rep: Reputation: 31
Thanks for your support.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Using find and grep - how to exclude a result ? graziano1968 Linux - General 13 12-04-2010 11:02 PM
exclude directories from find noir911 Linux - General 3 11-22-2006 07:39 AM
how do i get the proper path to a file through find command napster Linux - General 4 11-07-2005 05:35 AM
How can I exclude NFS with find with no visit david.dales Linux - General 2 08-24-2005 04:08 AM
exclude directory from find ebasi Linux - Software 8 07-17-2004 03:12 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 01:38 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration