Is there any command to list the contents if passed a directory, but output the contents if it's a file?For example, often when I am navigating the directory structure I will start typing into the terminal something likell /etc/path/  # I see a file in tab-completion that interests me, called myfile.txtll /etc/path/myfile.txt  # I do the auto-completion to get it into the command lineless /etc/path/myfile.txt  # Now I have to go back and change 'll' to 'less'Alternatively, if I'm looking for a file, I start withless /etc/path  # I see in tab-completion several files that might interest me, so I need to know morell /etc/path  # See more info about file sizes, etc, so I can choose the file I want. Have to change 'less' to 'll'less /etc/path/myfile.txt  # Now that I know which file I want, I have to go back and change 'll' to 'less'This is something I end up doing dozens of times a day, and starts to slow me down. Is there a command or script that does the likeliest scenario for you? For examplesome-program /etc/path/to/file/or/directoryIf the target is a text file or symlink to a text file, 'less /etc/path/to/.....' would be executed. But if it were anything else, e.g. directory, binary file, block device, it would do 'll /etc/path/to/......'Of course if it does something you don't want, like 'less' on a file symlink but you want to see the symlink itself with 'll', then you just run 'll' manually.Anything like this exist (I bet it's out there, it seems like such a common task)? Or am I just using Linux command line in an inefficient way and there are better ways to navigate through it...how do you do it? Or I am really the only one going back and forth in the command line all the time switching 'less' to 'll' and back again?I tried writing something but I'm a bash beginner so it's definitely not working, and quite clunky even if it were. Surely there's a better way out there, some magic command I've just not heard about?some-program() {  if [[ $# > 1 ]]; then    echo Only one argument supported at this time  exit 1  fi  if [[ $# == 0 ]]; then    ELEMENT=.  else    ELEMENT=$1  fi  if [[ -d $ELEMENT ]]; then    ls --color=auto -alF $ELEMENT  else    less $ELEMENT  fi}
Command to list contents if directory, or do output contents if file?
bash;command line