Home > OS >  Shell removed and keep the latest 10 files
Shell removed and keep the latest 10 files

Time:10-09

N as shown in figure: each name of the zip package, you need to remove the zip package, each name (aaa, BBB, CCC and DDD) keep only the latest ten zip
Not to write their own execution: ls -t | awk -f '-' '{the if (NR> 11) {print $1}} '| xargs rm -f

Aaa - 1.0.0-1. Zip
Aaa - 1.0.0-2. Zip
Aaa - 1.0.0-3. Zip
Aaa - 1.0.0-4. Zip
Aaa - 1.0.0-5. Zip
.
Aaa - 1.0.0-20. Zip
BBB - 1.0.0-1. Zip
BBB - 1.0.0-2. Zip
BBB - 1.0.0-3. Zip
BBB - 1.0.0-4. Zip
BBB - 1.0.0-5. Zip
.
BBB - 1.0.0-50.zip
CCC - 1.0.0-1. Zip
CCC - 1.0.0-2. Zip
CCC - 1.0.0-3. Zip
CCC - 1.0.0-4. Zip
CCC - 1.0.0-5. Zip
.
CCC - 1.0.0-80. Zip
DDD 1.0.0-1. Zip
DDD 1.0.0-2. Zip
DDD 1.0.0-3. Zip
DDD 1.0.0-4. Zip
DDD 1.0.0-5. Zip
.
DDD 1.0.0-100. Zip

CodePudding user response:

General backup is according to the days or weeks, months,

According to the days is simple:
The find. - the name "aaa" *.zip "- mtime + 10
The find. - the name "BBB" *.zip "- mtime + 10
The find. - the name "CCC" *.zip "- mtime + 10
The find. - the name "DDD" *.zip "- mtime + 10

CodePudding user response:

reference 1st floor zyzy257 response:
general backup is according to the days or weeks, months,

According to the days is simple:
The find. - the name "aaa" *.zip "- mtime + 10
The find. - the name "BBB" *.zip "- mtime + 10
The find. - the name "CCC" *.zip "- mtime + 10
Find. - the name "DDD" *.zip "- mtime + 10


But too many package, a a delete too much trouble, want to bulk delete; Must have at least five centuries zip for different names

CodePudding user response:

If it is a standard xyz *.zip, can consider to take the first three regular alpha into an array, and then traverse, according to the 1st floor method to do,

CodePudding user response:

Ls -t | awk -f '-' '{the if (NR> 3) {print $1}} '| xargs -i rm -f {} \;
  • Related