01-11-2017, 03:25 PM #1
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?
01-11-2017, 05:27 PM #2
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 !
01-11-2017, 06:57 PM #3
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
01-13-2017, 06:15 AM #4
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
01-13-2017, 08:57 PM #5
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.
01-13-2017, 08:59 PM #6
01-13-2017, 09:01 PM #7
01-13-2017, 09:12 PM #8
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.
Replies: 8 | Views: 1186Last post by kevinhng86, 01-12-2017, 06:06 PM
Replies: 5 | Views: 132Last post by Gecko, 01-12-2017, 03:02 AM
Replies: 7 | Views: 331Last post by Lampard, 01-28-2017, 08:32 PM
Replies: 1 | Views: 140Last post by Gecko, 01-12-2017, 03:25 AM
Replies: 18 | Views: 583Last post by serverbundle, 03-05-2017, 05:22 AM
Replies: 2 | Views: 827Last post by GswHosting, 01-11-2017, 07:16 PM
Replies: 6 | Views: 1086Last post by RDO Servers, 01-12-2017, 12:06 PM
Replies: 8 | Views: 822Last post by eva2000, 01-15-2017, 01:08 AM
By MilesWeb in forum Shared Hosting OffersReplies: 0 | Views: 217Last post by MilesWeb, 01-11-2017, 09:47 AM
Replies: 0 | Views: 15Last post by neckom, Yesterday, 09:06 PM
OFFER 7£ / Year > cPanel | SSD | CloudLinux | LiteSpeed | FREE SSL | Unmeterd | DDoS Protection > -30% OFFBy HostBastic in forum Shared Hosting OffersReplies: 0 | Views: 13Last post by HostBastic, Yesterday, 02:23 PM
By HostBastic in forum Other Hosting OffersReplies: 0 | Views: 12Last post by HostBastic, Yesterday, 02:19 PM
By HostBastic in forum VPS Hosting OffersReplies: 0 | Views: 41Last post by HostBastic, Yesterday, 02:17 PM
By HostBastic in forum Reseller Hosting OffersReplies: 0 | Views: 31Last post by HostBastic, Yesterday, 02:15 PM
Replies: 1 | Views: 511Last post by LJSHost, 01-08-2017, 02:37 PM
Replies: 6 | Views: 527Last post by Vishnu, 01-06-2017, 04:26 AM
By Dr. McKay in forum VPS HostingReplies: 4 | Views: 692Last post by HostXNow, 11-29-2016, 03:59 PM
By FerdieQO in forum VPS HostingReplies: 1 | Views: 328Last post by ValeriaMxc, 08-04-2016, 03:20 AM
By David Beroff in forum Web HostingReplies: 4 | Views: 322Last post by Kaz Wolfe, 07-26-2016, 03:07 AM
By marcyslen in forum Web Hosting