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 |
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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
|
|
05-16-2009, 02:43 AM
|
#1
|
Member
Registered: Dec 2004
Location: Japan
Distribution: REDHAT9.0, Mandrake10.1
Posts: 404
Rep:
|
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"
|
|
|
05-16-2009, 03:11 AM
|
#2
|
LQ Guru
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509
|
Code:
find / -wholename /shared_fs -prune -o -size +102400k -exec du -hs {} \;
Last edited by colucix; 05-16-2009 at 03:13 AM.
|
|
|
05-16-2009, 06:30 AM
|
#3
|
Member
Registered: Dec 2004
Location: Japan
Distribution: REDHAT9.0, Mandrake10.1
Posts: 404
Original Poster
Rep:
|
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?
|
|
|
05-16-2009, 11:49 AM
|
#4
|
LQ Guru
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509
|
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 {} \;
|
|
|
05-16-2009, 01:02 PM
|
#5
|
Member
Registered: Dec 2004
Location: Japan
Distribution: REDHAT9.0, Mandrake10.1
Posts: 404
Original Poster
Rep:
|
# 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.
|
|
|
05-16-2009, 01:15 PM
|
#6
|
LQ Guru
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509
|
Code:
find / \( -path /opt -o -path /proc \) -prune -o -size +10240k -exec du -hs {} \;
The syntax highlighted in red is for alternative (logical or).
|
|
|
05-16-2009, 01:57 PM
|
#7
|
Member
Registered: Dec 2004
Location: Japan
Distribution: REDHAT9.0, Mandrake10.1
Posts: 404
Original Poster
Rep:
|
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
|
|
|
05-16-2009, 02:06 PM
|
#8
|
LQ Guru
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509
|
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).
|
|
|
05-16-2009, 07:26 PM
|
#9
|
Member
Registered: Dec 2004
Location: Japan
Distribution: REDHAT9.0, Mandrake10.1
Posts: 404
Original Poster
Rep:
|
Thanks for your support.
|
|
|
All times are GMT -5. The time now is 12:02 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|