how to remove all except one file?

How can I remove all files and folders in a directory except one perticular file?

Suppose in a folder we have files f1,f2,f3.In this I want to delete all files except f1.

can any one tel me?

thanks in advance..

ls *|grep -v f1|xargs rm -rf

Or copy f1 to /tmp, rm all the files in the current directory and move back /tmp/f1 to the current directory.

[ksh]

rm !(f1)

[zsh]

rm ^f1

[bash]

shopt -s extglob
rm !(f1)

Sorry for bumping this, but . . .

if i wanted to delete all files and/or folders inside a specific folder but keep the files and folders that start with p and m, i should do . . .

rm -R *.* !(p*) !(m*)

is that correct ?

Thanks !

After enabling the extended glob you could try something like this:

rm -r -- !(@(m|p)*)