delete all files in current directory

Posted on 2010-01-06
Last Modified: 2012-05-08
Is a command you can issue that will delete every file in the current directory only?
Question by:PeterErhard
    LVL 3

    Expert Comment

    Hope this wil help you

         rm -rf *
    LVL 68

    Accepted Solution

    Rather use
    rm -f *
    rm -r will also delete all subdirectories recursively, which is obviously not desired!
    LVL 48

    Expert Comment

    If you really want to be pedantic and *only* include files, then

    find . -type f -maxdepth 1 | xargs rm

    Author Comment

    Thanks guys.

    So, just to confirm:

    If I'm in the "/home /admin /_processed_stats" directory and run rm -f * it will only delete the files within that directory and nothing else?
    LVL 68

    Expert Comment

    LVL 2

    Expert Comment

    For goodness sakes be careful with spaces when using rm -f ;)

    rm -rf /usr/local /bin

    for example will remove /usr/local AND /bin ;) not /usr/local/bin ;)
    and Tintin's solution is the best, because it won't remove directories, just files.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
    The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now