Posted in Linux commands

“find” with Style, Part 1: executing commands

How to find files and do some action with them? E. g. you want to find log files and want to see their content. Or you want to delete .o files.
Every now and then you can see examples like

find . -name ‘*.log’ -exec less {} \;

What happens here? For every found file find will start a less with this single file.
Now suppose you have several log files you want to browse through.

Every time find finds a file a new less is started. In this case the additional load is negligible, but imagine you want to delete thousands of .o files (this will be handled in a later blog post).

The better way is to terminate the -exec with +:

find . -name ‘*.log’ -exec less {} +

What happens here? Find collects the file names (until the maximum of a command line is reached) and and starts one command with many file names. With this less example you can check this by opening the next or previous file – which is not possible with the first example above.

One thought on ““find” with Style, Part 1: executing commands

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s