Find the answer to your Linux question:
Results 1 to 3 of 3
I was asked to make a program in Linux(Ubuntu) that removes all empty files in the current directory. I've got an idea on how to do it, but for some ...
  1. #1
    Just Joined!
    Join Date
    Nov 2010
    Posts
    1

    Help with Linux Script!

    I was asked to make a program in Linux(Ubuntu) that removes all empty files in the current directory. I've got an idea on how to do it, but for some reason it's not working as I planned,since the brackets from the if statements are giving me an error.

    [: 6: find: unexpected operator

    This is my program:

    #!/bin/bash
    if [ find . -type f -size 0 ]
    then
    find . -type f -size 0 | xargs rm -r
    echo "The empty files have been deleted"
    else
    echo "There are no empty files in this directory
    fi

    I really need this done ASAP Pls
    Last edited by eltiti55555; 11-23-2010 at 10:50 PM.

  2. #2
    Just Joined! barriehie's Avatar
    Join Date
    Apr 2008
    Posts
    81
    Quote Originally Posted by eltiti55555 View Post
    I was asked to make a program in Linux(Ubuntu) that removes all empty files in the current directory. I've got an idea on how to do it, but for some reason it's not working as I planned,since the brackets from the if statements are giving me an error.

    [: 6: find: unexpected operator

    This is my program:

    #!/bin/bash
    if [ find . -type f -size 0 ]
    then
    find . -type f -size 0 | xargs rm -r
    echo "The empty files have been deleted"
    else
    echo "There are no empty files in this directory
    fi

    I really need this done ASAP Pls
    Code:
      if [ $(find . -type f -size 0) ]
    or you could enclose in backticks, `, I find the $() easier to read.

  3. #3
    Super Moderator MikeTbob's Avatar
    Join Date
    Apr 2006
    Location
    Texas
    Posts
    7,144
    Hello and Welcome.
    Were you asked by a teacher? This smells of homework to me and that is forbidden. I'll be keeping an eye on this thread.
    I do not respond to private messages asking for Linux help, Please keep it on the forums only.
    All new users please read this.** Forum FAQS. ** Adopt an unanswered post.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...