質問

I am wondering if there is any way to make a script, that would run in the background and which will call the "ls" command every time I change directories("cd") in Linux.

I know that in order to put a process in the background you add a "&" when you run it.

Thanks in advance!

役に立ちましたか?

解決

You could replace cd with a shell function in your ~/.bashrc or similar startup script:

function cd {
    builtin cd "$@"
    RET=$?
    ls
    return $RET
}

this would also return the exit code of cd, just in case...

builtin is a shell builtin to execute the shell builtin cd instead of the cd funciton, to avoid running into a recursive loop - at least in bash - but should also work with other shells...

他のヒント

You can define a function in your .bashrc like this to achieve that:

cdlist(){
        cd "$1" && ls
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top