Find the answer to your Linux question:
Results 1 to 5 of 5
Hi! I've created a bash file to move all files that end witha tilde (~) to my /home/user/.Trash directory where they are stored so I can delete or restore them ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined! Scallywag's Avatar
    Join Date
    Jul 2009
    Location
    Black Mountain, NC
    Posts
    24

    Multiple Commands Issue


    Hi!

    I've created a bash file to move all files that end witha tilde (~) to my /home/user/.Trash directory where they are stored so I can delete or restore them at a later time.

    I want to list the files that have changes within the last hour. I'm able to do that but if none have been changes, I want to print out a message stating that none of the file have been changed. I've tried multiple commands but I'm not able to print out the message.

    Here's what I have:

    # Cleanup bash file cleanup /home/user & /var/www directories
    # and sends error messages to /dev/null directory.
    clear
    find /home/user -iname 'cleanup~' -type f -exec mv '{}' /home/user/.Trash \; 2>/dev/null
    find /home/user -iname '*.*~' -type f -exec mv '{}' /home/user/.Trash \; 2>/dev/null
    find /var/www -iname '*.*~' -type f -exec mv '{}' /home/user/.Trash \;
    echo "All files cleaned up."
    echo "-----------------------------------------------------------------------------"
    echo "Last files cleaned up:"
    find /home/user/.Trash -iname '*~' -mmin -60 || echo "No new files added." -exec ls -t '{}' \; 2>/dev/null
    echo "-----------------------------------------------------------------------------"

    Can someone please tell me if this is possible or what I'm doing wrong?

  2. #2
    Linux Newbie
    Join Date
    Mar 2009
    Posts
    228
    Try this:

    Code:
    find /home/user/.Trash -iname '*~' -mmin -60 | tee /tmp/tmp.tmp ; if [ ! -s /tmp/tmp.tmp ]; then echo 'No new files added'; fi; rm -f /tmp/tmp.tmp

  3. #3
    Just Joined! Scallywag's Avatar
    Join Date
    Jul 2009
    Location
    Black Mountain, NC
    Posts
    24

    Not working the way I'd like...

    i tried the code. Creates a tmp.tmp file in the /home/user/.Trash directory. That's all...

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Newbie
    Join Date
    Mar 2009
    Posts
    228
    Since tmp.tmp wasn't created in the /tmp directory shows that you didn't copy the command correctly. Did you get all of it? Here's the command again without it being in a code block:

    find /home/user/.Trash -iname '*~' -mmin -60 | tee /tmp/tmp.tmp ; if [ ! -s /tmp/tmp.tmp ]; then echo 'No new files added'; fi; rm -f /tmp/tmp.tmp

  6. #5
    Just Joined! Scallywag's Avatar
    Join Date
    Jul 2009
    Location
    Black Mountain, NC
    Posts
    24
    I got it all that time. Works now. Thanks!

Posting Permissions

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