# Lab 10b Linux Command Line Programs

### **Part 1: Manual Pages**

**What options makes&#x20;**_**ls**_**&#x20;not ignore entries starting with a period?**

```
ls -a, --all
```

**What option will specify the maximum number of iterations the&#x20;**_**top**_**&#x20;program goes through before ending?**

```
top -n
```

**Unlike Windows, the&#x20;**_**ping**_**&#x20;command will run forever by default. What option allows you to specify the number of packets ping will send before stopping?**

```
ping -c
```

### **Part 2: Sudo**

The _sudo_ command allows you to execute a command as another user. In practice, this is often used to let you execute commands as the _root user_ (basically the administrator) of the system, without having to open up a whole new terminal as in Windows.

Try running the following command in a terminal:

* echo "Hello root!" > /root/root.txt

This will try to create a file called "root.txt" in the home directory of the root user (/root), which will fail because you do not have the privileges to do so. However, if you run this command using _sudo_:

* sudo echo "Hello root!" > /root/root.txt

The command will succeed!

For part 2 of the lab, do the following:

* Use the echo command to create a file in /root that contains the text "My name is \<put your name here>."
* Display the contents of this file using the _cat_ command.

**SUBMIT: Take a screenshot of your terminal window successfully displaying the contents of the file you created in /root. (2 Points)**

<figure><img src="https://2268061532-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fo71vDQ8YHfe6Cj11Juh6%2Fuploads%2F3WdT3wCyQMB3meiBGWRI%2Fimage.png?alt=media&#x26;token=5df12437-5100-4a88-80de-95cddcd850e8" alt=""><figcaption></figcaption></figure>

### **Part 3: Grep**

The _grep_ program allows you to search for words within the provided input, and is often linked with other programs using the pipe ( | ) operator to search through the output the other program. For example, if you run "cat /etc/hosts", you should see the following output:

![etc\_hosts.PNG](https://champlain.instructure.com/courses/1921280/files/237317989/preview)

If you just wanted to see the localhost entries, you can use grep to filter the output as follows:

![etc\_grep.PNG](https://champlain.instructure.com/courses/1921280/files/237317983/preview)

For part 3 of the lab, do the following:

* Look through the /etc/passwd file (despite the name, no actual passwords are stored here), and pick one of the user names included in the file (the user names are the first item included on each line).
* Use cat to output the contents of /etc/passwd, but use a grep filter to only show the line associated with the user name you selected.

**SUBMIT: Take a screenshot of the the line printed by your grep-filtered output of /etc/passwd. (2 Points)**

<figure><img src="https://2268061532-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fo71vDQ8YHfe6Cj11Juh6%2Fuploads%2FyXJKuoNMJTr4bwiuIHZf%2Fimage.png?alt=media&#x26;token=de8edc77-64bf-4d52-b748-60960929a26b" alt=""><figcaption></figcaption></figure>

If you are reading this I hope you have a good Thanksgiving break Joseph!
