本文介绍了别名 - cd 后跟 ls的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何定义别名,以便在执行 cd Abcd
时,其中 'Abcd' 是目录的名称,该目录会更改为 'Abcd' 后跟 ls
显示目录的内容?
How can I define an alias so that when I do cd Abcd
, where 'Abcd' is the name of a directory, the directory is changed to 'Abcd' and is followed by ls
to show the contents of the directory?
推荐答案
我相信你不能使用别名来实现这一点,但你可以定义一个函数来做到这一点:
I believe you can't use an alias to accomplish that, but you could define a function to do it:
#print contents after moving to given directory
cl()
{
cd $@
ls
}
你可以把它放在你的 ~/.bashrc
文件中.
You could stick this in your ~/.bashrc
file.
如果您希望覆盖内置的 cd
命令,那么您可以这样做:
If you were hoping to override the builtin cd
command, then you could do:
#print contents after moving to given directory
cd()
{
builtin cd $@
ls
}
这篇关于别名 - cd 后跟 ls的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!