Running Commands

Every shell has a prompt at which you can type commands. Often the prompt character is $ for a normal user and # for an administrator, but it’s also common to see %, >, and virtually any other character.

Prompts also commonly include information about the environment: what directory you’re in, the name of the user your session is running under, or even things like the status of version control repositories or the battery status of your laptop.

When you open a new terminal window, you should see your prompt. It’s likely to look something like this:

 
user@computer:~ $

A cursor should be flashing just after the dollar sign, inviting you to type. If you type a single command and hit the Enter key, the shell will run that command for you and display its output on the screen. Try ls for a start, to list the contents of the current directory:

 
user@computer:~ $ ​ls
 
Documents Pictures Movies

Virtually all commands accept options (also known as flags or switches) that alter their behavior in different ways, and arguments, which generally specify actions to take or the target the tool should work on. We type these after the command, each one separated by a space. ls, for example, accepts many different options that change its behavior, and then zero or more arguments that specify what files or directories to list. For example:

 
user@computer:~ $ ​ls​​ ​​-l​​ ​​Pictures
 
-rw-r--r-- 1 rob staff 75130 2 May 2015 ollie.jpg
 
-rw-r--r-- 1 rob staff 6688 7 May 2015 hendrix.jpg

Here we specify one option, -l, which tells ls to list files in long format (showing things like the permissions, owner, and size of the files), and then specify one argument, Pictures, which tells ls to list the contents of that particular directory.

That’s all there is to it. You can get quite far using the shell in this way. The capabilities of the commands that come with your operating system are pretty vast. But you’re using only a tiny fraction of the shell’s power.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.17.29.19