Answers for "delete all the files except one in linux"

3

how to remove all files except one in linux

# if you are using a loop

shopt -s extglob

rm -rf !("abc.txt" | "abc.log" )  # others will be removed except these two
OR
rm -v !(*.zip|*.odt)

shopt -u extglob
Posted by: Guest on December-10-2020
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 "delete all the files except one in linux"

Code answers related to "Shell/Bash"

Browse Popular Code Answers by Language