Finding Files By Name, Size, and Both Name and Size


Let's perform a couple of independent finds and then combine the criteria of the finds. The finds in the following example are performed on a small desktop system. This allows me to search the entire system for files meeting various criteria. You may be working on a much larger, more elaborate system, so use caution when searching the entire system for files. You may slow down other users for a long period of time, depending on the number of files on the system both locally and accessible over the network.

First, let's find for all files on the system ending in .c with the command below:

 #  find / -name *.c -print  /usr/X11R6/include/X11/Xaw/Template.c /usr/X11R6/include/Xaw3d/Template.c /usr/X11R6/lib/X11/etc/et4000clock.c /usr/doc/glibc-2.1.1/examples.threads/ex1.c /usr/doc/glibc-2.1.1/examples.threads/ex2.c /usr/doc/glibc-2.1.1/examples.threads/ex3.c /usr/doc/glibc-2.1.1/examples.threads/ex4.c /usr/doc/glibc-2.1.1/examples.threads/ex5.c /usr/doc/glibc-2.1.1/examples.threads/ex6.c              .              .              . /usr/doc/bind-8.2/notes/db_names.c /usr/doc/libpng-1.0.3/example.c /usr/doc/FAQ/html/clone.c /usr/doc/gnome-libs-devel/devel-docs/gnomeui/gnomeui-scan.c # 

You can see from this find that there are many files on the system ending in .c . I included only the beginning and end of this search because the entire output would be too long.

I also ran this command and piped the output to wc , which showed 1737 files on the system ending in .c , as shown in the following example:

 #  find / -name *.c  wc  1737    1737   77044 # 
graphics/finda_icon.gif

Now we can search for all files on the system greater than 500,000 characters in size with the find command below:

 #  find / -size +500000c -print  /dev/core /etc/X11/core /var/lib/rpm/packages.rpm /var/lib/rpm/fileindex.rpm /var/lib/dosemu/hdimage.freedos /var/lib/slocate/slocate.db /var/lock/samba/SHARE_MEM_FILE /proc/kcore /home/ftp/lib/libc-2.1.1.so /home/test/linux1.xwd /lib/libc-2.1.1.so /lib/libdb-2.1.1.so /lib/libm-2.1.1.so /root/core               .               .               . /usr/share/gnome/help/users-guide/C/figs/full.gif /usr/share/emacs/20.3/etc/DOC-20.3.1 /usr/share/emacs/20.3/leim/quail/ZIRANMA.el /usr/share/emacs/20.3/leim/quail/ZIRANMA.elc /usr/share/emacs/20.3/leim/skk/skkdic.el /usr/share/emacs/20.3/leim/skk/skkdic.elc /usr/share/emacs/20.3/lisp/loaddefs.el /usr/share/sounds/card_shuffle.wav /usr/share/sounds/startup2.wav /usr/share/guavac/classes.zip 

I only included the beginning and end of this listing as well since there were many files of size greater than 500,000 characters on the system.

I also ran this command and piped the output to wc , which showed 215 files on the system with a size greater than 500,000 characters, as shown in the following example:

 #  find / -size +500000c -print  wc  215     215    6281 # 

Let's now combine the two commands and see how many of the files on the system ending in .c are also greater than 500,000 characters in size:

 #  find / -name *.c -size +500000c -print  /usr/src/drivers/scsi/advansys.c # 
graphics/finda_icon.gif

Of the 1737 files on the system ending in .c and the 215 files greater than 500,000 characters in size, only one file, advansys.c , meets both criteria. There is an implied and in the previous find command. We could have explicitly specified an and , however, it is implied in the find command. The find did indeed result in files that end in .c and are greater than 500,000 characters. The upcoming find uses the or operator, which is not implied.

What if we wanted to find both files ending in .c and .o that are greater than 500000 characters in size? We could use the -o operator which would "or" the files ending in .c and .o . The following example shows this find operation:

 find / -size +500000c \(  -name *.c -o -name *.a \) -print find / -size +500000c \(  -name *.c -o -name *.a \) -print  wc #  find / -size +500000c \( -name *.c -o -name *.a \) -print  /usr/X11R6/lib/libMagick.a /usr/X11R6/lib/libX11.a /usr/lib/bind/lib/libbind.a /usr/lib/bind/lib/libbind_r.a /usr/lib/libbfd.a /usr/lib/libBLT.a /usr/lib/libstdc++-2-libc6.1-1-2.9.0.a /usr/lib/libc.a              .              .              . /usr/lib/libinn.a /usr/lib/libtiff.a /usr/lib/liblinuxconf.a /usr/lib/libform_g.a /usr/lib/libncurses_g.a /usr/lib/python1.5/config/libpython1.5.a /usr/lib/libpisock.a /usr/lib/libcustoms.a /usr/lib/libqt.a /usr/lib/libst.a /usr/src/drivers/scsi/advansys.c # 
graphics/finda_icon.gif

The two file extensions for which we are searching are placed in parentheses. A backslash is required before the open and close parentheses because the parentheses have meaning to the shell and we want them to be used only to specify the precedence in our find command and not to be used by the shell. The result of this find shows that many files ending in .a and .c meet the criteria of greater than 500,000 characters.

Let's now pipe the output of this commnd to wc to see precisely the number of files ending in either .c or .o and having a size greater than 500,000 characters:

 #  find / -size +500000c \( -name *.c -o -name *.a \) -print  wc  39      39     982 # 

Of the 39 files that meet the criteria, we know that 38 ended in .a because our earlier example showed that only one file ending in .c met the criteria.



HP-UX 11i Systems Administration Handbook and Toolkit
HP-UX 11i Systems Administration Handbook and Toolkit (2nd Edition)
ISBN: 0131018833
EAN: 2147483647
Year: 2003
Pages: 301

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net