Module: Fynd::Tests

Included in:
Sieve
Defined in:
lib/fynd/tests.rb

Instance Method Summary collapse

Instance Method Details

#amin(n) ⇒ Object

File was last accessed n minutes ago.



13
14
# File 'lib/fynd/tests.rb', line 13

def amin(n)
end

#anewer(other) ⇒ Object

File was last accessed more recently than file was modified. If file is a symbolic link and the -H option or the -L option is in effect, the access time of the file it points to is always used.



19
20
21
22
23
# File 'lib/fynd/tests.rb', line 19

def anewer(other)
  files.select! do |file|
    File.lstat(file).atime > File.lstat(other).atime
  end
end

#atime(n) ⇒ Object

File was last accessed n*24 hours ago. When find figures out how many 24-hour periods ago the file was last accessed, any fractional part is ignored, so to match -atime +1, a file has to have been accessed at least two days ago.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/fynd/tests.rb', line 29

def atime(n)
  match = n.match(/([-+]?)(\d+)/)
  comparer, interval = match[1], match[2].to_i
  time = Time.now    
  
  files.select! do |file|
    atime = File.lstat(file).atime
    
    case comparer
    when '+'
      # more than n days ago
      atime < time - interval.days
    when '-'
      # less than n days ago
      atime > time - interval.days
    when ''
      # exactly n days ago
      atime <= time - (interval - 1).days && atime >= time - interval.days
    else
      raise ArgumentError, "argument must be n, +n, or -n"
    end    
  end
end

#cmin(n) ⇒ Object

File’s status was last changed n minutes ago.



54
55
# File 'lib/fynd/tests.rb', line 54

def cmin(n)
end

#cnewer(other) ⇒ Object

File’s status was last changed more recently than file was modi- fied. If file is a symbolic link and the -H option or the -L option is in effect, the status-change time of the file it points to is always used.



61
62
63
64
65
# File 'lib/fynd/tests.rb', line 61

def cnewer(other)
  files.select! do |file|
    File.lstat(file).ctime > File.lstat(other).ctime
  end
end

#ctime(n) ⇒ Object

File’s status was last changed n*24 hours ago. See the comments for -atime to understand how rounding affects the interpretation of file status change times.



70
71
# File 'lib/fynd/tests.rb', line 70

def ctime(n)
end

#emptyObject Also known as: empty?

File is empty and is either a regular file or a directory.



74
75
76
77
78
# File 'lib/fynd/tests.rb', line 74

def empty
  files.select! do |file|
    File.lstat(file).zero?
  end
end

#falseObject Also known as: false?

Always false.



83
84
85
# File 'lib/fynd/tests.rb', line 83

def false
  # false
end

#gid(n) ⇒ Object

File’s numeric group ID is n.



90
91
92
93
94
# File 'lib/fynd/tests.rb', line 90

def gid(n)
  files.select! do |file|
    File.lstat(file).gid == n.to_i
  end
end

#group(name) ⇒ Object

File belongs to group gname (numeric group ID allowed).



97
98
99
100
101
102
# File 'lib/fynd/tests.rb', line 97

def group(name)
  files.select! do |file|
    gid = File.lstat(file).gid
    Etc.getgrgid(gid).name == name
  end
end

#ilname(pattern) ⇒ Object

Like -lname, but the match is case insensitive. If the -L option or the -follow option is in effect, this test returns false unless the symbolic link is broken.



107
108
# File 'lib/fynd/tests.rb', line 107

def ilname(pattern)
end

#iname(pattern) ⇒ Object

Like -name, but the match is case insensitive. For example, the patterns ‘fo*’ and ‘F??’ match the file names ‘Foo’, ‘FOO’, ‘foo’, ‘fOo’, etc. In these patterns, unlike filename expan- sion by the shell, an initial ‘.’ can be matched by ‘*’. That is, find -name *bar will match the file ‘.foobar’. Please note that you should quote patterns as a matter of course, otherwise the shell will expand any wildcard characters in them.



117
118
119
120
121
# File 'lib/fynd/tests.rb', line 117

def iname(pattern)
  files.select! do |file|
    file =~ /#{pattern}/i
  end
end

#inum(n) ⇒ Object

File has inode number n. It is normally easier to use the -samefile test instead.



