Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Delete directory older than n days Post 303046016 by mustfirst on Tuesday 21st of April 2020 04:40:12 PM
Old 04-21-2020
Delete directory older than n days

Code:
drwxr-xr-x 2 dbadmin dbadmin 4096 Apr 21 09:44 2020-04-17
drwxr-xr-x 2 dbadmin dbadmin 4096 Apr 21 09:44 2020-04-16
drwxr-xr-x 2 dbadmin dbadmin 4096 Apr 21 09:44 2020-04-20
drwxr-xr-x 2 dbadmin dbadmin 4096 Apr 21 12:39 2020-04-14
drwxr-xr-x 2 dbadmin dbadmin 4096 Apr 21 12:41 2020-04-15
drwxr-xr-x 2 dbadmin dbadmin 4096 Apr 21 12:44 2020-04-18
drwxr-xr-x 2 dbadmin dbadmin 4096 Apr 21 13:18 2020-04-21

I'm trying to delete directories older than 7 days. The directories are created by date every day and there are *.gz files inside. Whevener I compress or uncompress the *.gz files, the directory modified date changes to the current date and when I run the code, it won't delete it. This is what I have so far:

Code:
find ~/delete/* -type d -mtime +7 -exec cp -r '{}' ~/test \;

 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

delete files older than 7 days

can anyone tell me how I would write a script in ksh on AIX that will delete files in a directory older than 7 days? (1 Reply)
Discussion started by: lesstjm
1 Replies

2. Shell Programming and Scripting

delete file older than N days

Hi, All, I'd like to delete files older than 1 day. I thought the following command find /your_directory -mtime +1-exec rm -f {} \; will do the work, but not so, it seems like it won't delete files unless it is 2 days old or older. the files between 1 day and 2 days old does not... (7 Replies)
Discussion started by: ericaworld
7 Replies

3. UNIX for Dummies Questions & Answers

Delete files older than 30 days

This is driving me crazy. How can I delete files in a specifc directory that are over 30 days old? Thanks in advance. (3 Replies)
Discussion started by: tlphillips
3 Replies

4. Solaris

Delete files older than 30 days

Hi all, I want to delete log files with extension .log which are older than 30 days. How to delete those files? Operating system -- Sun solaris 10 Your input is highly appreciated. Thanks in advance. Regards, Williams (2 Replies)
Discussion started by: William1482
2 Replies

5. Shell Programming and Scripting

To delete logs older than 30 days

I want to write a shell script that deletes all log files in a directory that are older than 30 days except for 3 files: I am using the following command: find /tmp/logs -name "*.log" -mtime +30 -exec rm -f {} \;But this command deletes all the log files. How can i modify this script that... (5 Replies)
Discussion started by: mmunir
5 Replies

6. Shell Programming and Scripting

Delete files older than X days.

Hi All, I am using below code to delete files older than 2 days. In case if there are no files, I should log an error saying no files to delete. Please let me know, How I can achive this. find /path/*.xml -mtime +2 Thanks and Regards Nagaraja. (3 Replies)
Discussion started by: Nagaraja Akkiva
3 Replies

7. Shell Programming and Scripting

Delete files older than 10 Days in a directory

Hi All I want to remove the files with name like data*.csv from the directory older than 10 days. If there is no files exists to remove older than 10 days, It should not do anything. Thanks Jo (9 Replies)
Discussion started by: rajeshjohney
9 Replies

8. AIX

Want to delete directory, subdirectories and all files which are older than 7 days

how do i remove sub directories of a directory and all files which are older than 7 days by a single command in AIX. pls help me. I am using command as #find /gpfs1/home/vinod/hpc/ -depth -type d -mtime +7 -exec rm -rf {} \; so i want to delete all sub directories and all files from the... (1 Reply)
Discussion started by: vinodkmpal
1 Replies

9. UNIX for Dummies Questions & Answers

Delete file older than three days

I am using SFTP to transmit files from the Mainframe to an UNIX server. I am looking for some kind of script that runs with SFTP to delete tranmitted files older than 3 days. Can this be done in a SFTP transmission batch job? (5 Replies)
Discussion started by: Steve Carlson
5 Replies
ST_SNAPSHOT(1)							      systraq							    ST_SNAPSHOT(1)

NAME
st_snapshot - calculate checksum and stat ownership and permissions of files SYNOPSIS
ST_SUM=sha256sum st_snapshot patterns homepatterns DESCRIPTION
st_snapshot calculates checksums and stats ownership and permissions of critical system files. This script is typically run in either root-mode or public-mode. Running this script in root-mode requires root priviliges. One is adviced to set up a dedicated user account for running this script in public mode. In root-mode, the files snapshot_root.list and snapshot_root.homelist are typically passed as arguments. These pattern files are read by the script and contain names of files and directories; listing a directory in such a pattern file is equivalent to listing all files which live in the directorytree with this directory as root. snapshot_root.list could e.g. read # snapshot_root.list - files and directories we wanna get # monitored: we wanna get a note once these files, or any file # under these directories, gets created, gets rm-ed, gets # permissions or contents changed. these notices will not # include the possibly secret contents of these files # # this file gets read by st_systraq /etc/group /etc/gshadow /etc/hosts.allow /etc/hosts.deny /etc/hosts.equiv /etc/lilo.conf /etc/passwd /etc/postfix/server.pem /etc/shadow /etc/skel /etc/ssh Equivalent files snapshot_pub.list and snapshot_pub.homelist should be on the system. These files should contain all worldreadable to be monitored files. This allows for running this script as root only in those cases where it's needed: when reading files, readable for root only. The homelist files contain files and directories which should get monitored for every homedirectory on the system. snapshot_pub.homelist could e.g. contain: .profile .cshrc .tcshrc .login .logout .bash_profile .bashrc .exrc .nexrc As a special case, when the environment variable ST_OPHOMES is set to a non-empty string (typically when running in public mode), we stat the permissions on all homedirectories themselves. The produced snapshot is printed to stdout. The output when running in public mode could look like: # ownership and permissions of homedirs drwxr-xr-x root root /bin drwxr-xr-x root root /dev drwxr-sr-x root staff /home drwxr-sr-x joostvb joostvb /home/joostvb drwxr-xr-x root root /usr/sbin drwxr-xr-x root root /var # sha256sum of critical pub files 4d3cd13d6dbc10e2e3ccb9477cbc9eb9b76302454c276d5771ae0b10a5fbb4d2 /home/joostvb/.ssh/id_rsa.pub eb8d83e0246f761a21bdfb13a03fac634ed7c3b7dde4c2efddd7b2838d32596f /var/qmail/alias/.bashrc 4e371f9a11f5a2464d3d5c952e58e24f73b377d33767ed93b2082fcb59a647fe /etc/zlogin # ownership and permissions of critical pub files -rw-rw-r-- joostvb joostvb /home/joostvb/.ssh/id_rsa.pub -rw-r--r-- joostvb joostvb /home/joostvb/.ssh/authorized_keys ENVIRONMENT
ST_OPHOMES - non-empty in case permissions on all homedirectories should be printed ST_SUM - command for calculating file checksums. E.g. sha256sum, sha512sum, sha384sum, sha224sum or sha1sum. SEE ALSO
The systraq manual. VERSION
This manpage: $Id: st_snapshot.pod 374 2008-12-14 08:47:32Z joostvb $ COPYRIGHT
Copyright (C) 2001, 2002, 2003, 2004, 2008 Joost van Baal This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program (see COPYING); if not, check with http://www.gnu.org/copyleft/gpl.html or write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. AUTHOR
Joost van Baal <joostvb-systraq-20041015@mdcc.cx> 20081217 2008-12-15 ST_SNAPSHOT(1)
All times are GMT -4. The time now is 01:59 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy