Web Hosting Forum Login
Not a member yet? Sign up

How to delete all files and folders in current directory using Linux commands?

  • FORUMS
  • WEB DESIGN
  • WEB HOSTING OFFERS
  • ADVERTISING
  • WEB HOSTING
  • REQUEST A HOST
  • BEST WEB HOSTING
  • QUICK MENU
  • REGISTER HERE - Join us for FREE
Results 1 to 8 of 8
  1. #1
    Join Date
    May 2016
    Posts
    98
    Thanks
    44
    Thanked 2 Times in 2 Posts
    Thumbs Up/Down
    Received: 9/0
    Given: 155/0

    How to delete all files and folders in current directory using Linux commands?

    I am trying to remove all files and sub directories in a directory but I only want to remove all files and sub folders, excluding the top directory itself.
    For example, I have a top directory like cPanel and it contains the files as system.log, gmp.sys and five folders, in this five folders, there are many sub folders.
    Now I want to delete all files in cPanel directory and all folders and sub folders in it.
    I am at root folder. How can I do this in Linux and using commands only?

  2. #2
    Join Date
    Jul 2016
    Location
    Hertfordshire, UK
    Posts
    894
    Thanks
    40
    Thanked 176 Times in 147 Posts
    Thumbs Up/Down
    Received: 443/3
    Given: 136/4
    If you want to remove the folder with all its contents (including all interior folders)

    rm -rfi /root/directory/*

    This will remove everything above /root/directory/ but leave the /root/directory/ empty but not deleted.

    I added the -i to ask for approval on every delete for safety, if the directory contains hundreds of files you will need to remove the -i or it will take hours.
    EXTERME WARNING: unless you understand this command completely and know exactly what you are doing do not run it !
    Web Hosting | Reseller | VPS
    30 Day Money Back Guarantee | cPanel | 365 Day UK Support | Free Trial
    https://www.ljshost.com

  3. #3
    Join Date
    Aug 2016
    Posts
    235
    Thanks
    20
    Thanked 33 Times in 32 Posts
    Thumbs Up/Down
    Received: 123/0
    Given: 42/1
    Great advice LJSHost, I never had need to delete all. I have some times need to delete something from some directory (leaving directory).
    I usually go to that directory using cd and then use rm * -R

  4. #4
    Join Date
    Dec 2016
    Location
    Core Files
    Posts
    89
    Thanks
    5
    Thanked 12 Times in 8 Posts
    Thumbs Up/Down
    Received: 83/0
    Given: 88/0
    The rm -rfi /folder/folder/* is very useful.

    Now if you really dislike someone...just do rm -R in the root and wait for sparks to fly

  5. #5
    Join Date
    Aug 2016
    Posts
    235
    Thanks
    20
    Thanked 33 Times in 32 Posts
    Thumbs Up/Down
    Received: 123/0
    Given: 42/1
    That reminds of some old joke.

    Your father have hidden games on computer to access them go to dos, enter format c: and hit enter and you will find all games.

  6. #6
    Join Date
    Jul 2016
    Location
    Hertfordshire, UK
    Posts
    894
    Thanks
    40
    Thanked 176 Times in 147 Posts
    Thumbs Up/Down
    Received: 443/3
    Given: 136/4
    Quote Originally Posted by WPCycle View Post
    The rm -rfi /folder/folder/* is very useful.

    Now if you really dislike someone...just do rm -R in the root and wait for sparks to fly
    Don't be cruel lol
    Web Hosting | Reseller | VPS
    30 Day Money Back Guarantee | cPanel | 365 Day UK Support | Free Trial
    https://www.ljshost.com

  7. #7
    Join Date
    Dec 2016
    Location
    Core Files
    Posts
    89
    Thanks
    5
    Thanked 12 Times in 8 Posts
    Thumbs Up/Down
    Received: 83/0
    Given: 88/0
    Quote Originally Posted by GswHosting View Post
    That reminds of some old joke.

    Your father have hidden games on computer to access them go to dos, enter format c: and hit enter and you will find all games.
    HAHAHA. You know the young cats will have to Google "What is DOS" and will be astounded by 16k RAM and saving data to cassettes...which they will then Google "What is a cassette"

  8. #8
    Join Date
    Jul 2016
    Location
    Hertfordshire, UK
    Posts
    894
    Thanks
    40
    Thanked 176 Times in 147 Posts
    Thumbs Up/Down
    Received: 443/3
    Given: 136/4
    I will just add to my original comments that before deleting anything always backup first. Better safe than sorry.

    Deleting files on the command line as root can go badly wrong the difference between deleting a few folders or the entire file system can be as simple as a / or a * in the wrong place.
    Web Hosting | Reseller | VPS
    30 Day Money Back Guarantee | cPanel | 365 Day UK Support | Free Trial
    https://www.ljshost.com

Newer Threads

  1. elzorro
    macklong
    Replies: 11 | Views: 2054
    Last post by macklong, 06-13-2017, 09:02 PM
  2. forumrating
    Gecko
    Replies: 5 | Views: 383
    Last post by Gecko, 01-12-2017, 03:02 AM
  3. forumrating
    Godaddy heavy pricing
    By forumrating in forum Domain Names
    Lampard
    Replies: 7 | Views: 832
    Last post by Lampard, 01-28-2017, 08:32 PM
  4. forumrating
    KelvinSmith
    Replies: 3 | Views: 267
    Last post by KelvinSmith, 06-02-2017, 05:35 AM
  5. AnnaBlanch
    WHGBTom
    Replies: 23 | Views: 1491
    Last post by WHGBTom, 04-29-2017, 11:08 PM

Older Threads

  1. harrygreen90
    GswHosting
    Replies: 2 | Views: 1069
    Last post by GswHosting, 01-11-2017, 07:16 PM
  2. harrygreen90
    DDoS protection service?
    By harrygreen90 in forum Dedicated Server
    racksandcloud
    Replies: 7 | Views: 1636
    Last post by racksandcloud, 06-03-2017, 04:31 PM
  3. harrygreen90
    Rocketrix
    Replies: 12 | Views: 1626
    Last post by Rocketrix, 05-10-2017, 10:59 PM
  4. MilesWeb
    MilesWeb
    Replies: 0 | Views: 340
    Last post by MilesWeb, 01-11-2017, 09:47 AM

Latest Threads

  1. Webhostwala
    Webhostwala
    Replies: 4 | Views: 38
    Last post by Webhostwala, Today, 09:33 AM
  2. David Beroff
    How to make a whois server?
    By David Beroff in forum Web Hosting
    VirtuBox
    Replies: 1 | Views: 69
    Last post by VirtuBox, Today, 04:31 AM
  3. David Beroff
    VirtuBox
    Replies: 1 | Views: 59
    Last post by VirtuBox, Today, 03:05 AM
  4. WHGBTom
    WHGBTom
    Replies: 0 | Views: 37
    Last post by WHGBTom, 06-24-2017, 07:16 PM
  5. Maxoq
    mobin
    Replies: 2 | Views: 45
    Last post by mobin, Yesterday, 06:48 AM

Similar Threads

  1. FerdieQO
    Kaz Wolfe
    Replies: 2 | Views: 760
    Last post by Kaz Wolfe, 05-31-2017, 01:58 AM
  2. Paul Wellner Bou
    LJSHost
    Replies: 1 | Views: 611
    Last post by LJSHost, 01-08-2017, 02:37 PM
  3. Kaz Wolfe
    Vishnu
    Replies: 6 | Views: 688
    Last post by Vishnu, 01-06-2017, 04:26 AM
  4. Dr. McKay
    HostXNow
    Replies: 4 | Views: 859
    Last post by HostXNow, 11-29-2016, 03:59 PM
  5. David Beroff
    Kaz Wolfe
    Replies: 4 | Views: 404
    Last post by Kaz Wolfe, 07-26-2016, 03:07 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Web Hosting Forum

ForumWeb.Hosting is a web hosting forum where you’ll find in-depth discussions and resources to help you find the best hosting providers for your websites or how to manage your hosting whether you are new or experienced. You’ll find it all here. With topics ranging from web hosting, internet marketing, search engine optimization, social networking, make money online, affiliate marketing as well as hands-on technical support for web design, programming and more. We are a growing community of like-minded people that is keen to help and support each other with ambitions and online endeavors. Learn and grow, make friends and contacts for life.

Community

The world's smartest hosting providers come here to discuss & share what's trending in the web hosting world!
Copyright ©2017, ForumWeb.Hosting. All rights reserved. Web Hosting Forum for webmasters, web hosting providers, designers and web developers.

Welcome to Forum Web Hosting

The World's Number 1 Web Hosting Community, Reviews & Services

Log in!

Continue with Facebook
Continue With Email. By signing up you indicate that you have read and agree to the Terms of Service and Privacy Policy.

Sign in Manually

Need an account? Sign up now!