blog hits

Web Counters

Monday, May 25, 2009

Create a recycle bin for linux console

Concept : when a user deletes a file that file is moved in to the folder $HOME/.junk

  1. Create the .junk folder in the /etc/skel directory.

    The content in this directory is copied in to the user home directory when the new user is created. This technique can be used to create the .junk directory in the users home directory.

    login as the root
    $ su - root
    password :
    #

    create the .junk directory
    # mkdir /etc/skel/.junk

  2. The envioromental variabble we create is WASTEBIN.

    The value of the variable will be $HOME/.junk - this enables the user to call the recycle bin directory from the command line.
    edit the file .bash_profile which is executed when the user logs in
    # vi /etc/skel/.bash_profile

    in that file add at the bottom
    export WASTEBIN=$HOME/.junk

  3. The command that we create is "del" this is alias to "rm" command.

    edit the .bashrc file
    # vi /etc/skel/.bashrc

    and append this text to that file to make an alias. add this to the file bottom
    alias rm=del

  4. design the "del" command

    In shell(bash) $1, $2, $3... $9 are the nine bash commanline arguments. So we use this predefine variables to pass the values to the "del" command.

    we can also use $* variable, which represent all those 9 variables at once. so the del command would be in the following format
    del ....

    create the file#
    # vi usr/local/bin/del

    then add
    mv $* $WASTEBIN

  5. change the execution permission to the del command

    # chmod +x /usr/local/bin/del

0 comments:

Post a Comment