Sponsored Content
Operating Systems Linux Ubuntu Delete all files that match date '+%Y-%m-%d_%H:%M' Post 303031301 by drew77 on Monday 25th of February 2019 04:28:21 PM
Old 02-25-2019
Delete all files that match date '+%Y-%m-%d_%H:%M'

I need to modify this so it delete all date files and not leave the 2 newest.


Code:
TARGET_DIR='/media/andy/MAXTOR_SDB1/Ubuntu_Mate_18.04/'
REGEX='[0-9]{4}-[0-9]{2}-[0-9]{2}_[0-9]{2}:[0-9]{2}'   # regular expression that match to: date '+%Y-%m-%d_%H:%M'
LATEST_FILE="$(ls "$TARGET_DIR" | egrep "^${REGEX}$" | tail -1)"
find "$TARGET_DIR" ! -name "$LATEST_FILE" -type f -regextype egrep -regex ".*/${REGEX}$" -exec rm -f {} +
rsync --progress -r -u /media/andy/MAXTOR_SDB1/Ubuntu_Mate_18.04/* /home/andy/Ubuntu_18.04_Programs/

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

how to delete files by date

My apache logs are saved in the following format (using rotatelogs): Oct 8 01:59 access_log.1002412800 Oct 9 01:55 access_log.1002499200 Oct 10 01:58 access_log.1002585600 Oct 11 01:56 access_log.1002672000 Oct 12 01:59 access_log.1002758400 I would like to run a cronjob once a week to... (2 Replies)
Discussion started by: jamesbond
2 Replies

2. UNIX for Dummies Questions & Answers

Delete files by date

Hi, Can anyone help me delete old files in a directory? Let's say, I want to delete all files which are 365 days old. Thank you. (2 Replies)
Discussion started by: risk_sly
2 Replies

3. Solaris

Delete files according to date

Hi All, I am wondering whether is there a way to remove files according to date. For example, I have 500 files between Jan - April, and I want to remove files created only on March. Is there any way to do this? Thanks in advanced. rgds, Ronny (2 Replies)
Discussion started by: ronny_nch
2 Replies

4. Shell Programming and Scripting

find files for a particular date and delete

How can I delete files for a particular date ? I apologize in advance If there is solution please put the link. Thanks, (5 Replies)
Discussion started by: jville
5 Replies

5. Shell Programming and Scripting

Delete files by date

Hello, Due to an error while processing data I have to delete all files created the 4 october on a RED HAT 3 Server. I am wondering if one of you is aware of a command that could only delete all files that were created the Oct 4 This will be very, very, very helpful Thanks for your... (6 Replies)
Discussion started by: Aswex
6 Replies

6. Shell Programming and Scripting

Delete log files content older than 30 days and append the lastest date log file date

To delete log files content older than 30 days and append the lastest date log file date in the respective logs I want to write a shell script that deletes all log files content older than 30 days and append the lastest log file date in the respective logs This is my script cd... (2 Replies)
Discussion started by: sreekumarhari
2 Replies

7. UNIX for Dummies Questions & Answers

Delete files of a particular date

dear all, i m a newbie and i want to delete all files of a particular date,how can i do this? your help appreciated,thanks in advance. OS:RHEL 6 (5 Replies)
Discussion started by: mdabdul
5 Replies

8. UNIX for Dummies Questions & Answers

How to delete all the files older than a date?

Hi, I need a command for deleting all the compress files *.Z that are older than the current date - 5 days. Basically I have a directory where daily I meet some back up files and I want to remove automatically the ones 5 days (or more) older than the current date. How can I write a 'rm' command... (1 Reply)
Discussion started by: Francy
1 Replies

9. UNIX for Dummies Questions & Answers

Delete Files from a date

I'm quite new to Unix but I want to delete some old backup files stored in a directory. the backups are stored on a network storage device located at /mnt/terastation12/backup. I want to delete everything upto one month ago. would the following command in Unix Sun do that? find... (5 Replies)
Discussion started by: dbajtr
5 Replies

10. UNIX for Beginners Questions & Answers

Count the number of files to delete doesnt match

Good evening, need your help please Need to delete certain files before octobre 1 2016, so need to know how many files im going to delete, for instance ls -lrt file_20160*.lis!wc -l but using grep -c to another file called bplist which contains the list of all files backed up doesn match... (7 Replies)
Discussion started by: alexcol
7 Replies
AUTOTRASH(1)						      General Commands Manual						      AUTOTRASH(1)

NAME
autotrash -- program to automatically purge old files from the FreeDesktop.org trash SYNOPSIS
autotrash [-d purge_n_days_old] autotrash [--delete number_of_megabytes_to_purge] autotrash [--keep-free number_of_megabytes_to_free] DESCRIPTION
autotrash is a program that looks in a FreeDesktop.org Trash folder for information on it's contents and then purges a part of the trash depending on the options. The most common option is -d, which will purge files that have been in the trash for more then a given number of days. The option --delete will remove at least the given number of megabytes from the trash, removing the oldest trash first. Using --keep-free will make sure at least the given number of megabytes of free space is available, by automatically setting --delete to the right value. For example, to keep at least a 1GB of free space, removing files from the trash if needed, use autotrash --keep-free 1024 . OPTIONS
This program follows the usual GNU command line syntax, with long options starting with two dashes (`-'). -h --help Show a summary of options. -d DAYS --days DAYS Purge files older than DAYS number of days. -T PATH --trash-path PATH Use the given path as the location of the Trash directory, instead of the default: ~/.local/share/Trash . --max-free M Only purge files if there is less than M megabytes of free space left at the trash location. As an example, if you set this to 1024, then autotrash will only start to work if there is less than 1GB of free space in the trash. Till that time, autotrash will just exit normally without scanning the Trash directory. If unsure, try running autotrash with --dry-run and --verbose to see the effect. --delete M Purge at least M megabytes, deleting oldest trash addition first. It uses trash entries, NOT individual files. This means that if your oldest trashed item is a 1GB directory, and you request at least 10MB to be removed (M=10), autotrash will remove 1GB. If unsure, try running autotrash with both --dry-run and --stat to see the effect. --min-free M --keep-free M Make sure there is a minimum of M megabytes of free space. If there is less free space, set --delete to the difference between M and the amount of free space. If unsure, try running autotrash with --dry-run and --verbose to see the effect. -D REGEX --delete-first REGEX Purge any file which matches REGEX first, regardless of it's time-stamp. REGEX must be a valid regular expression. If this option is used multiple times, the files matching the first regular expression are deleted first, then the second etc. Example, delete any *.avi files first, then by age: --delete-first '.*.avi' -v --verbose Output information on what is happening and why. -q --quiet Only output warnings. --check Report .trashinfo files that point to a non-existing file. This will only happen with a broken Trashcan. It is left up to the user to actually do something with this information. These files will be removed as soon as the mentioned file would be removed by autotrash. --dry-run Only list what would be done, but actually do nothing. --stat Show the number, and total size of files involved. -V --version Show the version of program. EXAMPLES
Examples of program use. autotrash -d 30 Purge any file that has been in the trash for more then 30 days. autotrash --max-free 1024 -d 30 Only purge files from the trash if there is less than 1GB of space left on the trash filesystem. If so, only trash files that are older than 30 days. autotrash --min-free 2048 Purge files from trash, oldest first, till there is at least 2GB of space on the trash filesystem. There is no restriction on how old trashed files are. autotrash --min-free 2048 -D '.*.bak' -D '.*.avi' Purge files from trash till there is at least 2GB of space on the trash filesystem. If we need to remove files, make sure we remove *.bak files first, then all *.avi files and after that the oldest to the newest. There is no restriction on how old trashed files can get. Please note that '.*.bak' and '.*.avi' are regular expressions and not glob patterns. Given that they are regular expressions, using -D '.*.(png|gif|jpg|jpeg)' will match images with any of the given extensions. autotrash --max-free 4000 --min-free 2048 -d 30 Start reading the trash if there is less than 4000MB of free space, then start keeping an eye on. At that point, remove files older than 30 days and if there is less than 2GB of free space after that remove even newer files. @hourly /usr/bin/autotrash --max-free 4000 --min-free 2048 -d 30 Experienced users should consider adding autotrash as a crontab entry, using crontab -e and adding the line above. AUTHOR
This manual page was written by A. Bram Neijt bram@neijt.nl for the Debian system (and may be used by others). Permission is granted to copy, distribute and/or modify this document under the terms of the GNU General Public License, Version 3 or any later version published by the Free Software Foundation. On Debian systems, the complete text of the GNU General Public License can be found in /usr/share/common-licenses/GPL. AUTOTRASH(1)
All times are GMT -4. The time now is 04:30 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy