我想要一个产生以下结果的别名:
$cd /home/ok
[clear screen]
/home/ok
total 452K
-rwx--x--x 1 user gigl 16K Oct 1 14:08 ok0
drwx------ 5 user gigl 0 Oct 1 14:02 ok1
drwx------ 5 user gigl 0 Oct 1 13:59 ok2
drwx------ 9 user gigl 0 Oct 1 14:01 ok3
-rw------- 1 user gigl 32 Sep 30 14:36 ok4
Run Code Online (Sandbox Code Playgroud)
我做了一个类似的剧本
$cat ~/.cd.sh
#!/bin/bash
cd $1 && clear && pwd && ls -lh --color=auto
Run Code Online (Sandbox Code Playgroud)
但它不会改变当前的目录.这可能是因为在脚本中它会改变目录但是当它回到bash时我回到了目录中我执行了脚本.
任何的想法 ?
谢谢,从答案中我得到了类似的工作:
alias ls="clear && pwd && ls -lh --color=auto"
cd() { builtin cd "$1" && ls; }
Run Code Online (Sandbox Code Playgroud)
就个人而言,我建议编写一个函数而不是从.bashrc或.bash_profile加载的别名.
该功能看起来非常像您已经拥有的:
cdd () {
cd "$1"
clear
pwd
ls -lh --color=auto
}
Run Code Online (Sandbox Code Playgroud)
我不是肯定为什么别名导致你回去,但我测试了功能,它的工作原理.