Find and remove files

Hi,
I was given a task to do some housekeeping of users directory
Basically, the structure is of below.
/User DIR
---UserA
---UserB
---UserC
---UserD
---UserE
Each user contain several type of files.
I wan to do a housekeep of the directories to remove *.txt, *.log, *.wk1 that are more than 5 days old.
Pls kindly assist.
i need to search for several type of extension .wk1 , .log , .txt etc. how do i incorporate it in? . Another thing is
ls -l | find . -name "*.txt" -mtime +3 -exec ls {} \; it actually returns me all the subdirectories as well. y is that so?
in my office, i have existing scripts that have similiar syntax
find . ! -type d -ctime -5 -name '*.txt' -exec ls {} \;
find . ! -type d -ctime -5 -name '*.txt' -exec rm -f {} \;
what does find . ! -type d means?
Pls kindly assist.

cghcgh wrote:
echo "\n Foldername = ${DIRNAME}"
cd ${DIRNAME}
USERFILE=`ls -1 *.xls *.wk1 *.txt`
for USERFILENAME in ${USERFILE}; do
echo "\n Checking whether file is more than 7 days"
echo " Filename = ${USERFILENAME}"
echo " Removing this file = `find . -mtime +${KEEP} -a -name ${USERFILENAME} -exec ls -l {} \;`"
find . -mtime +${KEEP} -a -name ${USERFILENAME} -exec rm
UGH You are looking for files with an ls, then going back and running two separate finds for every file. But every find will do a full descent/search run of all data in that directory. That's horribly inefficient. The more data under that directory and the more files the 'ls' hands off, the more time and IO it will consume.
Why not just replace that section above with:
echo "\n Foldername = ${DIRNAME}"
find ${DIRNAME} ! -type d \(-name "*.xls" -o -name "*.wk1" -o -name "*.txt" \) -mtime +${KEEP} -exec rm {} +
One find, no 'ls', no problems with spaces.
Add in a '-print' before the '-exec' if you want to print or capture the filenames as you're removing them.
Darren

