简体   繁体   English

如何在命令行上的每个命令的末尾添加 ls -la?

[英]How to add `ls -la` to the end of each command on the command line?

I am constantly running ls -la after cd 'ing into folders as I often work on file trees that I'm not familiar with.我经常在cd进入文件夹后运行ls -la ,因为我经常处理我不熟悉的文件树。

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.这变得很乏味,我想在每次按 enter 后添加ls ,这样我在更改目录时总能看到文件和文件夹列表。

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.换句话说,如果你在一个有很多文件的目录中,你将看不到任何 output 命令,因为它会因为提示命令而滚出。 Maybe using something like也许使用类似的东西

PROMPT_COMMAND='ls -la | head -n10'

might be better.可能会更好。

Create a function in your.bashrc like在 your.bashrc 中创建一个 function

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

Edit:编辑:
Better is supporting different options/arguments with更好的是支持不同的选项/参数

mycd() {
  cd "$@" && ls -la
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM