gpt4 book ai didi

linux - 别名 - cd 后跟 ls

转载 作者:太空狗 更新时间:2023-10-29 11:09:52 28 4
gpt4 key购买 nike

我如何定义一个别名,以便当我执行 cd Abcd 时,其中“Abcd”是目录的名称,该目录更改为“Abcd”并后跟 ls 显示目录的内容?

最佳答案

我相信你不能使用别名来完成它,但你可以定义一个函数来完成它:

#print contents after moving to given directory
cl()
{
cd $@
ls
}

您可以将其粘贴到您的 ~/.bashrc 文件中。

如果您希望覆盖内置的 cd 命令,那么您可以这样做:

#print contents after moving to given directory
cd()
{
builtin cd $@
ls
}

关于linux - 别名 - cd 后跟 ls,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14146530/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com