linux - 如果文件路径包含通配符 (*),则创建或复制文件将不起作用

标签 linux bash unix

我正在创建脚本,我将在路径中找到一个可执行脚本,一旦找到,我将后退两步并转到另一个目录进行备份,但当 cd 到该目录时,我将在目录名称 Cell 中使用星号通配符,但在创建新文件或复制文件等时,带有通配符的/Cell/不接受。我认为,与其将星号视为通配符,不如将其视为目录名称本身。

用简单的方式理解。我通过触摸命令重新创建了它。

有人可以帮我解决这个问题吗?

使用 Cell 的文件列表

# ls -lrt /usr/WebSphere/AppServer70/profiles/Dmgr01/bin/../config/cells/*Cell*/admin-authz.xml
-rw-rw-r-- 1 wasadm wasadm 84047 Mar 28 06:14 /usr/WebSphere/AppServer70/profiles/Dmgr01/bin/../config/cells/lmsdqndpv01Cell07/admin-authz.xml`

创建文件失败,单元格

`# touch /usr/WebSphere/AppServer70/profiles/Dmgr01/bin/../config/cells/*Cell*/test
touch: cannot touch ‘/usr/WebSphere/AppServer70/profiles/Dmgr01/bin/../config/cells/*Cell*/test’: No such file or directory`

使用 *lmsdqndpv01Cell07 创建文件

`# touch /usr/WebSphere/AppServer70/profiles/Dmgr01/bin/../config/cells/lmsdqndpv01Cell07/test`

使用 Cell 的文件列表

`# ls -lrt /usr/WebSphere/AppServer70/profiles/Dmgr01/bin/../config/cells/*Cell*/test
-rw-r--r-- 1 root root 0 Mar 28 07:00 /usr/WebSphere/AppServer70/profiles/Dmgr01/bin/../config/cells/lmsdqndpv01Cell07/test

最佳答案

我通过下面的命令实现了这一点,但想知道是否有任何简单的方法可以做到这一点。

for file in $(find $bin/../config/cells/*Cell*/ -name admin-authz.xml) ;
  do
    cp $file "$file"_"$LanID"_consoleaccess_`date '+%Y-%m-%d-%H:%M'`
  done

关于linux - 如果文件路径包含通配符 (*),则创建或复制文件将不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55396361/

相关文章:

bash - 寻找大文件的 uniq -c 替代品

node.js - create-react-app my-app ...找不到命令

linux - 将 ksh 脚本从 unix 迁移到 linux

linux - 在 ping 中使用 -m 选项

c++ - unix中如何获取当前工作目录下最大的文件?

mysql - 增加 mysql docker 中的 max_allowed_pa​​cket 大小

c++ - 与 imread 相比,QImage 到 cv::Mat 转换奇怪的行为

linux - 将电脑上的 localhost 连接到 github

linux - 在 bash 脚本中分配 "at"命令的输出

linux - awk 以制表符作为分隔符