How to delete files older than 2 days in Bash?

How to delete files older than 2 days in Bash?

Additionally check file times with ‘stat filename’ Note: mtime can be replaced with mmin for better control as mtime discards all fractions (older than 2 days (+2 days) actually means 3 days ) when it deals with getting the timestamps of files in the context of days Not the answer you’re looking for?

How to tar certain file types in all subdirectories?

Use “find” and “grep” to get all path of .php and .html files in all directory and its sub-directories. Then pass those path information to tar to compress. Please be careful with those symbol ` and ‘. Note also that this will hit the limit of how many characters your shell will allow on the command line, unlike some of the other answers.

How to delete shell scripts back to current date?

Closed 7 years ago. I’m new to shell scripts, can anyone help? I want to delete scripts in a folder from the current date back to 10 days. The scripts looks like: The script will run in every 10 day with Crontab, that’s why I need the current date. -delete no surprise. Remove it to test your find filter before executing the whole command

How to extract specific file ( s ) from tar.gz?

-z: filter archive through gzip, use to decompress .gz files. Let’s assume you have a tarball called lotsofdata.tar.gz and you just know there is one file in there you want but all you can remember is that its name contains the word contract.

How to find and delete files older than X days in Linux?

Find and Delete Files Older Than X Days In Linux. First, let us find out the files older than X days, for example 30 days. To do, so, just run: $ find . -mtime +30 -print. The above command will find and display the older files which are older than 30 day in the current working directorys. Here,

Is there a way to find and delete files?

(It may need to run rm -f a few times if you have thousands of files.) This tells find itself to delete the files, without running rm . This may be infinitesimally faster than the -exec variants, but it will not work on all systems.

How to find and remove files older than 30 days?

-name . -prune \\ -name ‘*.txt’ ! -type d -mtime +30 -print -exec rm -f {} + | grep ‘^’ > /dev/null || echo >&2 No text files to del The grep is to check whether find produces any output (no errors) so we output the No text files to del message if it didn’t (remove the > /dev/null if you do want to see the files that we attempt to delete).