几乎每次我通过命令行(即 bash)“cd”到我机器上的不同目录(在这种情况下,运行 Mac OS X 10.6.7)时,我都会立即输入“ls”以获取内容列表在那个目录中。我试图找出一种覆盖“cd”的方法,以便它更改为请求的目录,然后一次性给我列表。
我已经能够获得我正在寻找的基本功能,并将以下行添加到我的 ~/.bash_profile
function cl() { cd "$@"; ls -l; }
Run Code Online (Sandbox Code Playgroud)
这按预期工作。更改到请求的目录,然后向我显示内容。我遇到问题的地方是试图覆盖“cd”本身而不是创建新的“cl”命令。
下面的事情不工作
##### Attempt 1 #####
# Hangs the command line
function cd() { cd "$@"; ls -l; }
##### Attempt 2 #####
# Hangs the command line
function cd() { 'cd' "$@"; ls -l; }
##### Attempt 3 #####
# Does not change directory.
# Does list contents, but of the directory where you started.
function cd() { /usr/bin/cd "$@"; ls …Run Code Online (Sandbox Code Playgroud)