Tuesday, November 15, 2005

Power of "find"

"find" is a command line utility. Its basic usage is to find some files. e.g.
find . -name '*.html'
The above example is to find all HTML files under current directory.

While building a homepage, it is common to change HTML and graphic files to 0644 permission. We can use the "-exec" option of find to execute the "chmod"; command to change the permission of the files, e.g:

find . \( -name '*.html' -o -name '*.png' -o -name '*.jpg' \) -exec chmod 0644 {} \;
The parameters after "-exec" is the command to be executed. In the command, "{}" is replaced by the found file. The "\;" is the terminator of the command of "-exec".

No comments: