运维 | 应该永远使用这些 alias
应该永远使用这些 alias:
alias mkdir='mkdir -v'
alias mv='mv -v'
alias cp='cp -v'
alias rm='rm -v'
alias ln='ln -v'
有两个好处:
- 清楚地知道自己操作的结果
- 因为有
stdout
所以会拖慢执行速度,让你有跟多时间后悔
但是删除 node_modules 的时候我一般 \rm
去掉 -v
,或者 > /dev/null
扩展:
alias rm="trash"
Several commands of trash
Before we using trash
command, we need to install it first.
sudo apt install trash-cli
1. Use trash-list
to check whether there are any deleted files in Trash
trash-list
But at the beginning, if there is no file, no information will be displayed here.
2. Use trash
to delete files
Suppose I have two files that I want to delete, called 01.txt and 02.txt.
trash 01.txt 02.txt
Use a space to separate the two files, you can see that these two files are no longer under the current folder. At this time, use trash-list
to confirm that the file is under Trash, and you should see information like this:
2020-08-04 20:38:40 /home/clay/02.txt
2020-08-04 20:38:40 /home/clay/01.txt
Record the time of deletion and the file path before deletion.
3. Use restore-trash
to restore files
If you want to restore the files in Trash, you can enter:
restore-trash
Output:
restore-trash
0 2020-08-04 20:38:40 /home/clay/02.txt
1 2020-08-04 20:38:40 /home/clay/01.txt
What file to restore [0..1]:
Suppose you want to restore 02.txt, then you have to enter its number 0.
This is a little troublesome when restoring a large number of files… In fact, it can be copied directly from the path of ~/.local/share/Trash/files/
with the cp
command. It is recommended not to use the mv
command to move directly, or to cause confusion in the subsequent trash
command.
4. Fourth, use trash-empty to empty all files in Trash
It's very simple, use directly:
trash-empty
All files under Trash will be deleted. However, just like the rm
command, you must first make sure that there are all unnecessary files.
In the end, I think even if there are more insurance steps, the possibility of accidentally deleting the mistake will always be there. The most important thing is that users must carefully confirm the instructions they have given. This is the way to cure the root cause.
https://twitter.com/laixintao/status/1461620348445552642
https://clay-atlas.com/us/blog/2021/08/14/linux-en-trash-instead-rm/
https://web.archive.org/web/20211119153317/https://clay-atlas.com/us/blog/2021/08/14/linux-en-trash-instead-rm/
本作品采用 知识共享署名-相同方式共享 4.0 国际许可协议 进行许可。