From 0de42e91f0aa5fec29ef04a11c48bc1fd24bbc89 Mon Sep 17 00:00:00 2001 From: unigeorge <40418272+unigeorge@users.noreply.github.com> Date: Wed, 11 Aug 2021 19:46:37 +0800 Subject: [PATCH] Update and rename sources/tech/20210807 Remove files and folders in the Linux terminal.md to translated/tech/20210807 Remove files and folders in the Linux terminal.md --- ...files and folders in the Linux terminal.md | 87 ------------------- ...files and folders in the Linux terminal.md | 87 +++++++++++++++++++ 2 files changed, 87 insertions(+), 87 deletions(-) delete mode 100644 sources/tech/20210807 Remove files and folders in the Linux terminal.md create mode 100644 translated/tech/20210807 Remove files and folders in the Linux terminal.md diff --git a/sources/tech/20210807 Remove files and folders in the Linux terminal.md b/sources/tech/20210807 Remove files and folders in the Linux terminal.md deleted file mode 100644 index a34faffb25..0000000000 --- a/sources/tech/20210807 Remove files and folders in the Linux terminal.md +++ /dev/null @@ -1,87 +0,0 @@ -[#]: subject: "Remove files and folders in the Linux terminal" -[#]: via: "https://opensource.com/article/21/8/remove-files-linux-terminal" -[#]: author: "Seth Kenlon https://opensource.com/users/seth" -[#]: collector: "lujun9972" -[#]: translator: "unigeorge" -[#]: reviewer: " " -[#]: publisher: " " -[#]: url: " " - -Remove files and folders in the Linux terminal -====== -Learn to safely remove files and folders in the Linux terminal. -![Removing files][1] - -To remove a file on a computer using a graphical interface, you usually drag a file or a folder to a "trash" or "recycle" bin. Alternately, you might be able to select the file or folder you want to remove, right-click, and select **Delete**. - -When removing a file or folder in the terminal, there is no trash bin, at least by default. On a graphical desktop, the Trash is a protected directory so that users don't accidentally trash the Trash, or move it from its default location and lose track of it. The Trash is just a highly managed folder, so you can make your own Trash folder for use in your terminal. - -### Setting up a trash bin for the terminal - -Create a directory called **Trash** in your home directory: - - -``` -`$ mkdir ~/Trash` -``` - -### Removing a file - -When you want to remove a file or folder, use the **mv** command to move a file or directory to your Trash: - - -``` -`$ mv example.txt ~/Trash` -``` - -### Deleting a file or folder permanently - -When you're ready to remove a file or folder from your system permanently, you can use the **rm** command to erase all of the data in your Trash folder. By directing the **rm** command to an asterisk (`*`), you delete all files and folders inside the **Trash** folder without deleting the **Trash** folder itself. If you accidentally delete the **Trash** folder, however, you can just recreate it because directories are easy and free to create. - - -``` -`$ rm --recursive ~/Trash/*` -``` - -### Removing an empty directory - -Deleting an empty directory has the special command **rmdir**, which only removes an empty directory, protecting you from recursive mistakes. - - -``` -$ mkdir full -$ touch full/file.txt -$ rmdir full -rmdir: failed to remove 'full/': Directory not empty - -$ mkdir empty -$ rmdir empty -``` - -### Better trash - -There are [commands for trashing files][2] that aren't included by default in your terminal, but that you can install from a software repository. They make it even easier to trash files, because they manage and use the very same Trash folder you use on your desktop. - - -``` -$ trash ~/example.txt -$ trash --list -example.txt -$ trash --empty -``` - --------------------------------------------------------------------------------- - -via: https://opensource.com/article/21/8/remove-files-linux-terminal - -作者:[Seth Kenlon][a] -选题:[lujun9972][b] -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]: https://opensource.com/users/seth -[b]: https://github.com/lujun9972 -[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/ch01s10.svg_.png?itok=p07au80e (Removing files) -[2]: https://www.redhat.com/sysadmin/recover-file-deletion-linux diff --git a/translated/tech/20210807 Remove files and folders in the Linux terminal.md b/translated/tech/20210807 Remove files and folders in the Linux terminal.md new file mode 100644 index 0000000000..35b9d73659 --- /dev/null +++ b/translated/tech/20210807 Remove files and folders in the Linux terminal.md @@ -0,0 +1,87 @@ +[#]: subject: "Remove files and folders in the Linux terminal" +[#]: via: "https://opensource.com/article/21/8/remove-files-linux-terminal" +[#]: author: "Seth Kenlon https://opensource.com/users/seth" +[#]: collector: "lujun9972" +[#]: translator: "unigeorge" +[#]: reviewer: " " +[#]: publisher: " " +[#]: url: " " + +在 Linux 终端中删除文件和文件夹 +====== +本教程讲述了如何在 Linux 终端中安全地删除文件和文件夹。 +![Removing files][1] + +要想使用图形化界面删除计算机上的文件,你可能会直接将文件或文件夹拖拽到 “垃圾箱” 或 “回收站”。或者你也可以选择要删除的文件或文件夹,右键单击并选择 **删除**。 + +而在终端中删除文件或文件夹时并没有垃圾箱一说(至少默认情况下没有)。在图形化桌面上,Trash(即垃圾箱文件夹)是一个受保护的目录,保护机制可以防止用户不小心将该目录删除,或将其从默认位置移动从而导致找不到它。Trash 本质不过是一个被高度管理的文件夹,因此你可以创建自己的 Trash 文件夹以在终端中使用。 + +### 为终端设置一个垃圾箱 + +在家目录中创建一个名为 **Trash** 的目录: + + +``` +$ mkdir ~/Trash +``` + +### 删除文件 + +要删除文件或文件夹时,使用 **mv** 命令将文件或文件夹移至 Trash 中: + + +``` +$ mv example.txt ~/Trash +``` + +### 永久删除文件或文件夹 + +当你准备从系统中永久删除某个文件或文件夹时,可以使用 **rm** 命令清除垃圾箱文件夹中的所有数据。通过将 **rm** 命令指向星号(`*`),可以删除 **Trash** 文件夹内的所有文件和文件夹,而不会删除 **Trash** 文件夹本身。因为用户可以方便且自由地创建目录,所以即使不小心删除了 **Trash** 文件夹,你也可以再次新建一个。 + + +``` +$ rm --recursive ~/Trash/* +``` + +### 删除空目录 + +删除空目录有一个专门的命令 **rmdir** ,它只能用来删除空目录,从而保护你免受递归删除错误的影响。 + + +``` +$ mkdir full +$ touch full/file.txt +$ rmdir full +rmdir: failed to remove 'full/': Directory not empty + +$ mkdir empty +$ rmdir empty +``` + +### 更好的删除方式 + +此外还有一些并没有默认安装在终端上的 [删除文件命令][2],你可以从软件库安装它们。这些命令管理和使用的 **Trash** 文件夹与你在桌面模式使用的是同一个(而非你自己单独创建的),从而使删除文件变得更加方便。 + + +``` +$ trash ~/example.txt +$ trash --list +example.txt +$ trash --empty +``` + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/21/8/remove-files-linux-terminal + +作者:[Seth Kenlon][a] +选题:[lujun9972][b] +译者:[unigeorge](https://github.com/unigeorge) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://opensource.com/users/seth +[b]: https://github.com/lujun9972 +[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/ch01s10.svg_.png?itok=p07au80e (Removing files) +[2]: https://www.redhat.com/sysadmin/recover-file-deletion-linux