I am constantly running ls -la after cd 'ing into folders as I often work on file trees that I'm not familiar with.
This is getting tedious and I would like someway to add ls after each time I press enter so I can always see the list of files and folders when I change directory.
I couldn't find much support on google as I wasn't sure what to google.
You can set
PROMPT_COMMAND='ls -la'
It runs the command before showing the prompt, ie after it runs the command you entered in the command line. In other words, if you're in a directory with many files, you won't see any output of your commands, as it will scroll out because of the prompt command. Maybe using something like
PROMPT_COMMAND='ls -la | head -n10'
might be better.
Create a function in your.bashrc like
mycd() {
cd "$*" && ls -la
}
Edit:
Better is supporting different options/arguments with
mycd() {
cd "$@" && ls -la
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.