简体   繁体   English

在Ubuntu Server(Linux)中使用rm时如何更改错误消息

[英]How to change error messaging when using rm in Ubuntu Server (Linux)

I want to be able to change my messages eg: 我希望能够更改我的消息,例如:

student@ubuntuserver: rm -v filename

removed 'file' --> I want to change this to for example You succesfully removed this file! 删除了“文件” ->我想将其更改为例如, 您成功删除了该文件! or something else... Also when something goes wrong with removing the file it normally says: No such file or directory! 或其他问题...当删除文件时出现问题时,通常会说: 没有这样的文件或目录! I want it to say Error when removing file or could not remove file 我想说删除文件时出错无法删除文件

The error manages given by rm are part of the rm binary installed on the system. rm给出的错误管理是系统上安装的rm二进制文件的一部分。 If you want to change it write a wrapper program that changes the message output when you invoke it. 如果要更改它,请编写一个包装程序,该程序在调用它时会更改消息输出。

您可以根据rm成功或失败来分析退出代码并打印自定义消息:

rm filename 2>/dev/null && echo "You succesfully removed this file!" || echo "Error when removing file"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM