Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Unix question

  1. May 19, 2003 #1

    Monique

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    Hi guys, I have been trying to get familiar with the Unix environment.. there is just one (actually two) things that I cannot figure out. It must be a trivial question for you guys.

    How do I delete a file from a root directory without actually going there?

    How do I delete all the files from a subdirectory without actually deleting the directory and without going there?
     
  2. jcsd
  3. May 19, 2003 #2
    Code (Text):
    rm /dirname/filename
    rm ../filename   (file is up one directory)

    rm -r subdirname  (deletes everything in subdirname + subdir)
    rm -r subdirname/* (same w/o removing subdir)
    you can use ../ to go up one directory or start with / to start from the rootdir, in any unix command that takes a file arg

    never ever do "rm -r /" :)
     
    Last edited by a moderator: May 19, 2003
  4. May 19, 2003 #3

    Monique

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    Thanks Damgo, I was playing around with it yesterday and really couldn't figure it out :)

    What exactly does -r stand for?

    So rm -r / would remove everything that is placed underneath the rootdir? Better be carefull then :P
     
  5. May 19, 2003 #4
    yeah, watch out. i've done that before, it wasn't pretty.

    -r is 'recursive'

    if you want to know what a UNIX command does, you can almost always type "man command" or sometimes "info command" to get the manpage with all the options and explanations. "command --help" sometimes gives a shorter version.

    eg "man rm" tells you all the options you can use.
     
  6. May 19, 2003 #5

    Monique

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    Yes, I had tried that yesterday: man rm
    But it doesn't tell me anything about deleting from root or subdirectories :)

    I noticed -r and was able to delete from the subdirectory and when promted I didn't allow it to delete the directory itself.. your solution is better though :)

    So what does recursive mean?
     
  7. May 19, 2003 #6
    Be very careful with this command especially if you are logged in as root. You could remove the contents of an entire harddisk with 8 keypresses :)

    I have done this a once or twice with very serious consequences.
     
  8. May 19, 2003 #7

    Monique

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    I have experience with files being deleted in Unix.. someone was trying to clean-up the system and was deleting old programmes. Instead of deleting the old program that was designed for me, the new one was deleted with all my data inside!!

    Ofcourse we have a backup. One problem: the backup apparently had had problems and the latest data were anno not recent so I had to reenter everything :S That is when I learnt that if something is deleted in Unix, it is gone :P

    So I tried looking up the meaning of recursive, which gave me things like "GNU: GNU's Not Unix" or some other weird compound names. Not very helpfull.
     
  9. May 19, 2003 #8
    >>So what does recursive mean?
    Something that calls or refers to itself. eg, f(n)=f(n-1)+f(n-2) is a recursive formula... here rm -r works by deleting something if it's a file; if it's a directory it calls rm -r on everything inside the directory.

    silly chemists! :p
     
  10. May 19, 2003 #9

    Monique

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    lol, I'd invite you to discuss the benefits of isolated populations in the genetic dissection of complex diseases with me :P

    Thanks for the little computer 101 time :)
     
  11. May 20, 2003 #10
    The way to remove entire subdirectories is to use rm -rf /dirname/otherdir or whatever you're trying to do. At least, I believe this. I don't have any subdirectories I'm willing to delete, so I'm going off memory.

    As you know the -r stands for recursive, the f stands for force. I remember after 9/11 there were shirts on thinkgeek.com that said rm -rf /bin/laden. Very funny
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: Unix question
  1. Printers on UNIX (Replies: 2)

  2. Running UNIX (Replies: 4)

Loading...