The rm command in CentOS is transformed into Moving files to the recycle bin.

Source: Internet
Author: User
Converting the rm command in linux to moving a file to the recycle bin rm is a command for deleting files in Linux. it is a very powerful but dangerous command in Linux, in particular, rm-rf is sometimes powerful enough to make you cry. when you want to clear all the files and directories in the current directory, it's easy # rm-rf. /* This is nothing, but if you accidentally break it into this # rm-rf/* sorry! ~~ Rm deletes the inode information when deleting a file, which makes it difficult to restore the deleted file by using rm to convert the rm command in linux to move the file to the recycle bin.

Rm is the command to delete files in Linux. it is a very powerful but dangerous command in Linux. in particular, rm-rf is sometimes so powerful that you can cry, when you want to clear all files and directories in the current directory, it's easy # rm-rf. /* This is nothing, but if you accidentally break it into this # rm-rf/* sorry! ~~ Rm deletes the inode information when deleting a file, which makes it very difficult to restore the file deleted using rm. In short, rm is too dangerous, especially when it comes with-rf parameters, it must be careful, but Tigers also have a nap, so why not give rm a dose of regret! After constantly searching on the Internet, I found a section to transform the rm command to move the file to a specified recycle bin directory, and then I can view the files in the recycle bin directory, then, you can clear the recycle bin directory to completely delete a piece of code from the file. the original source of this short code is no longer well-known, but we will share it with you in the spirit of being happy!

Mkdir-p/. trash # Create a directory as the recycle bin. here, the. trash directory under the user's home directory is used.

Alias rm = trash # The Command alias rm is changed to trash. by trash the rm command alias value, rm is transformed into a deleted file to the recycle bin.

Alias r = trash

Alias rl = 'ls ~ /. Trash '# The rl command displays the files in the recycle bin.

Alias ur = undelfile # ur command to retrieve files in the recycle bin

Undelfile ()

{

Mv-I ~ /. Trash/\ $ @./

} # The function is used to retrieve files in the recycle bin.

Trash ()

{

Mv $ @~ /. Trash/

} # This function moves the specified file to the specified directory. by trash the alias value of the rm command, the rm is transformed into a deleted file to the recycle bin.

Cleartrash ()

{

Read-p "clear sure? [N] "confirm

[$ Confirm = 'y'] | [$ confirm = 'y'] &/bin/rm-rf ~ /. Trash /*

} # This function is used to clear all files in the recycle bin directory.

This code defines three functions: trash, undelfile, and cleartrash. Trash is used to move files to the specified recycle bin directory. undelfile is used to retrieve the specified files in the recycle bin directory. cleartrash is used to clear the recycle bin directory. The rm command alias is trash to implement the transformation of the rm command! The following is my modified code, which is directly created in the user's home directory. The trash directory is used as the recycle bin, and other code is added to the. bashrc file in the user's home directory. This will automatically take effect every time you log on to this code! After logging on to the system, execute the following command under bash to convert the rm command to delete the file to the recycle bin!

Mkdir-p ~ /. Trash

Cat>. bashrc <

Alias rm = trash

Alias rl = 'ls ~ /. Trash'

Alias ur = undelfile

Undelfile ()

{

Mv-I ~ /. Trash/\ $ @./

}

Trash ()

{

Mv \ $ @~ /. Trash/

}

Cleartrash ()

{

Read-p "clear sure? [N] "confirm

[\ $ Confirm = 'y'] | [\ $ confirm = 'y'] &/bin/rm-rf ~ /. Trash /*

}

EOF

======================================


Instance:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.