Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to delete files by mistake under Linux

2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly shows you the "mistakenly deleted files under Linux how to do", the content is easy to understand, clear, hope to help you solve doubts, the following let the editor lead you to study and learn "how to mistakenly delete files under Linux" this article.

Delete the alias created as rm-I

When the-I option is used with the rm command (which also includes other file processing commands such as cp or mv), a prompt appears before deleting the file. This can also be applied when a file is copied, moved, or renamed when a file with the same name as the target file already exists in the location.

This prompt will give you a second chance to consider whether you really want to delete the file-if you choose OK on this prompt, the file will be deleted. In this case, I'm sorry, this technique doesn't prevent your carelessness.

To replace rm with the rm-I alias, do this:

Alias rm='rm-i'

Run the alias command to determine that rm is now aliased:

However, this is valid only on the current shell of the current user. In order to change, you must save it to ~ /. Bashrc as shown below (some versions of the Linux system may be ~ / .profile).

In order for changes made in ~ / .bashrc (or ~ / .profile) to take effect immediately, run the file from the current shell:

. ~ / .bashrc

Forensics tool-Foremost

However, when you realize that you have accidentally deleted a file in the system and feel panic-don't worry. Let's take a look at foremost, a forensics tool for dealing with this situation.

To install Foremost in CentOS/RHEL 7, you need to enable Repoforge:/strong > first.

# rpm-Uvh http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el7.rf.x86_64.rpm # yum install foremost

In Debian and its derivative systems, you do this:

# aptitude install foremost

After the installation is complete, let's do a simple test. First delete an image file named nosdos.jpg under the / boot/images directory:

# cd images # rm nosdos.jpg

To restore this file, use foremost as shown below (first confirm the partition-in this case, / boot is in the / dev/sda1 partition).

# foremost-t jpg-I / dev/sda1-o / home/gacanepa/rescued

Where / home/gacanepa/rescued is the directory on another disk-remember, it's not wise to restore the file to the same disk as the deleted file. If during the recovery process, the disk partition where the file was deleted was occupied, the file may not be restored. In addition, do not do anything else before performing a file recovery operation.

When the foremost execution is complete, the recovered files (if recoverable) can be found in the directory / home/gacanepa/rescue/ jpg`.

The above is all the contents of this article "how to delete files by mistake under Linux". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report