Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 04-16-2009, 04:46 PM   #1
Registered: Jan 2009
Posts: 51

Rep: Reputation: 17
Empty a directory

What is the easiest way to empty a directory from the command line without removing the directory itself?

Long version:
I want to put a couple of aliases in my .bashrc to empty these folders I've got from downloading data from a few lab instruments.
For example ~/lab/instruments/epic-32-random-char-folder/

I've found that deleting the whole folder is a mistake. It saves me a number of steps in the download if those long named dirs are already in place. The software that analyzes the results copies out of the directories but doesn't clear them. Long story short these dirs must be manually cleared of about a thousand files between each use.
Old 04-16-2009, 04:49 PM   #2
LQ Guru
Registered: Nov 2006
Location: Belgium
Distribution: Ubuntu 11.04, Debian testing
Posts: 5,019

Rep: Reputation: 130Reputation: 130
rm *? If the folder does not contain any subdirectories, that is.

Last edited by jay73; 04-16-2009 at 04:50 PM.
Old 04-16-2009, 05:22 PM   #3
LQ Guru
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678

Rep: Reputation: 122Reputation: 122
rm -rf ~/lab/instruments/epic-32-random-char-folder/*
Old 04-16-2009, 11:19 PM   #4
Registered: Jan 2009
Posts: 51

Original Poster
Rep: Reputation: 17
Originally Posted by billymayday View Post
rm -rf ~/lab/instruments/epic-32-random-char-folder/*


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
rm: cannot remove directory `ff': Directory not empty blancs Linux - General 17 08-29-2011 01:47 PM
large directory while it is empty Mrjas Linux - General 17 12-05-2007 02:35 AM
The postgresql data directory content in the pgsql directory is lost (empty data dir) kisembo Linux - Software 1 02-13-2006 01:11 PM
Empty directory contents stefaandk Linux - General 1 08-22-2005 07:03 AM
deleting non-empty directory sadiboyz Linux - Newbie 2 04-21-2003 09:29 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:10 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration