Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


cmd to delete an entire folder in a linux VPS?
New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

cmd to delete an entire folder in a linux VPS?

rahulksrahulks Member
edited March 2013 in General

on Cent OS . Assume the folder is named as "fold" and the location is /root/fold

Will this be faster than deleting via Filezilla ?

«1

Comments

  • enter to /root, then

    rm -rf fold

    be careful with that command.

  • I always use rm -rf folder/ but to be safe I'd first try rm -r folder/

  • Honestly....

    google.com

  • whats the diffrence with rm -rf fold and rm -r folder/ ? is rm -r folder/ more safe to use and why?

  • That's the tag for the command.

    rm -r folder/ means remove -recursion (as in repeat (this is mostly in relation to folders))

    rm -rf folder/ means remove -recursion -force (as in it repeats and also forces (basically saying "nuke everything"))

  • @HalfEatenPie said: rm -rf folder/ means remove -recursion -force (as in it repeats and also forces (basically saying "nuke everything"))

    Actually not "nuke everything" but rather "shut up and work" as in not prompting for everything.

    @rahulks said: whats the diffrence with rm -rf fold and rm -r folder/ ? is rm -r folder/ more safe to use and why?

    rm -rf folder/ is slow and useless and doesn't delete hidden files (starting with a dot). It will iterate through the folder deleting every file and folder in it. Issuing the command without the ending slash will just remove the folder path from the filesystem table.

  • @BronzeByte said: Actually not "nuke everything" but rather "shut up and work" as in not prompting for everything.

    True. I just generalized it.

  • @rahulks said: Will this be faster than deleting via Filezilla ?

    Yes, rm -rf is faster.

    The -r is recursive (remove a directory and any subdirectories).
    The -f is force (dont prompt to confirm removal).

    Writing -rf at the end is perhaps slightly safer. Like this:

    rm /folder -rf

    Rather than this:

    rm -rf /folder

    You see, if you start typing and accidently hit the Enter key before typing out the whole thing:

    rm -rf /

    Then all hell breaks loose (erasing everything on the disk).

    Or you can do what @dedicados wrote, and change into the parent directory first:

    cd /somewhere

    And then write the rm command without any / and write only the name of your folder:

    rm -rf folder

    In any case, just be careful and you'll be fine.

  • @yomero said: Honestly....

    google.com

    +1, we all learn from basics but if you have to post even for questions like this...you really have a long long way to go.

  • Next time Google it first, but if you really can't find the answer post here

  • rm -rf

      .. simple, i suggest you download a 'Unix/Linux Command Cheat Sheet' so it will be helpful.
  • Well, clearly he doesn't know the command line very well... I'm sure there's a lot of people like that in here, using only cPanel and such.

    Not everybody is a command line wizard, but we can inspire them to become one ;)

    What he actually asked is: would it be faster to use something other than FileZilla?
    (which nobody else bothered to answer - and yes, that answer can be found with google, but its not as easy as it could be)

    And he speculates that there would be a command for that.

    So if anything, you could say "yeah the rm command is faster, try to google that".

    Dont get me wrong, I dislike lazy questions as much as the next guy, but... yeah.

    @rahulks
    you're a wizard, harry!

  • @rahulks do you have root access to a server this is connected to the public internet?

  • @BronzeByte said: rm -rf folder/ is slow and useless and doesn't delete hidden files (starting with a dot)

    rm -rf folder/ definitely deletes everything inside folder/, even hidden files.

  • @xBytez said: rm -r akash/

    when i tried that it asked rm: descend into directory `akash'? what should i type?

  • Press y and then press enter.

    But using -rf will prevent such questions. See the other replies in this thread.

    You can abort the rm command by pressing CTRL + C.

  • @rahulks

    i recommend to try www.cyberciti.biz any time you have linux related questions. even though there are many resources, i find this site a lot useful personally.

  • You can greatly reduce the chance of a catastrophic OMG error by developing the habit of never typing the / character as root (in commands that alter the filesystem).

    Use your shell's tab-completion instead. This let's you verify the path. And once you've done that you can add the command-line switches at the end.

  • @rahulks said: hen i tried that it asked rm: descend into directory `akash'? what should i type?

    y if you want to continue, Although use rm -rf folder/ if you check if you're using the correct folder. rm -r just asks for confirmation I think.

  • @sleddog said: catastrophic OMG error

    And what a sinking feeling that is. rm -rf doesn't ask if you're sure. Thank god for backups!

  • raindog308raindog308 Administrator, Veteran

    "Why is this rm -rf taking so long..."

  • emgemg Veteran
    edited March 2013

    My teenage son asked me what REALLY happens when you type the dreaded "rm -rf /" ...

    (DANGER WARNING: Do NOT enter it on a system you care about!)

    ... so I suggested that we try it out for fun on several linux installations that I had. What we expected was a completely wiped file system with all files gone, under the assumption that the process would run to completion from RAM. What really happened was that different distros did different things, but the terminal hung or the system froze long before the command completed. Several hung the terminal instantly, leaving large parts of the file system still intact. Some systems survived, sort-of, but they were not really useable. No surprise there. Obviously, the command deleted some critical file out from under a vital OS process that depended on it, but which file dealt the actual death blow probably depended on the distro, the incidental timing of various processes on the system - certainly it seemed random. My son and I got bored and gave up long before we turned the experiment into a true scientific investigation.

  • xBytezxBytez Member
    edited March 2013

    @emg you should tell your son to execute:

    shred -n 5 -vz /dev/sda

    or

    dd if=/dev/urandom of=/dev/sda
  • @emg @xBytez or dd if=/dev/null of=/dev/sda

  • raindog308raindog308 Administrator, Veteran

    @emg - I suspect the system would keep working as long as you didn't delete /dev. Once you delete the tty, etc. from /dev, the kernal doesn't know where to talk.

    The kernel, background processes, init, your shell, etc. are already in memory so they keep working.

    Of course, things would be broken all over the place - no new processes of any significance could start because all the libraries and binaries are gone, lots of I/O wouldn't work, /tmp is gone, utilities that look stuff up in /etc wouldn't work, etc.

    Not sure if you can rm -rf /proc, or what happens if you do. In theory, nothing, since it's just a window, but it would probably further break processes.

    If you had swapfiles (not swap partitions, but swapfiles), nuking them might cause a kernel panic.

  • xBytezxBytez Member
    edited March 2013

    @Bogdacutuu said: @emg @xBytez or dd if=/dev/null of=/dev/sda

    or: dd if=/dev/random of=/dev/sda

  • twaintwain Member

    @sleddog I often precede a potentially dangerous command with a # until I am certain

  • DomainBopDomainBop Member
    edited March 2013

    Honestly....

    google.com

    tried that google.com command from bash...didn't do anything...switched to Lynx...tried it again...yay, no annoying adsense ads on google pages in Lynx! Honestly, thank you for posting that tip!

    Will this be faster than deleting via Filezilla ?

    Deleting directories via the command line is much faster than doing it in Filezilla

  • emgemg Veteran
    edited March 2013

    Just for giggles, I tried several of the various suggestions above. Most of them behaved similarly to the "rm -rf /" command. In other words, the system hung or otherwise misbehaved in an unpredictable manner. Systems like this could not be booted again.

    I didn't think that "dd if=/dev/null of=/dev/sda" would work, and I was right. /dev/null is a bottomless pit, but not a source of data. The command exits immediately because there is zero input from /dev/null.

    The choice of /dev/urandom vs. /dev/random is interesting. /dev/random is supposed to block (pause input) if it runs low on entropy until it can gather sufficient additional entropy to meet input demands. One source of that entropy is the file system, which may be partially hosed. Another problem with /dev/random is that different implementations may or may not block. I have not dived deep into this area for a long time, so I don't know whether this issue was fixed.

    Based strictly on observation, I think the /dev/random input blocked quickly enough that the output did not overwrite anything vital in the filesystem. After waiting a decent amount of time, I rebooted the system successfully. An fsck showed one orphan inode.

    /dev/urandom, on the other hand, does not block. It will use a psuedo random number generator to provide sufficient input to meet demand. Sure enough, it killed the host.

    For the record, I tried various distros with my son, but tested the last few commands suggested above only on Ubuntu 12.04 LTS 32-bit. That was fun, but I had better get back to work.

  • SunshineSunshine Member
    edited March 2013

    Hehe.

    There's also /dev/zero .. even faster than /dev/urandom.

    Useful for wiping a disk with dd, which you sometimes want to do for legitimate purposes.

Sign In or Register to comment.