简体   繁体   English

在终端中重命名文件的脚本

[英]Script with renaming files in terminal

I am writing a script in bash to manage files. 我在bash中编写脚本来管理文件。 I need to add a functionality to change files name. 我需要添加一项功能来更改文件名。 To get a file I use zenity File Selection Dialog. 要获取文件,我使用zenity File Selection对话框。 After this operation I have a variable with path to this file: /home/user/Desktop/name_of_file . 完成此操作后,我将获得一个变量,该变量具有此文件的路径: /home/user/Desktop/name_of_file How can I remove current file name from this string and put there a new one? 如何从该字符串中删除当前文件名,然后放置一个新文件名?

With Bash's Parameter Expansion : 随着Bash的参数扩展

name="/home/user/Desktop/name_of_file"
new="${name%/*}/new_name_of_file"
echo "$new"

Output: 输出:

/home/user/Desktop/new_name_of_file

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

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