You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Linux下如何使用绝对路径运行指定配置/脚本/JSON文件?

实现绝对路径运行文件的方法

1. 获取所有文件的绝对路径

既然你已经拿到get_session_msgs_query.json的绝对路径为/root/PWG/logstash-pipelines/enum/logstash_templates/get_session_msgs_query.json,如果其他文件(enum-pipeline-2.conf、enum-ruby-filter-2.rb、lookup.json)和它在同一目录,那它们的绝对路径直接在该目录后拼接文件名即可:

  • /root/PWG/logstash-pipelines/enum/logstash_templates/enum-pipeline-2.conf
  • /root/PWG/logstash-pipelines/enum/logstash_templates/enum-ruby-filter-2.rb
  • /root/PWG/logstash-pipelines/enum/logstash_templates/lookup.json

如果其他文件不在这个目录,进入对应文件所在的文件夹,执行readlink -f 文件名就能获取绝对路径,示例:

cd /目标文件所在目录
readlink -f enum-pipeline-2.conf

2. 替换脚本/配置中的路径引用

找到之前使用./文件名的脚本或配置文件,把所有相对路径替换成对应的绝对路径:

  • 若脚本中原本是:
./enum-pipeline-2.conf
./enum-ruby-filter-2.rb

修改为:

/root/PWG/logstash-pipelines/enum/logstash_templates/enum-pipeline-2.conf
/root/PWG/logstash-pipelines/enum/logstash_templates/enum-ruby-filter-2.rb
  • 若配置文件(比如Logstash的conf)里有引用:
file => "./get_session_msgs_query.json"

修改为:

file => "/root/PWG/logstash-pipelines/enum/logstash_templates/get_session_msgs_query.json"

3. 验证运行效果

替换完成后,直接执行脚本或启动相关服务(比如Logstash),确认文件能正常加载。示例启动Logstash命令:

logstash -f /root/PWG/logstash-pipelines/enum/logstash_templates/enum-pipeline-2.conf

内容的提问来源于stack exchange,提问作者Lalit Kumar Singh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.19 07:50:31