trash()

sudo vim /usr/local/bin/trash

#!/bin/bash

trash() { local dest=”$HOME/.trash”

# 确保 .trash 目录存在 mkdir -p “$dest”

if [ $# -eq 0 ]; then echo “Usage: trash <file> [<file> …]”

exit 1

fi

for file in “$@”; do

if [ -e “$file” ]; then

local base_name=$(basename “$file”)

local dest_path=”$dest/$base_name”

local counter=1

# 处理文件名冲突

while [ -e “$dest_path” ]; do

dest_path=”$dest/${base_name%.*}_${counter}${base_name##*.}”

counter=$((counter + 1))

done

mv -v “$file” “$dest_path” echo “Moved ‘$file’ to ‘$dest_path'”

else echo “File not found: $file”

fi

done

}

# Call the function with all arguments passed to the script trash “$@”

添加执行权限:

chmod +x ~/usr/local/bin/trash

[root@iZbp17f9qggamfiyactkfwZ ~]# touch example.txt
[root@iZbp17f9qggamfiyactkfwZ ~]# trash example.txt
‘example.txt’ -> ‘/root/.trash/example.txt’
Moved ‘example.txt’ to ‘/root/.trash/example.txt’
[root@iZbp17f9qggamfiyactkfwZ ~]#

------本页内容已结束,喜欢请分享------

感谢您的来访,获取更多精彩文章请收藏本站。

© 版权声明
THE END
喜欢就支持一下吧
点赞6 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片

    暂无评论内容