Announcement

Collapse
No announcement yet.

Avoid overwriting existing files....

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Avoid overwriting existing files....

    Avoid overwriting existing files

    Operator ">" and ">>" are used to send output for one command to the specified file. But if accidentally you overwrite any important file which is not suppose to, then you might face serious problems on your server.

    Suppose we type command as anycommand > /etc/userdomains, then all the ujser accounts on your dedicated server will get messed up.

    Or in a hurry if you want to append the output with the operator >> but you by mistake type operator > , then the file will get overwrite instead of append that file.

    To avoid this to be happended on your server, set "noclobber" variable.
    If you want to set it on the server use following command
    -----------------------------------
    [[email protected] ~]# set -o noclobber
    -----------------------------------
    In order to disable it use following command
    ----------------------------------
    [[email protected] ~] set +o noclobber
    ----------------------------------


    Just try to run following command if "noclobber" is enabled on your server.

    ---------------------------------------------
    [[email protected] ~]# ls -l > /etc/userdomains
    ---------------------------------------------
    The output will be

    bash: /etc/userdomains: cannot overwrite existing file

    and your file is safe

    Following command will be used for setting "noclobber" variable directly in bachrc file on the server.
    ---------------------------------------------
    [[email protected] ~]# echo ‘set -o noclobber’ >> ~.bashrc
    ---------------------------------------------

    If you want to overwrite a particular file then disable "noclobber" on the server and check twice before firing that command. Make it very sure that the command is correctly written.
Working...
X