Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Jun 242010
 

xargs when the filename contains a newline

Answer:

It is always handy to combine the power of find and xargs for a lot of tasks, such as

# find /tmp -type f | xargs rm -rf

However, the command will failed if the a file contains a newline character. To solve this, you can do like below.

# find /tmp -type f -print0 | xargs -0 rm -rf

Now the file list returned by the find command is terminated by a null character, so it will not mixed with the newline character if they are part of the filename. Also, the xargs -0 option will treat the null character as the delimiter (rather than newline).

Jan 072009
 

Becareful when using the mtime option in find command

Answer:

A simple command like the following is very handy when finding all the files in the current directory which have been modified within 1 day.

# find -type f -mtime -1

But the above interpretation is simply wrong!

The real meaning of the above command is: Find all the files in the current directory which have been modified less than 2 days.

So if a file is modified before 1.9999999.. day, it still match the above command since the fractional part is ignored.

Try it yourself if you don't believe.

Reference:

man find