125
126
127
128
129
# File 'lib/fynd/tests.rb', line 125

def inum(n)
  files.select! do |file|
    File.lstat(file).ino == n.to_i
  end
end

#iregex(pattern) ⇒ Object

Like -regex, but the match is case insensitive.



132
133
# File 'lib/fynd/tests.rb', line 132

def iregex(pattern)
end

#iwholename(pattern) ⇒ Object

Like -wholename, but the match is case insensitive.



136
137
# File 'lib/fynd/tests.rb', line 136

def iwholename(pattern)
end

File has n links.



140
141
# File 'lib/fynd/tests.rb', line 140

def links(n)
end

#lname(pattern) ⇒ Object

File is a symbolic link whose contents match shell pattern pat- tern. The metacharacters do not treat ‘/’ or ‘.’ specially. If the -L option or the -follow option is in effect, this test returns false unless the symbolic link is broken.



147
148
# File 'lib/fynd/tests.rb', line 147

def lname(pattern)
end

#mmin(n) ⇒ Object

File’s data was last modified n minutes ago.



151
152
# File 'lib/fynd/tests.rb', line 151

def mmin(n)
end

#mtime(n) ⇒ Object

File’s data was last modified n*24 hours ago. See the comments for -atime to understand how rounding affects the interpretation of file modification times.



157
158
# File 'lib/fynd/tests.rb', line 157

def mtime(n)
end

#name(pattern) ⇒ Object

Base of file name (the path with the leading directories removed) matches shell pattern pattern. The metacharacters (‘*’, ‘?’, and ‘[]’) match a ‘.’ at the start of the base name (this is a change in findutils-4.2.2; see section STANDARDS CON- FORMANCE below). To ignore a directory and the files under it, use -prune; see an example in the description of -wholename. Braces are not recognised as being special, despite the fact that some shells including Bash imbue braces with a special meaning in shell patterns. The filename matching is performed with the use of the fnmatch(3) library function. Don’t forget to enclose the pattern in quotes in order to protect it from expansion by the shell.



172
173
174
175
176
# File 'lib/fynd/tests.rb', line 172

def name(pattern)
  files.select! do |file|
    file =~ /#{pattern}/
  end
end

#newer(other) ⇒ Object

File was modified more recently than file. If file is a sym- bolic link and the -H option or the -L option is in effect, the modification time of the file it points to is always used.



181
182
# File 'lib/fynd/tests.rb', line 181

def newer(other)
end

#nogroupObject

No group corresponds to file’s numeric group ID.



198
199
200
201
202
203
204
205
206
207
208
# File 'lib/fynd/tests.rb', line 198

def nogroup
  files.select! do |file|
    gid = File.lstat(file).gid
    begin
      Etc.getgrgid(gid)
      false
    rescue ArgumentError => e
      true
    end
  end
end

#nouserObject

No user corresponds to file’s numeric user ID.



185
186
187
188
189
190
191
192
193
194
195
# File 'lib/fynd/tests.rb', line 185

def nouser
  files.select! do |file|
    uid = File.lstat(file).uid
    begin
      Etc.getpwuid(uid)
      false
    rescue ArgumentError => e
      true
    end
  end
end

#path(pattern) ⇒ Object

See -wholename. The predicate -path is also supported by HP-UX find.



211
212
# File 'lib/fynd/tests.rb', line 211

def path(pattern)
end

#perm(mode) ⇒ Object

-perm mode

File’s permission bits are exactly mode (octal or symbolic). Since an exact match is required, if you want to use this form for symbolic modes, you may have to specify a rather complex mode string. For example ‘-perm g=w’ will only match files which have mode 0020 (that is, ones for which group write per- mission is the only permission set). It is more likely that you will want to use the ‘/’ or ‘-’ forms, for example ‘-perm -g=w’, which matches any file with group write permission. See the EXAMPLES section for some illustrative examples.

-perm -mode

All of the permission bits mode are set for the file. Symbolic modes are accepted in this form, and this is usually the way in which would want to use them. You must specify ‘u’, ‘g’ or ‘o’ if you use a symbolic mode. See the EXAMPLES section for some illustrative examples.

-perm /mode

