Lab 10b Linux Command Line Programs

Part 1: Manual Pages

What options makes ls not ignore entries starting with a period?

ls -a, --all

What option will specify the maximum number of iterations the top program goes through before ending?

top -n

Unlike Windows, the ping 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)

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:

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

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)

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

Last updated