Sample Header Ad - 728x90

Remove all files/directories except for one file

444 votes
10 answers
790865 views
I have a directory containing a large number of files. I want to delete all files except for file.txt . How do I do this? There are too many files to remove the unwanted ones individually and their names are too diverse to use * to remove them all except this one file. Someone suggested using rm !(file.txt) But it doesn't work. It returns: Badly placed ()'s My OS is Scientific Linux 6. Any ideas?
Asked by Kantura (4925 rep)
Sep 5, 2014, 01:59 AM
Last activity: Nov 1, 2024, 06:21 PM