linux - 如果某些必需的文件是不同的目录,我如何在任何地方执行命令?
问题描述
假设命令是my_command
并且此命令必须在当前工作目录中准备特定文件(file1、file2 和 file3)。
因为我经常my_command
在许多不同的目录中使用,所以我想将某些文件保留在某个目录中,并my_command
在工作目录中没有这三个文件的情况下执行。我的意思是我不想将这三个文件复制到每个工作目录。
例如:
包含三个文件的目录/home/chest
工作目录:/home/wd
如果我执行命令my_command
,它会自动识别三个文件/home/chest/
我认为这种方式类似于添加 $PATH 而不是可执行文件,而只是文件。
解决方案
似乎文件需要在当前工作目录中才能使vasp_std
命令按预期工作,我认为您可以简单地将所有文件添加到主目录的包含文件夹中,然后从您的文件夹中创建指向该文件夹的符号链接脚本。在脚本的最后,符号链接将被删除:
#!/bin/bash
# create a symbolic link to our resource folder
ln -s ~/include src
# execute other commands here
# finally remove the symbolic link from the current directory
unlink src
如果vasp_std
命令要求将文件直接放在当前工作目录下,您可以为每个文件创建一个符号链接:
#!/bin/bash
# create link for to all resource files
for file in ~/include/*
do
ln -s $file `basename $file`
done
# execute other commands here
# remove any previously created links
for file in ~/include/*
do
unlink `basename $file`
done
推荐阅读
- mysql - 计算 SQL 中两个或多个时间戳之间的分钟数
- c# - MariaDB和C#之间的日期时间格式问题
- python - 不能在 mongoengine 过滤器查询中使用“gte”
- c# - 自定义属性以过滤具有空值的属性
- numpy - numpy (n, m) 和 (n, k) 到 (n, m, k)
- java - 数组列表中的对象加载后也是类似的。为什么?
- c++ - Certmgr - 不更新没有私钥的自签名证书
- java - 为什么我收到 JsonSyntaxException 错误
- numpy - Numpy polyfit。如何精确拟合所提供的数据点
- laravel - 翻译 arabe laravel