是否有一种简单的方法可以打印file.txt的完整路径?
file.txt = /nfs/an/disks/jj/home/dir/file.txt
<命令>
dir> <command> file.txt
应该打印
/nfs/an/disks/jj/home/dir/file.txt
是否有一种简单的方法可以打印file.txt的完整路径?
file.txt = /nfs/an/disks/jj/home/dir/file.txt
<命令>
dir> <command> file.txt
应该打印
/nfs/an/disks/jj/home/dir/file.txt
当前回答
find $PWD -type f | grep "filename"
or
find $PWD -type f -name "*filename*"
其他回答
你可以把它保存在壳里。Rc或者直接放到控制台
function absolute_path { echo "$PWD/$1"; }
alias ap="absolute_path"
例子:
ap somefile.txt
将输出
/home/user/somefile.txt
在类似的场景中,我从其他位置启动cshell脚本。为了设置脚本的正确绝对路径,让它只在指定的目录中运行,我使用了以下代码:
set script_dir = `pwd`/`dirname $0`
$0存储脚本执行的确切字符串。
例如,如果脚本像这样启动:$> ../../test/test.csh, $script_dir将包含/home/abc/sandbox/v1/
除了"readlink -f",还有一个常用的命令:
$find /the/long/path/but/I/can/use/TAB/to/auto/it/to/ -name myfile /the/long/path/but/I/can/use/TAB/to/auto/it/to/myfile $
这也给出了控制台的完整路径和文件名
跑题:这种方法只给出相对链接,而不是绝对链接。readlink -f命令是正确的。
如果你和文件在同一个目录:
ls "`pwd`/file.txt"
用目标文件名替换file.txt。
find $PWD -type f | grep "filename"
or
find $PWD -type f -name "*filename*"