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: 21 June 2018, 3:55 AM EDT
Posts: 801
Thanks: 213
Thanked 7 Times in 7 Posts
Originally Posted by MadeInGermany View Post
Turn on extended globbing first:

shopt -s extglob
Still, I cannot see it working. Below is the error.

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 03:04 PM..