Similar Messages

  • HT2905 No Display Duplicates under File. How to find and remove duplicate items in your iTunes library

    I now have iTunes ver 11.0.4.4 under Windows 7. I lost all iTunes stuff when updating to Windows 7. I have loaded thousands amd thousands of music files from backup disks, but there are many duplicates. I am attemping to re-establish my old library. I used to be able to remove duplicates quickly with the old iTunes. The new iTunes doesn't seem to offer the same service. Is there any way to remove duplicates quickly, or must I do it one by one?

    When deduping use Shift > View > Show Exact Duplicate Items as this is normally a more useful selection. You need to manually select all but one of each group to remove. Sorting the list by Date Added may make it easier to select the appropriate tracks. If you have multiple entries in iTunes connected to the same file on the hard drive then don't send to the recycle bin. Use my DeDuper script if you're not sure, don't want to do it by hand, or want to preserve ratings, play counts and playlist membership. See this thread for background and please take note of the warning to backup your library before deduping.
    (If you don't see the menu bar press ALT to show it temporarily or CTRL+B to keep it displayed)
    See also HT2905: How to find and remove duplicate items in your iTunes library
    tt2

  • How to find and remove corrupted files?

    Hi,
    Can anyone give me some direction in locating and removing files that have been corrupted? I am trying to back up my system for the first time on time machine, and keep getting an error message. I visited an Apple store today for support and had them reformat my external drive. I am able to start the backup, but it quits and gives me an error message.
    Thanks!

    fatchay wrote:
    my HD needs to be repaired and that I have an invalid directory count. Is this why I can't backup?
    Run Repair Disk: Boot from install disc (insert disc>restart>immediately hold down c key and keep holding it until you see “Preparing Installation”)>at first screen select the language and click Continue> click on the Utilities Menu in the menu bar>open Disk Utility>select your HD in the panel on the left side>click Repair Disk at bottom of main window. Run this at least twice, and keep running it until it says “appears ok” twice in a row. If that doesn’t happen, you may need a stronger utility such as DiskWarrior or if the directory is damaged beyond repair, you may need to reinstall the OS, or you may have a damaged HD (repair utilities can only repair the directory structure, not the HD itself).

  • On my MacBook with Lion Safari does start, does not react immediately after trying to open it. Installing a new Safari does not help. Removing parts of Safari in the Library did not help. Where can I find and remove all components (LastSession ...)?

    How can I reset Safari with all components? On my MacBook with Lion, Safari does not start, does not react immediately after trying to open it. Installing a new Safari does not help. Removing parts of Safari in the Library does not help. Where can I find and remove all components as LastSession and TopSites?

    The only way to reinstall Safari on a Mac running v10.7 Lion is to restore OS X using OS X Recovery
    Instead of restoring OS X in order to reinstall Safari, try troubleshooting extensions.
    From the Safari menu bar click Safari > Preferences then select the Extensions tab. Turn that OFF, quit and relaunch Safari to test.
    If that helped, turn one extension on then quit and relaunch Safari to test until you find the incompatible extension then click uninstall.
    If it's not an extensions issue, try troubleshooting third party plug-ins.
    Back to Safari > Preferences. This time select the Security tab. Deselect:  Allow plug-ins. Quit and relaunch Safari to test.
    If that made a difference, instructions for troubleshooting plugins here.
    If it's not an extension or plug-in issue, delete the cache.
    Open a Finder window. From the Finder menu bar click Go > Go to Folder
    Type or copy paste the following
    ~/Library/Caches/com.apple.Safari/Cache.db
    Click Go then move the Cache.db file to the Trash.
    Quit and relaunch Safari to test.

  • How to find and remove any special character in filename?

    I have a files in various Windows Servers 2003 with a special character at his names, who are causing problem with backup software, i don´t know what character is because in explorer they are not shown and in command line they are shown only as interrogation
    mark and for this, i don´t know how i will find and remove then.
    Thanks.

    Hi,
    I agree with Dave. We can try using
    chkdsk utility to check the file system and file system metadata of a volume for logical and physical errors.
    Regarding
    chkdsk, the following article can be referred to for more information.
    Chkdsk
    http://technet.microsoft.com/en-us/library/cc730714.aspx
    Best regards,
    Frank Shen

  • How can I find and remove duplicate photos in iPhoto?

    What is the best way to find and remove duplicate photos in iPhoto?

    Are you seeing these duplicates in iPhoto or via the Finder?  If it's in the iPhoto window then you can use one of these applications to identify and remove duplicate photos from an iPhoto Library:
    iPhoto Library Manager - $29.95
    Duplicate Cleaner for iPhoto - free
    Duplicate Annihilator - $7.95 - only app able to detect duplicate thumbnail files or faces files when one library has been imported into another with iPhoto 8 and earlier.
    PhotoSweeper - $9.95 - This app can search by comparing the image's bitmaps or histograms thus finding duplicates with different file names and dates.
    I also prefer iPLM as it is more than just a dup finder.  It's a the most versatile iPhoto utility available.
    OT

  • HT2905 how do i find and remove duplicate songs in itunes 11.1.3?

    i transferred my itunes to a new computer today, and somehow half of my library was duplicated. no i cant seem to find a way to get rid of the duplicates without selecting them one at a time. any ideas?

    Apple's official advice on duplicates is here... HT2905: How to find and remove duplicate items in your iTunes library. It is a manual process and the article fails to explain some of the potential pitfalls.
    Use Shift > View > Show Exact Duplicate Items to display duplicates as this is normally a more useful selection. You need to manually select all but one of each group to remove. Sorting the list by Date Added may make it easier to select the appropriate tracks, however this works best when performed immediately after the dupes have been created.  If you have multiple entries in iTunes connected to the same file on the hard drive then don't send to the recycle bin.
    Use my DeDuper script if you're not sure, don't want to do it by hand, or want to preserve ratings, play counts and playlist membership. See this thread for background and please take note of the warning to backup your library before deduping.
    (If you don't see the menu bar press ALT to show it temporarily or CTRL+B to keep it displayed)
    Alternativey see this migrate iTunes library post, you may want to revisit the transfer method.
    tt2

  • Hi , how do i find and remove duplicate videos and photos on my ipad2 , please help

    Hello , i have an apple ipad 2 , and iphone 4s and 5s . I have transferred all videos and photos on both these phones to the ipad to make space on my iphones. I have no doubt that there is now multiple duplicates on my ipad . How can i find and remove these. Please help should you know !

    i imported all the files in my sd card to my mac and then i did format the card, it says 160kb is used up.
    I also did find files in the trash when i connected the camera to the macbook and deleted them all, there is nothing left in the camera or the trash and it still says 160kb used :/

  • How to find and remove specific email messages

    I just read an article about a health department employee inadvertently sending a confidential e-mail to 800 users. The IT department shutdown the mail server and wihin an hour removed all copies of the message from the system.
    I asked myself, if that happened here, how would I do that? I could shutdown the Messaging Server, but not sure what to do after that.
    How would you identify, find, and remove a particular e-mail message from everyone's inbox?
    $ imsimta version
    iPlanet Messaging Server 5.2 HotFix 1.26 (built Mar 31 2004)

    Well, each message is stored as a simple text file in the store. Assuming unix, you could do a pretty simple find and grep, looking for a key phrase. exec rm from that, and you're done....
    After such brute force methods, you do need to run
    reconstruct -r

  • My external hard drive is 'seen' by my iMac and I can go into the Finder and open files and folders. I am using the hard drive for Time Machine back up. However Time Machine says it can't find the drive. Same thing has happened with Final Cut Express.

    My new LaCie external hard drive is 'seen' by my iMac and I can go into the Finder and open files and folders. I am using the hard drive for Time Machine back up. However Time Machine says it can't find the drive.
    The same thing happened recently between Final Cut Express and my other LaCie external hard drive used as the Scratch disk. It fixed itself.
    I've run out of ideas. Help would be very much appreciated. Thanks.

    have you done some searches on FCPx and time machine? Is there a known issue with using a TM drive with FCPx? dunno but ...wait...I'll take 60 sec for you cause I'm just that kind of guy....   google...." fcpx time machine problem"  Frist page link 
    http://www.premiumbeat.com/blog/fcpx-bug-best-practices-for-using-external-hard- drives-and-final-cut-pro-x/
           You cannot have time machine backups on your hard drive if you intend to use it in FCPX.
    booya!

  • How do I find and remove duplicates on the 11.2 itunes?

    How do I find and remove duplicates on the 11.2 itunes?

    duplicate annihaitor
    But often duplicates are a symptom and you really need to address the cause - more information is needed to help out with that
    LN

  • I can't seem to open (view) my photos.  I get an error message that says "the file couldn't be opened because you don't have permission to view it. To view or change permission, select the item in the finder and choose File. Get info."

    I can't seem to open (view) my photos.  I get an error message that says "the file couldn't be opened because you don't have permission to view it. To view or change permission, select the item in the finder and choose File. Get info."  I have never had this happen before?  Thanks!

    Try the following:
    1 - launch iPhoto with the Command+Option keys held down and rebuild the library.
    2 - Run Option #1, Repair Permissions.
    OT

  • Cannot reinstate catalog after returning PC (Windows 7) to factory settings (because of worm infection). Catalog was backed up on external drive but not using PSE backup facility. Cannot find and *.tly file. Is this hopeless?

    Cannot reinstate catalog after returning PC (Windows 7) to factory settings (because of worm infection). Catalog was backed up on external drive but not using PSE backup facility. Cannot find and *.tly file. Is this hopeless?

    If you made backups of all of your photos and your catalog file using some third-party method (i.e. not using the PSE catalog backup command), then you should be able to restore everything.
    Step 1. Put the photos in the EXACT SAME LOCATION as before. For example, if they were in subfolders of C:\Users\<username>\Documents, then they must go into the exact same subfolders of C:\Users\<username>\Documents.
    Step 2. Move the catalog file to wherever you want it to be, and then double-click on it.

  • I can not open documents I get a message that says To view or change permissions, select the item in the Finder and choose File Get Info.  help

    I have a mac with os X.  I have saved documents and photos on my computer and am now not able to open them.  I get a message that tells To view or change permissions, select the item in the Finder and choose File > Get Info.  I do that and it is not locked.  confused.  help

    In the Info window it's this:
    Do you have read and write privileges?

  • How can I find and remove viruses from my mac

    I fear that I might have a virus on my beloved macbook pro. i message was spassing out and not sending my messages, my folders continue to dissapear from my desktop causing me to restart finder (not a big deal just annoying) and some other out-of-place things are happening. I don't like credit cards so i can't buy any intvirus software so I was curious to know if there is a way to search for, find, and remove this potential virus on my own.

    Apple provides and updates malware protection as part of the operating system functionality. There is no application you need to run. In using Macs in the corporate world and privately over the last 20+ years, the only malware that got into a Mac came from a shared MS Word document. That was in 1994.
    Everytime that I chose to run a commercial or opensource anti-virus tool, a full sweep showed no infections.
    There may be other systemic issues with your Mac that are the root cause for what you describe. As a baseline, I would do the following:
    Run /Applications/Utilities/Disk Utility. On your boot disk, choose First Aid, and verify/repair permissions.
    Reboot your Mac. Immediately press and hold the shift key until a login screen appears. Enter your login name, your password, and before continuing, press and hold the shift key again, until your desktop reappears.
    Reboot normally.
    What effect do the above have on the problems you mentioned?

Maybe you are looking for