Flylib.com

Books Software

 
 
 

Find Files by Group Ownership


Find Files by Group Ownership

file -group

If an option that allows you to work with users is available for a command, you know that an option for groups is also probably present. The find command is no different: If you want to look for files owned by a particular group, just use -group , followed by the group's name or number. On the music drive, scott should be the owner and music should be the group. Let's see if there are any files that aren't in the music group:

$ find . ! -group music
./Disco/Brides_of_Funkenstein_-_Disco_to_Go.mp3
./Disco/Sister_Sledge_-_He's_The_Greatest_Dancer.mp3
./Disco/Wild_Cherry_-_Play_That_Funky_Music.mp3
./Electronica/New_Order/Bizarre_Love_Triangle.mp3


There are only four files out of a large number of files that aren't in the music group. Now we need to run chgrp (see Chapter 7) on these files to make everything on the drive exactly the same.

Notice that, once again, we used ! to say, "Find the files that are not owned by the music group."



Find Files by File Size

file -size

Sometimes you'll want to find files based on their size. The find command can assist here as well. To specify a size, use the -size option, followed by a letter representing the size scheme you wish to use. If you don't provide a letter, the default is used; however, you should understand that you probably won't find what you want. If you don't append a letter after the number, the default is in bytes (which is then divided by 512 and rounded up to the next integer). This is too much math. It's easier to use a suffix after the number that represents the size in more common terms, as shown in Table 10.1.

Table 10.1. Find Files by Size

Suffix

Meaning

b

512-byte blocks (the default)

c

Bytes

k

Kilobytes (KB)

M

Megabytes (MB)

G

Gigabytes (GB)


Let's say we want to find every Clash song from their immortal album, London Calling , that is 10MB. (Yes, these were encoded at a super-high rate.) This job is easy enough with find :

$ cd Punk/Clash/1979_London_Calling
$ find . -size 10M
./07_-_The_Right_Profile.ogg
./08_-_Lost_In_The_Supermarket.ogg
./09_-_Clampdown.ogg
./12_-_Death_Or_Glory.ogg


That's weird. Only four songs? Here's where you need to understand a "gotcha" associated with using find : If you say 10M , then find looks for files that are exactly 10MB in size (rounded to 10MB, of course). If you want files larger than 10MB, you need to place a plus sign ( + ) in front of the given size; if you want files smaller than 10MB, use a minus sign ( - ) in front of the size:

$ find . -size +10M
./Jimmy_Jazz.ogg
./ Lover's_Rock.ogg
./ Revolution_Rock.ogg


Now we have a problem. Specifying 10M gives us files that are exactly 10MB, excluding those that are bigger, while specifying +10M gives us files that are larger than 10MB, excluding those that are exactly 10MB. How do we get both? If you want to learn how to obtain files that are 10MB and larger, see the "Show Results If Either Expression Is True (OR)" section later in this chapter.

Tip

If you want to find large text files, use c after your number. As Table 10.1 shows, c changes the search size to bytes. Every character in a text file is a byte, so an easy way to remember c is to associate it with the " characters " in a text file.

For instance, to find enormous text files, you can use this code:

$ find /home/scott/documents -size +500000c