How do I remove a file or directory?



  • This needed a section on its own because removing a file can be dangerous depending on what you are removing and the priviledges you have. Generally if you have a user account you can remove obsolete files and directories, that you own, when you need to. This is good disk space management.

    Even if you do own the file, once you remove it there is no easy way of getting it back, without going to a backup, it's time wasted which in most cases you could do without, and it means sucking up to the Systems Administrator to get it back for you.

    Ask yourself these questions before removing a file first:
    Is this file being used by anyone or anything else under UNIX?
    Has there been a recent backup of the file?
    Do you know why you want to remove this file?
    Will the file ever be needed again?
    Should I make my own backup in an area I am allowed to use and has enough space?
    Chances are as a normal user without priviledges to remove most important files under UNIX but, regardless of this, still ask yourself the questions above. If in doubt as the Systems Administrator
    If you have DOUBLE and TRIPLE checked you want to remove it

    To remove a file

    $ rm "name of file"
    eg:
    $ rm filelist
    

    Remove files with confirmation

    $ rm -i "name of file"
    eg:
    $ rm -i filelist
    

    To remove a directory

    $ rm -r "name of directory"
    eg:
    $ rm -r testdir
    

    The other way to remove a directory is using the UNIX command rmdir, this will only remove a directory if it is completely empty.

    $ rmdir "name of empty directory"
    eg:
    $ rmdir emptydir
    

Log in to reply
 

© Lightnetics 2024