Monday, October 26, 2009

Find Files / Search in Linux: Quick Examples

$ find / -name myfilename
____look in the root directory + mounted drives

$ find / -mtime -2
____find all files modified in the last two days

$ find . -name '?foo*'
____find all files in current and sub directories that start with foo (wildcard) (have to use ' ' with *)

$ find . -iname AbCd
____case insensitive

$ find / -user scott
____find files owned by scott (can do groups and permissions, too)

$ find / -type f
____find files, not directories. d is for directories, l is for sym links.

$ find / -name foo 2>/dev/null
____hide "permission denied errors". You could also just do $ sudo find ...

$ find . -maxdepth 2
____only go 2 directories deep

$ find . -size +20k -size -1M
____size is greater than 20k, less than 1M. note lower case k.

$ find . -exec grep -iH dog {} \;
____find files containing text (dog), i means case insensitive, sub l for H to get only file names
$ locate
____an indexed version of find, may not have recent files

No comments: