unix shell - ls -d $PWD
unix shell - ls -d $PWD
我想创建一个名为 Ls 的别名,当我尝试列出特定文件时打印出当前目录和文件名
unix> ls a.txt
unix> a.txt -> print out
I want it to print out the directory name too:
unix> /hier1/hier2/hier3/a.txt
When I do 'ls -d $PWD/a.txt'
it prints out
unix> /hier1/hier2/hier3/a.txt
When I make an alias of the above
alias Ls 'ls -d $PWD', it prints out the as below with a space.
unix> Ls a.txt
unix> /hier1/hier2/hier3 a.txt
How do I get the below print without the space and with a slash as below:
unix> Ls a.txt
unix> /hier1/hier2/hier3/a.txt -> THIS IS WHAT I WANT
你最好做一个函数。进入你的 ~/.bashrc 文件并使用导出命令创建函数:
function Ls(){
p="$PWD"
out="${p}/"
echo $out
}
然后保存退出:wq,输入:
source ~/.bashrc
命令应该准备就绪
如果你使用的是zsh,那么添加:
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
到 ~/.zshrc 文件。
alias Ls="echo -n $PWD/; ls "
我想创建一个名为 Ls 的别名,当我尝试列出特定文件时打印出当前目录和文件名
unix> ls a.txt
unix> a.txt -> print out
I want it to print out the directory name too:
unix> /hier1/hier2/hier3/a.txt
When I do 'ls -d $PWD/a.txt'
it prints out
unix> /hier1/hier2/hier3/a.txt
When I make an alias of the above
alias Ls 'ls -d $PWD', it prints out the as below with a space.
unix> Ls a.txt
unix> /hier1/hier2/hier3 a.txt
How do I get the below print without the space and with a slash as below:
unix> Ls a.txt
unix> /hier1/hier2/hier3/a.txt -> THIS IS WHAT I WANT
你最好做一个函数。进入你的 ~/.bashrc 文件并使用导出命令创建函数:
function Ls(){
p="$PWD"
out="${p}/"
echo $out
}
然后保存退出:wq,输入:
source ~/.bashrc
命令应该准备就绪
如果你使用的是zsh,那么添加:
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
到 ~/.zshrc 文件。
alias Ls="echo -n $PWD/; ls "