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
    102
    Thanks
    44
    Thanked 3 Times in 3 Posts
    Thumbs Up/Down
    Received: 10/0
    Given: 163/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
    990
    Thanks
    40
    Thanked 188 Times in 157 Posts
    Thumbs Up/Down
    Received: 478/3
    Given: 138/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: 124/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
    100
    Thanks
    5
    Thanked 12 Times in 8 Posts
    Thumbs Up/Down
    Received: 86/0
    Given: 98/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: 124/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
    990
    Thanks
    40
    Thanked 188 Times in 157 Posts
    Thumbs Up/Down
    Received: 478/3
    Given: 138/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
    100
    Thanks
    5
    Thanked 12 Times in 8 Posts
    Thumbs Up/Down
    Received: 86/0
    Given: 98/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
    990
    Thanks
    40
    Thanked 188 Times in 157 Posts
    Thumbs Up/Down
    Received: 478/3
    Given: 138/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: 3477
    Last post by macklong, 06-13-2017, 09:02 PM
  2. forumrating
    Viggn
    Replies: 10 | Views: 725
    Last post by Viggn, 09-24-2017, 09:43 PM
  3. forumrating
    Godaddy heavy pricing
    By forumrating in forum Domain Names
    Lampard
    Replies: 7 | Views: 994
    Last post by Lampard, 01-28-2017, 08:32 PM
  4. forumrating
    hineyolu
    Replies: 4 | Views: 525
    Last post by hineyolu, 07-14-2017, 02:46 AM
  5. AnnaBlanch
    yajtagaamo
    Replies: 31 | Views: 2125
    Last post by yajtagaamo, 11-04-2017, 04:41 AM

Older Threads

  1. harrygreen90
    GswHosting
    Replies: 2 | Views: 1140
    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: 3070
    Last post by racksandcloud, 06-03-2017, 04:31 PM
  3. harrygreen90
    Rocketrix
    Replies: 12 | Views: 2173
    Last post by Rocketrix, 05-10-2017, 10:59 PM
  4. MilesWeb
    MilesWeb
    Replies: 0 | Views: 394
    Last post by MilesWeb, 01-11-2017, 09:47 AM

Latest Threads

  1. HostColor
    HostColor
    Replies: 0 | Views: 12
    Last post by HostColor, Today, 10:48 AM
  2. Lene
    Lene
    Replies: 0 | Views: 13
    Last post by Lene, Today, 06:18 AM
  3. pau18
    pau18
    Replies: 0 | Views: 14
    Last post by pau18, Today, 12:12 AM
  4. trendjing
    24x7serverman
    Replies: 1 | Views: 20
    Last post by 24x7serverman, Today, 05:59 AM
  5. Chris Worner
    Virtualbox on Linux VPS?
    By Chris Worner in forum VPS Hosting
    LJSHost
    Replies: 2 | Views: 29
    Last post by LJSHost, Today, 02:02 PM

Similar Threads

  1. FerdieQO
    Kaz Wolfe
    Replies: 2 | Views: 1522
    Last post by Kaz Wolfe, 05-31-2017, 01:58 AM
  2. Paul Wellner Bou
    LJSHost
    Replies: 1 | Views: 696
    Last post by LJSHost, 01-08-2017, 02:37 PM
  3. Kaz Wolfe
    Vishnu
    Replies: 6 | Views: 809
    Last post by Vishnu, 01-06-2017, 04:26 AM
  4. Dr. McKay
    HostXNow
    Replies: 4 | Views: 1021
    Last post by HostXNow, 11-29-2016, 03:59 PM
  5. David Beroff
    Kaz Wolfe
    Replies: 4 | Views: 498
    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!