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

The method of deleting files using the Linux command line

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

Share

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

This article mainly introduces the method of using Linux command line to delete files, which has certain reference value and can be used for reference by friends who need it. I hope you will learn a lot after reading this article. Next, let the editor take you to learn about it.

Rm command

The rm command is a command that most people use when deleting a file. It is used to delete a file or directory.

The syntax of the rm command is:

Rm / path/to/file

You can also delete all files in folders and subfolders, as follows:

Rm-R / path/to/folder

Once the file is deleted by the rm command, it cannot be recovered, so the command must be used with great care. However, we can prevent accidental deletion of files to some extent by using various methods.

Rm-I / path/to/file

Whenever you run the above command, a message is displayed asking if you are sure you want to delete the file.

But if you delete dozens of files and each file receives a prompt, we need to press "y" repeatedly to confirm, which will be troublesome.

We can use the following command, which prompts us only when we need to delete more than 3 files or delete them recursively.

Rm-I / path/to/file

Trash-cli tool

Trash-cli is a command-line tool for the Recycle Bin that provides the command-line recycle bin. We can use the trash-cli tool to move files to the Recycle Bin or restore deleted files.

Install (using package Manager)

Sudo apt-get install trash-cli

If you are using a centos-based system, you need to use the yum command:

Sudo yum install-y trash-cli

How do I move files to the Recycle Bin?

To move a file to the Recycle Bin, use the following command:

Trash / path/to/file

The file is not completely deleted, but is moved to the Recycle Bin in the same way as the Windows Recycle Bin.

If you provide a folder name to the trash command, it sends the folder and all files in the folder to the Recycle Bin.

How do I list files in the Recycle Bin?

To list the files in the Recycle Bin, run the following command:

Trash-list

The returned results include the original path of the file, the date and time the file was moved to the Recycle Bin.

How do I recover files from the Recycle Bin?

The man page of the trash command indicates that to restore files, you should use the following command:

Trash-restore

However, if you run this command, you may receive a command not found error.

The alternative to file restore is to use the restore-trash command, as follows:

Restore-trash

The restore-trash command lists all files in the Recycle Bin, each with a number next to it. To restore the file, simply enter the number next to the file.

How to empty the Recycle Bin?

The main problem with the Recycle Bin is that files still take up valuable drive space. If you really don't need everything in the Recycle Bin, you can run the following command to empty the Recycle Bin.

Trash-empty

If you want to delete all files that already exist in the Recycle Bin for a specific number of days, simply use the trash-empty command to specify that number. Example:

Trash-empty 7

Delete all files that have existed in the Recycle Bin for 7 days.

Thank you for reading this article carefully. I hope it is helpful for everyone to share the method of deleting files using the Linux command line. At the same time, I also hope that you can support us, pay attention to the industry information channel, and find out if you encounter problems. Detailed solutions are waiting for you to learn!

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