Posted in Linux commands

“find” with Style, Part 2: Deleting Files

Now let’s delete files with style. The usual command to clean up a directory tree (e.g. to delete .o files) is

$ find . -name '*.o' -exec rm {} \;

As I wrote in an earlier post this calls rm for every single file. A first improvement is to change the terminator at the end of the line:

Continue reading ““find” with Style, Part 2: Deleting Files”

Posted in Linux commands

ssh: bypass /etc/hosts and DNS

A common little problem in my daily work is to log on to another machine with a cryptic filename, e.g. First I have find out, that the web server is on that machine. How easy would it be to type just ssh webserver! The sysadmins don’t want to put this neither into the name service nor into /etc/hosts. But there is help.

Continue reading “ssh: bypass /etc/hosts and DNS”

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.