# Anatomy of a Unix Command

A basic UNIX command has 3 parts. These are:

1. command name
2. options (zero or more)
3. arguments (zero or more)

In general, UNIX commands are written as single strings followed by the return key. Note that UNIX commands are case-sensitive, i.e. it does matter whether you type a letter in uppercase or lowercase.

### **Example**

```
wc –l myfile.txt
```

The example above has the following components:

* the command name (wc)
* one option (-l)
* one argument (myfile.txt)

### **Options**

* Also called “switches” or “flags”.
* Specify the way a given commands must work.
* Preceded by one or two dashes (one dash if the switch is a single character, two dashes otherwise).

### Tab completion

Tab completion is a useful features of UNIX where the shell automatically fills in partially typed commands when the tab key is used. This is advantageous in many ways:

* Commands or filenames with long or difficult spelling require fewer keystroke to reach
* In the case of multiple possible completions, the shell will list all filenames beginning with those few characters.

### History

Another useful feature is the fact that the shell remembers each typed command, so you can easily recall and run previous commands.

* By using the up and down arrows at the prompt, you can revisit the command history and recall previously typed commands.
* Previous commands can be re-executed as they are or can be edited using the left/right arrow.

Use the *history* command to specify how many and which previous commands to display.

```
# display last typed commands
history 
```

```
#display the last n typed commands
history n

```

```
#execute command n
!n
```

```
#execute last command in the list
!!
```

```
# recall and execute the n-th last command
!-n
```

Examples:

```
# recall the last 5 typed commands
history 5 
```

```
# recall and execute the 3rd last command
!-3
```

```
# recall and execute command number 120
!120
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://igb.mit.edu/mini-courses/introduction-to-unix-and-ki-computational-resources/basic-unix/anatomy-of-a-unix-command.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
