Skip to main content
  1. Archives/

Remove all files but one with rm

··94 words·1 min·
Tips & How-To's Terminal Tips-and-Howto's Tutorials

Is there any way to remove all of the files in a directory except for one with a certain filename? For instance, if I had a directory containing the files file1, file2, and dontdelete. Would there be any way to quickly delete file1, and file2 and not dontdelete? I know that I could just do rm file1 file2 but that wouldn’t work for a bunch of files. Also, I’m on Mac OS X if that makes a difference

via command line - Remove all files but one with rm - Super User.

Nice tip.

Sathyajith Bhat
Author
Sathyajith Bhat
Author, AWS Container Hero and DevOps Specialist.

Related

Removing file named -rf in Unix
··66 words·1 min
Tips & How-To's Commands Linux Tutorials
I did something crazy at some point that created a file called “-rf” on my filesystem. Now I can’t figure out how to delete it. I’ve tried rm "-rf" rm \-rf But these just exit immediately. Arrgh! Anyone know how to remove this file? Preferably without accidentally cleaning out my whole folder. heh. What’re the odds, eh? via Removing “-rf” file in Unix - Super User.
Five tips for a more efficient Linux desktop | Five Tips | TechRepublic.com
··130 words·1 min
Linked Commands Cover Find Linux Open Source Tips Tips-and-Howto's Tutorials
1: The pager I am always shocked at how few people actually use the Linux pager. It’s been around forever and has always served the same functionality — it offers the user multiple desktops to keep the desktop better organized. I employ the pager like this: With four workspaces, I dedicate each workspace to a different use. My layout looks like this: Desktop 1 is for networking tools. Desktop 2 is for writing/office tools.
Get Kannada Language displayed properly in Gentoo and Sabayon
··96 words·1 min
News Indic Linux Terminal Tutorials
Well I was browsing through some Kannada sites the other day and all I got was big blocks. Turned out that Gentoo and Sabayon didn’t have support for displaying Kannada characters, though, I had no such problems with Hindi & Bengali characters [amongst others]. Changing the Character encoding in Firefox to Auto-detect or Unicode didn’t work either. After doing a bit of searching, found the solution. So open the terminal, switch to root user and type