linux - 使用 linux 删除文件名中的第一个单词

标签 linux bash

<分区>

我有大量文件需要重命名。该名称当前为“sink-foobar”。我想删除'sink-'。一定有办法用 bash 做到这一点,但我运气不好。

最佳答案

简单:

rename 's/sink-//' *files

它是 Perl 版本,有时被命名为 prename,它在 Ubuntu 和许多发行版上作为默认安装。

为确保您的选择正确,请运行此命令:

file $(readlink -f $(type -p rename)) | grep &>/dev/null -i perl &&
    echo "Good version" ||
        echo "ELF version, not the good one"

在 Debian 和衍生版(Ubuntu...)上,您可以将其设置为默认值:

 update-alternatives --set rename /usr/bin/vendor_perl/rename

参见 https://metacpan.org/module/rename

关于linux - 使用 linux 删除文件名中的第一个单词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13661562/

相关文章:

macos - 在 OSX 上的 bash 脚本中运行 perl 命令

git - 别名 g ='git' 并让 bash 完成仍然有效

php - 设置 PHP 函数超时

linux - 创建可引导的 .img 文件

bash - 从 Bash shell 脚本发布文件

java - 标准输入可用性(竞争条件?)

bash - 如何在 Macbook 上为 oh-my-zsh 更改我的 $PS1?

android - 连接时自动启动 MTK 设备(非三星)

linux - Gnuplot 垂直虚线

c++ - 在 Linux 上使用 C++ 检测唤醒计算机