Skip to main content
Engineering LibreTexts

01-B.15: Bash to

  • Page ID
  • Enter Commands in Bash

    Just like a programming language the bash shell has a syntax - that is the manner in which a command is entered on the keyboard. If commands, options and arguments are not entered in the proper manner the user will receive an error. Most commands have a variety of options that may or may not be optional. Take the ls command that is shown in the example on the left. This command will allow the user to simply enter the command without any options or arguments; it simply assumes the user is asking for a short list of the current directory. (a short list is simply the file/directory names). If you enter options, it still assumes those options pertain to the listing of the current directory. Only if the user enters one or more arguments does it list something other then the current directory. So, how do you know which commands require options, or arguments? It simply takes practice and actually working on a Linux system.

    If you fail to enter a command in the proper syntax, the shell will return an error message of some type. These messages are not always as easy to decipher as we would like, but often they are pretty straight forward. The most common one is probably "command not found", which is the result of a typo on the command line. Another common error is "no such file or directory" - again, often caused by a typ0, or perhaps an incorrect path name.

    Entering an ls command in the terminal window. When you enter a command in Linux you can add options and arguments that give the command more specific information about what the user wants the comand to do
    Figure \(\PageIndex{1}\): Command line: options and arguments ("Linux Shell" by Patrick McClanahan is licensed under CC BY-SA 4.0)
    Command line entered Explanation Does what?
    ls Command only - no options, no arguments. Returns a list of the files/directory names from the current directory.
    ls -al Command with 2 options. Linux allows you to enter: ls -a -l, or combine the options in one: ls -al. The -a shows the hidden files - those files that begin with a period - in the example you use a file called . and one called .. The -l is a "long" listing that lists the details of each file/directory, as shown in the example above.
    ls /usr Command with an argument but no options. Linux knows this is an argument because it is NOT preceded by a dash. The output is the default listing of the /usr directory - which is simply a listing of the files/directories in the /usr directory.
    ls -al /usr Command with both options and arguments. This produces a long listing of all files/directories - including hidden files/directories - in the /usr directory.

    Notice that the options are preceded by a dash. This is how Linux knows that what follows are options and not simply arguments (you CAN provide arguments without any options on some commands). Again - time and experience will help you with all of this.

    • Was this article helpful?