Skip to content
Advertisement

How to display all commands of the bash shell in a file? Linux [closed]

So I have an assignment in linux terminal asking me to create a file in the home directory and to make the file display all the commands of the bash shell which is found in the /bin directory.

I already tried to use the echo command to display the commands to the file but it is not working:

echo $ls /bin > File1

I expect that the file contains all the commands of the bash shell, but when I type the line above in the linux terminal, the content of the file is just the word “/bin”.

Is there any other way to use to meet the expected result?

Advertisement

Answer

Here you don’t need the echo command, as ls already prints to standard output, which can then be piped to the file. The command you want is:

ls /bin > File1

A good way to go about this is by checking that “ls /bin” by itself will print to standard output the contents of /bin, and once you see the expected output, run it again with the “> File1” to then output to File1.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement