Unix/Linux Go Back    



Rm all files but two

Shell Programming and Scripting




Kindly Note - This is a Single User Post by Forum Member mohtashims Regarding:
Rm all files but two.
Please Follow The Primary Link Above to View the Full Discussion.

   
Old Unix and Linux 07-12-2017   -   Original Discussion by mohtashims
mohtashims's Unix or Linux Image
mohtashims mohtashims is offline
Registered User
 
Join Date: Jun 2011
Last Activity: 3 November 2017, 12:11 PM EDT
Posts: 779
Thanks: 204
Thanked 7 Times in 7 Posts
Quote:
Originally Posted by MadeInGermany View Post
Turn on extended globbing first:

Code:
shopt -s extglob

Still, I cannot see it working. Below is the error.


Code:
bash-3.2$ shopt -s extglob
 bash-3.2$ rm -rf /tmp/data/* !(@(output.txt))
rm: cannot read directory enav/output: Permission denied
rm: Unable to remove directory enav: File exists
rm: Unable to remove directory hsperfdata_u543267: Permission denied
rm: Unable to remove directory hsperfdata_vbarne: Permission denied

Strangely along with the error the /tmp/data/ folder itself gets deleted.

Last edited by mohtashims; 07-12-2017 at 04:04 PM..