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
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
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
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us