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 8338673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:40:05+00:00 2026-06-09T04:40:05+00:00

I want to empty the file which is more than 30 MB size. I

  • 0

I want to empty the file which is more than 30 MB size. I tried to solve that using find command.

   find . -maxdepth 1 -size +32M -exec cat /dev/null > {} \;

and

   find . -maxdepth 1 -size +32M -exec echo -n > '{}' \;

But the both commands doesn’t empty the file.Instead of that ,it creates a {} file.

why it doesn’t empty the file? and why it creates a file called {}?.
what is wrong with the find command?

  • 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-09T04:40:06+00:00Added an answer on June 9, 2026 at 4:40 am

    Solution

    You must use sh -c in this case:

     -exec sh -c "> {}" \;
    

    Example of usage

    Preparing files:

    $ echo hello > a1
    $ cp a1 a2; cp a1 b1; cp a1 b2
    $ ls -l
    total 16
    -rw-r--r-- 1 ic ic 6  6. Aug 14:45 a1
    -rw-r--r-- 1 ic ic 6  6. Aug 14:45 a2
    -rw-r--r-- 1 ic ic 6  6. Aug 14:45 b1
    -rw-r--r-- 1 ic ic 6  6. Aug 14:45 b2
    

    Executing the command:

    $ find . -name 'a*' -exec sh -c '> {}' \;
    

    Checking the results:

    $ ls -l
    total 8
    -rw-r--r-- 1 ic ic 0  6. Aug 14:45 a1
    -rw-r--r-- 1 ic ic 0  6. Aug 14:45 a2
    -rw-r--r-- 1 ic ic 6  6. Aug 14:45 b1
    -rw-r--r-- 1 ic ic 6  6. Aug 14:45 b2
    $ cat a1
    $ cat b1
    hello
    

    As you can see, files that are starting with a are now empty; and other files are not.

    Explanation

    When you make something like

    find . -maxdepth 1 -size +32M -exec cat /dev/null > {} \;
    

    you make this redirection not inside the exec command, but outside of it.

    ( find . -maxdepth 1 -size +32M -exec cat /dev/null )  ===> ( {} \; )
    

    Of course it is incorrect. You must make this redirection inside the command that is executed by find. To do that, you must run a new shell inside the exec command. You make this using sh -c.

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

Sidebar

Related Questions

I have a csv file which may have empty or blank rows. I want
I want that find empty tags, here is a example txt =<lol1><><lol2> rgx =
I have a file with more than 500 000 urls. Now I want to
Let's say I have an empty XML file like so: <root></root> And I want
I know new rails apps come with an empty favicon.ico file. I want to
i want to make empty textbox checking for android. i tried try catch but
I have a csv file which I want to convert to xml but the
I have an xml file in which it is possible that the following occurs:
I have a list, which may be empty or non-empty. I want to create
I want to write the output of a specific 'top' command to a file.

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.