unix

Limit find depth

Snippet

Limit the depth of find for checking only some subdirectories instead of all of them by using -maxdepth.

You can also use -mindepth to sandwich directory levels.

# same as finding all files one level down, similar to "ls ./??*"
find . -maxdepth 1 -type f
 
# find all sub-subdirectories in the current directory
find . -maxdepth 2 -mindepth 2 -type d

Find files of particular size

Snippet

Say, find a file bigger than a megabyte.

$ find . -size +1M

List the UNIX groups I'm in

Blog

Easy enough:

$ groups
users www-data
$

So much easier than, say, the concatenation of these:

$ grep `whoami` /etc/group | cut -f1 -d: 
www-data
$ grep :`grep $USER /etc/passwd | cut -f4 -d:`: /etc/group | cut -f1 -d:
users
$