Web Hosting Forum Login
Not a member yet? Sign up

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

  • HOME
  • FORUMS
  • WEB DESIGN
  • WEB HOSTING OFFERS
  • ADVERTISING
  • FIND A HOST
  • WEB HOSTING
  • QUICK MENU
  • REGISTER HERE - Join us for FREE
Results 1 to 8 of 8
  1. #1
    Join Date
    May 2016
    Posts
    66
    Thanks
    34
    Thanked 1 Time in 1 Post
    Thumbs Up/Down
    Received: 5/0
    Given: 67/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
    680
    Thanks
    33
    Thanked 151 Times in 132 Posts
    Thumbs Up/Down
    Received: 308/3
    Given: 117/3
    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 !
    UK Web Hosting | Reseller Hosting | VPS | Domain Registration | Affiliates
    100% Cloud Powered | 30 Day Money Back Guarantee | cPanel | 365 Day UK Support
    https://www.ljshost.com

  3. #3
    Join Date
    Aug 2016
    Posts
    234
    Thanks
    20
    Thanked 32 Times in 31 Posts
    Thumbs Up/Down
    Received: 110/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
    58
    Thanks
    4
    Thanked 8 Times in 5 Posts
    Thumbs Up/Down
    Received: 50/0
    Given: 40/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
    234
    Thanks
    20
    Thanked 32 Times in 31 Posts
    Thumbs Up/Down
    Received: 110/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
    680
    Thanks
    33
    Thanked 151 Times in 132 Posts
    Thumbs Up/Down
    Received: 308/3
    Given: 117/3
    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
    UK Web Hosting | Reseller Hosting | VPS | Domain Registration | Affiliates
    100% Cloud Powered | 30 Day Money Back Guarantee | cPanel | 365 Day UK Support
    https://www.ljshost.com

  7. #7
    Join Date
    Dec 2016
    Location
    Core Files
    Posts
    58
    Thanks
    4
    Thanked 8 Times in 5 Posts
    Thumbs Up/Down
    Received: 50/0
    Given: 40/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
    680
    Thanks
    33
    Thanked 151 Times in 132 Posts
    Thumbs Up/Down
    Received: 308/3
    Given: 117/3
    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.
    UK Web Hosting | Reseller Hosting | VPS | Domain Registration | Affiliates
    100% Cloud Powered | 30 Day Money Back Guarantee | cPanel | 365 Day UK Support
    https://www.ljshost.com

Newer Threads

  1. elzorro
    kevinhng86
    Replies: 8 | Views: 441
    Last post by kevinhng86, 01-12-2017, 06:06 PM
  2. forumrating
    Gecko
    Replies: 5 | Views: 54
    Last post by Gecko, 01-12-2017, 03:02 AM
  3. forumrating
    Godaddy heavy pricing
    By forumrating in forum Domain Names
    Gecko
    Replies: 6 | Views: 128
    Last post by Gecko, 01-20-2017, 06:42 AM
  4. forumrating
    Gecko
    Replies: 1 | Views: 61
    Last post by Gecko, 01-12-2017, 03:25 AM
  5. AnnaBlanch
    vpsrus
    Replies: 11 | Views: 219
    Last post by vpsrus, 01-20-2017, 03:37 AM

Older Threads

  1. harrygreen90
    GswHosting
    Replies: 2 | Views: 189
    Last post by GswHosting, 01-11-2017, 07:16 PM
  2. harrygreen90
    DDoS protection service?
    By harrygreen90 in forum Dedicated Server
    RDO Servers
    Replies: 6 | Views: 429
    Last post by RDO Servers, 01-12-2017, 12:06 PM
  3. harrygreen90
    eva2000
    Replies: 8 | Views: 312
    Last post by eva2000, 01-15-2017, 01:08 AM
  4. PaulAdam
    PaulAdam
    Replies: 0 | Views: 151
    Last post by PaulAdam, 01-11-2017, 09:47 AM

Latest Threads

  1. UH-Peter
    UH-Peter
    Replies: 0 | Views: 11
    Last post by UH-Peter, Yesterday, 09:28 PM
  2. Mihai B.
    LJSHost
    Replies: 1 | Views: 28
    Last post by LJSHost, Yesterday, 04:48 PM
  3. Moebuntu
    Moebuntu
    Replies: 4 | Views: 115
    Last post by Moebuntu, Yesterday, 03:23 PM
  4. DefaultUser
    24x7CSM
    Replies: 4 | Views: 128
    Last post by 24x7CSM, Today, 02:04 AM
  5. hostingcoupons
    EcommIndiaCloudIT
    Replies: 3 | Views: 102
    Last post by EcommIndiaCloudIT, Yesterday, 11:46 PM

Similar Threads

  1. Paul Wellner Bou
    LJSHost
    Replies: 1 | Views: 252
    Last post by LJSHost, 01-08-2017, 02:37 PM
  2. Kaz Wolfe
    Vishnu
    Replies: 6 | Views: 251
    Last post by Vishnu, 01-06-2017, 04:26 AM
  3. Dr. McKay
    HostXNow
    Replies: 4 | Views: 575
    Last post by HostXNow, 11-29-2016, 03:59 PM
  4. FerdieQO
    ValeriaMxc
    Replies: 1 | Views: 240
    Last post by ValeriaMxc, 08-04-2016, 03:20 AM
  5. David Beroff
    Kaz Wolfe
    Replies: 4 | Views: 221
    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!