advanced deletion

How can i delete the contents of the directory except one file?

Move or Copy the one file to somewhere else, then delete everything.

More details about the names of your files might allow someone to create an rm command which helps.

Or...

ls -1 | grep -v "^MY_FILE$" | xargs rm -f

or

ls -a1 | grep -Ev "^(\.|\.\.|MY_FILE)$" | xargs rm -f

The list of files in the directory is:
EDF
EDFINSTALLER.sh
EDF.tar.gz
abcd.bin

I don't want to delete EDFINSTALLER.sh

find . -type f \( -name . -o -prune -a ! -name EDFINSTALLER.sh \) -exec echo rm {} \;

If that's what you want just remove the echo

What is the function of echo here?

---------- Post updated at 07:58 AM ---------- Previous update was at 07:53 AM ----------

I just forgot to mention that EDF is a folder

ls -1 | grep -v "^MY_FILE$" | xargs -I{} rm -f {} 2>/dev/null

For safety we use echo to see what files will be deleted.

Thanks

Evrything is deleted except the folder "EDF". I want to delete that too

ls -1 | grep -v "^EDFINSTALLER\.sh$" | xargs rm -rf