13.07.2015 Views

Linux System Administration Recipes A Problem-Solution Approach

Linux System Administration Recipes A Problem-Solution Approach

Linux System Administration Recipes A Problem-Solution Approach

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CHAPTER 8 ■ USING THE COMMAND LINE BETTERExpressionsThe real power of find lies in the breadth of available expressions:• -amin n, -atime n: Finds the file last accessed n minutes ago, or n × 24 hours ago.• -cmin n, -ctime n: Finds the file status last changed n minutes ago, or n × 24hours ago.• -mmin n, -mtime n: Finds the file last modified n minutes ago, or n × 24 hours ago.■ Note With the time options, a value of n means exactly n, +n means more than n, and -n means less than n.• find / -mmin -10: Returns all files in the / filesystem that were modified in the lastten minutes.• -fstype type: Returns files that are on a filesystem of this type. Valid valuesinclude ufs, tmp, nfs, and mfs.• -name foo: Searches for files whose name matches this shell pattern; so, wildcardsand anything else the shell deals with can be used. The following will find youraccounting files if you lose them!find /home/juliet -name 'accounts*'• -iname foo: Like -name, but case insensitive.• -regexp foo: Searches for files whose whole path (not just the filename) matchesthe regexp foo. The regexp type is by default emacs regexps.■ Note Always quote patterns (so, find / -name 'foo*') to avoid the shell expanding the wild characters.You can also search for files by type (-type filetype) and size (-size m), as well as by the user (-userusername) or group (-group groupname) that owns them.■ Note You can use the exec option with find to run a particular command on the files returned, but it’s muchmore flexible to use xargs, as described in the next recipe.180Download at WoweBook.Com

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!