I as a web developer I personally love to keep a ton of things in my Trash. I feel that if I deleted anything prematurely that there may be a version or an image that I can still dig out in a time of need. Sometimes, however, I want to delete something permanently, as I know for sure that there are no future uses for it. Other times, I just need a file that contains no data and is not associated with any applications. Here is a helpful terminal tip for creating and deleting files that I often find creative uses for.
A word of warning for those of you who are not familiar with the Terminal.app: Keep in mind that when using the Terminal to delete things that it is really easy to delete something that you didn’t intend to. After deleting a file with the Terminal, there is no way to retrieve it. With that in mind, be certain that the files you wish to eliminate are indeed the files you intended to remove.
Creating files with Terminal
To create a blank file with no associations or data, start by navigating to Utilities | Applications folder and double-click the Terminal.app.
Once open, you want to change your location from your User folder to the location where you would like to place the file. I’ll be using the Desktop for this example but you can place it in any location that you like.
To change your location within Terminal, simply type at the command prompt:
Type the first couple of letters of the word Desktop and press tab to auto complete the directory name.
If you want to know what directory you are in at any time, type pwd at the command prompt.
Deleting files using the Terminal
Now that we have created this filename file, lets delete it! With your Terminal still open, type the following at the command prompt:
Then Drag the file (filename) from your Desktop into the Terminal window and release. This provides the file's destination so that you don’t have to type it manually. Be sure that there is a space between rm –Rf and the directory path.
rm –Rf /Users/UserName/Desktop/filename
The command for "rm" means to remove, the flag "R" is recursive which will allow you to delete the contents of a directory, and "f" means force, causing the Terminal to delete the file regardless of the error it may cause. Remove the "f" if you don’t want to risk deleting something that may produce an error.
Once you’ve typed in the command, press return and the file will disappear from the desktop.
Wil Limoges is a Louisville, KY freelance web designer and Digital Savant at the vimarc group. He has had the pleasure of working for Apple as a Genius, loves science, and aspires to make great things!