문제

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