Any of the permission bits mode are set for the file. Symbolic modes are accepted in this form. You must specify ‘u’, ‘g’ or ‘o’ if you use a symbolic mode. See the EXAMPLES section for some illustrative examples. If no permission bits in mode are set, this test currently matches no files. However, it will soon be changed to match any file (the idea is to be more con- sistent with the behaviour of perm -000).



243
244
# File 'lib/fynd/tests.rb', line 243

def perm(mode)
end

#regex(pattern) ⇒ Object

File name matches regular expression pattern. This is a match on the whole path, not a search. For example, to match a file named ‘./fubar3’, you can use the regular expression ‘.*bar.’ or ‘.*b.*3’, but not ‘f.*r3’. The regular expressions understood by find are by default Emacs Regular Expressions, but this can be changed with the -regextype option.



252
253
# File 'lib/fynd/tests.rb', line 252

def regex(pattern)
end

#samefile(other) ⇒ Object

File refers to the same inode as name. When -L is in effect, this can include symbolic links.



257
258
# File 'lib/fynd/tests.rb', line 257

def samefile(other)
end

#size(n) ⇒ Object

File uses n units of space. The following suffixes can be used:

‘b’ for 512-byte blocks (this is the default if no suffix is

used)

‘c’ for bytes

‘w’ for two-byte words

‘k’ for Kilobytes (units of 1024 bytes)

‘M’ for Megabytes (units of 1048576 bytes)

‘G’ for Gigabytes (units of 1073741824 bytes)

The size does not count indirect blocks, but it does count blocks in sparse files that are not actually allocated. Bear in mind that the ‘%k’ and ‘%b’ format specifiers of -printf handle sparse files differently. The ‘b’ suffix always denotes 512-byte blocks and never 1 Kilobyte blocks, which is different to the behaviour of -ls.



281
282
# File 'lib/fynd/tests.rb', line 281

def size(n)
end

#trueObject

Always true.



285
286
# File 'lib/fynd/tests.rb', line 285

def true
end

#type(c) ⇒ Object

File is of type c:

b block (buffered) special c character (unbuffered) special d directory p named pipe (FIFO) f regular file l symbolic link; this is never true if the -L option or the

-follow option is in effect, unless the symbolic link is
broken. If you want to search for symbolic links when -L
is in effect, use -xtype.

s socket D door (Solaris)



301
302
303
304
305
306
307
308
309
310
311
312
# File 'lib/fynd/tests.rb', line 301

def type(c)
  files.select! do |file|
    case c.to_s
    when 'f', 'file'
      File.lstat(file).file?
    when 'd', 'dir', 'directory'
      File.lstat(file).directory?
    else
      false
    end
  end
end

#uid(n) ⇒ Object

File’s numeric user ID is n.



315
316
317
318
319
# File 'lib/fynd/tests.rb', line 315

def uid(n)
  files.select! do |file|
    File.lstat(file).uid == n.to_i
  end
end

#used(n) ⇒ Object

File was last accessed n days after its status was last changed.



322
323
# File 'lib/fynd/tests.rb', line 322

def used(n)
end

#user(name) ⇒ Object

File is owned by user uname (numeric user ID allowed).



326
327
328
329
330
331
# File 'lib/fynd/tests.rb', line 326

def user(name)
  files.select! do |file|
    uid = File.lstat(file).uid.to_i
    Etc.getpwuid(uid).name == name
  end
end

#wholename(pattern) ⇒ Object

File name matches shell pattern pattern. The metacharacters do not treat ‘/’ or ‘.’ specially; so, for example,

find . -wholename './sr*sc'

will print an entry for a directory called ‘./src/misc’ (if one exists). To ignore a whole directory tree, use -prune rather than checking every file in the tree. For example, to skip the directory ‘src/emacs’ and all files and directories under it, and print the names of the other files found, do something like this:

find . -wholename './src/emacs' -prune -o -print


347
348
# File 'lib/fynd/tests.rb', line 347

def wholename(pattern)
end

#xtype(c) ⇒ Object

The same as -type unless the file is a symbolic link. For sym- bolic links: if the -H or -P option was specified, true if the file is a link to a file of type c; if the -L option has been given, true if c is ‘l’. In other words, for symbolic links, -xtype checks the type of the file that -type does not check.



355
356
# File 'lib/fynd/tests.rb', line 355

def xtype(c)
end