I am currently doing an assessment and I am stuck on a question, it's "how do you modify the ls -a command so that it only shows hidden files beginning with B?" I have managed to find out how to show files beginning with B but not hidden files. I would really appreciate the help, thank you very much!

  • 2
    Well, hidden files usually begin with ., so I'm presuming the question actually means files that begin with .B, so you should be able to use that in your ls – Eric Renouf Jul 7 '16 at 12:28
  • A "hidden" file's name starts with ., therefore, there are no hidden files with names starting with B. ;-) – Kusalananda Jul 7 '16 at 13:00
  • Originally the authors of ls wanted to not display .. and .. So they did a quick hack: If file-name does not start with a . then display it. This passed all the tests (they missed out some tests e.g. ..., .hello). So they deployed it. The users then discovered that they could hide files, by starting them with a .. Eventually it was documented, and thus official behaviour. – ctrl-alt-delor Jul 7 '16 at 13:06
  • Does your question mean “show files if and only if they are hidden and then start with a .B;>". OR “show files if not hidden or starts with a .B” (i.e. “only show hidden files if they begin with B”)? – ctrl-alt-delor Jul 7 '16 at 13:13

You can list all hidden files starting with "B" with the following command:

ls -a .B*
  • 3
    you don't even need the -a! – Jeff Schaller Jul 7 '16 at 12:36
  • 3
    echo .B* perhaps? :) – ilkkachu Jul 7 '16 at 13:07
  • 1
    You do need a -d though. Or it will show content of directories, if file is a directory. – ctrl-alt-delor Jul 7 '16 at 13:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.