Ubuntu Unleashed 2019 Edition: Covering 18.04, 18.10, 19.04

(singke) #1

Another useful test is -size, which you use to specify how big the files
should be in order to match. You can specify the size in kilobytes and
optionally use + or - to specify greater than or less than. Consider these
examples:


Click here to view code image
matthew@seymour:~$ find /home -name ".txt" -size 100k
matthew@seymour:~$ find /home -name "
.txt" -size +100k
matthew@seymour:~$ find /home -name "*.txt" -size -100k


The first example brings up files of exactly 100KB, the second only files
larger than 100KB, and the last only files under 100KB.


Moving on, the -user option enables you to specify the user who owns the
files you are looking for. So, to search for all files in /home that end with
.txt, that are under 100KB, and that are owned by user matthew, you use
this:


Click here to view code image
matthew@seymour:~$ find /home -name "*.txt" -size -100k -user matthew


You can flip any of the conditions by specifying -not before them. For
example, you can add -not before -user matthew to find matching files
owned by everyone except matthew:


Click here to view code image
matthew@seymour:~$ find /home -name "*.txt" -size -100k -not -user
matthew


You can add as many -not parameters as you need, and you can even use -
not -not to cancel out the first -not. (Yes, that is pointless.) Keep in
mind, though, that -not -size -100k is essentially equivalent to -size
+100k, with the exception that the former will match files of exactly 100KB,
whereas the latter will not.


You can use -perm to specify which permissions a file should have in order
to match it. This is tricky, so read carefully. The permissions are specified in
the same way as with the chmod command: u for user, g for group, o for
others, r for read, w for write, and x for execute. However, before you give
the permissions, you need to specify a plus, a minus, or a blank space. If you
specify neither a plus nor a minus, the files must exactly match the mode you
give. If you specify -, the files must match all the modes you specify. If you
specify +, the files must match any the modes you specify. Confused yet?


The confusion can be cleared up with some examples. This following

Free download pdf