Home > Enterprise >  How to add `ls -la` to the end of each command on the command line?
How to add `ls -la` to the end of each command on the command line?

Time:01-19

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.

CodePudding user response:

You can set

PROMPT_COMMAND='ls -la'

It runs the command before showing the prompt, i.e. 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.

CodePudding user response:

Create a function in your .bashrc like

mycd() {
  cd "$*" && ls -la
}
  • Related