Find Files by File Type


find -type

One of the most useful options for find is -type, which allows you to specify the type of object you wish to look for. Remember that everything on a UNIX system is a file (covered back in Chapter 1, "Things to Know About Your Command Line," in the "Everything Is a File" section), so what you're actually indicating is the type of file you want find to ferret out for you. Table 10.2 lists the file types you can use with find.

Table 10.2. Finding Files by Type

File Type Letter

Meaning

f

Regular file

d

Directory

l

Symbolic (soft) link

b

Block special file

c

Character special file

p

FIFO (First In First Out)

s

Socket


Let's say we want a quick list of the Steely Dan albums we have on the music drive. Since all songs are placed into directories by album, look for folders with -type d:

$ cd /media/music/Rock $ find Steely_Dan/ -type d Steely_Dan/ Steely_Dan/1980_Gaucho Steely_Dan/1975_Katy_Lied Steely_Dan/1974_Pretzel_Logic Steely_Dan/1976_The_Royal_Scam Steely_Dan/2000_Two_Against_Nature Steely_Dan/1972_Can't_Buy_A_Thrill Steely_Dan/1973_Countdown_To_Ecstasy Steely_Dan/1977_Aja 


This list is helpful, but since the name of every album directory begins with the year the album was released, we can sort by year for more precise information:

$ cd /media/music/Rock $ find Steely_Dan/ -type d | sort Steely_Dan/ Steely_Dan/1972_Can't_Buy_A_Thrill Steely_Dan/1973_Countdown_To_Ecstasy Steely_Dan/1974_Pretzel_Logic Steely_Dan/1975_Katy_Lied Steely_Dan/1976_The_Royal_Scam Steely_Dan/1977_Aja Steely_Dan/1980_Gaucho Steely_Dan/2000_Two_Against_Nature 


It can be incredibly beneficial to use a pipe to filter the list you generate with find; as you get better with find, you'll see that you do this more and more.



Linux Phrasebook
Linux Phrasebook
ISBN: 0672328380
EAN: 2147483647
Year: 2007
Pages: 288

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