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:
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
#
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
#
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.
18.117.168.46