March 9, 2016

How do I modify ls -a command?

I live in the UK and I'm currently taking the OCR GCSE Computing A452 Controlled assessment. One of the tasks is to, as the question states, modify the command ls -a to only display files beginning with b, and, as my knowledge of Linux is sound, though not particularly deep, and google is no help, I thought to as linux.com for the answers. Thanks if you reply!

ls -a b* && ls -a .b* && ls -a _b* |grep ^b

ls -a b* && ls -a .b* && ls -a _b* |grep ^b

Like  (4 likes)

ls -a b* && ls -a .b* && ls -a _b* |grep ^b

ls -a b* && ls -a .b* && ls -a _b* |grep ^b

Like  (4 likes)

ls -a is list all files including "hidden files". ls -a | grep b* wont...

ls -a is list all files including "hidden files". ls -a | grep b* wont include hidden files and only files starting with lower case b. If you want case insensitive better ls -a | grep -i b* If you want to include directories ls -a | grep -i ^b

If you want to search for files that are hidden(start with . ) as well as non hidden that begin with the letter b it would take alot more command but personally Im not sure

Like  (6 likes)

I did not find a configuration file that will allow a user to modify the ls...

I did not find a configuration file that will allow a user to modify the ls command. The ls command is a binary file read only by the system. You can use the command #ls -a | grep b* which will give you anything starting with a "b" but all I got were directories. Perhaps, the question was not to modify the program "ls" but the command ls -a to a command that will list all files starting with "b". Find a tag/option that you can append to ls that will list all files beginning with "b"

Like  (4 likes)
Click Here!