Answers for "linux remove every file in folder except most recent"

CSS
1

bash remove all files in directory except a few

## Ensure you enable this first!
shopt -s extglob

## Delete all file except file1 ##
rm  !(file1)
 
## Delete all file except file1 and file2 ##
rm  !(file1|file2) 
 
## Delete all file except all zip files ##
rm  !(*.zip)
 
## Delete all file except all zip and iso files ##
rm  !(*.zip|*.iso)
 
## You set full path too ##
rm /Users/vivek/!(*.zip|*.iso|*.mp3)
 
## Pass options ##
rm [options]  !(*.zip|*.iso)
rm -v  !(*.zip|*.iso)
rm -f  !(*.zip|*.iso)
rm -v -i  !(*.php)
Posted by: Guest on February-28-2022
1

linux remove files except

/* " Be Careful !!! This will delete your folders recursively !!! " 
The below script was used to remove all files exept the last 5 in a pipline 
The ls -1v sorts the folders ascending by number. 
*/
sudo ls -1v | head -n -5 | xargs rm -r
Posted by: Guest on September-09-2021

Code answers related to "linux remove every file in folder except most recent"

Browse Popular Code Answers by Language