Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8697783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:36:14+00:00 2026-06-13T01:36:14+00:00

I am trying to remove all empty files that are older than 2 days.

  • 0

I am trying to remove all empty files that are older than 2 days. Also I am ignoring hidden files, starting with dot. I am doing it with this code:

find /u01/ -type f -size 0 -print -mtime +2 | grep -v "/\\." | xargs rm

It works fine until there are spaces in the name of the file. How could I make my code ignore them?

OS is Solaris.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T01:36:15+00:00Added an answer on June 13, 2026 at 1:36 am

    Option 1

    Install GNU find and GNU xargs in an appropriate location (not /usr/bin) and use:

    find /u01/ -type f -size 0 -mtime +2 -name '[!.]*' -print0 | xargs -0 rm
    

    (Note that I removed (what I think is) a stray -print from your find options. The options shown removes empty files modified more than 2 days ago where the name does not start with a ., which is the condition that your original grep seemed to deal with.)

    Option 2

    The problem is primarily that xargs is defined to split its input at spaces. An alternative is to write your own xargs surrogate that behaves sensibly with spaces in names; I’ve done that. You then only run into problems if the file names contain newlines — which the file system allows. Using a NUL ('\0') terminator is guaranteed safe; it is the only character that can’t appear in a path name (which is why GNU chose to use it with -print0 etc).

    Option 3

    A final better option is perhaps:

    find /u01/ -type f -size 0 -mtime +2 -name '[!.]*' -exec rm {} \;
    

    This avoids using xargs at all and handles all file names (path names) correctly — at the cost of executing rm once for each file found. That’s not too painful if you’re only dealing with a few files on each run.

    POSIX 2008 introduces the notation + in place of the \; and then behaves rather like xargs, collecting as many arguments as will conveniently fit in the space it allocates for the command line before running the command:

    find /u01/ -type f -size 0 -mtime +2 -name '[!.]*' -exec rm {} +
    

    The versions of Solaris I’ve worked on do not support that notation, but I know I work on antique versions of Solaris. GNU find does support the + marker and therefore renders the -print0 and xargs -0 workaround unnecessary.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to build a function that will remove all the files that start
I'm trying to remove all of the leaves. I know that leaves have no
I'm trying to remove all hidden tags (and the ending tag) via regular expression
JSFiddle: http://jsfiddle.net/QbyUR/ So, I have an empty TD, that I'm trying to remove the
I want to remove the class attribute from all elements that have an empty
I'm trying to remove a directory with PHP. I unlink/remove all files/subdirs from the
I'm trying to remove all but the first child component from a Java Container.
I am trying to remove all HTML elements from a String. Unfortunately, I cannot
I am trying to remove all of a specific character from a string. I
I'm trying to simply remove all nested li elements within ul , but it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.