0% found this document useful (0 votes)
9 views

Operating System Lab2

This document discusses Linux commands, their structure, and how to get more information about commands using man pages. It notes that commands have a name followed by optional arguments, and arguments starting with "-" are configuration arguments. It provides examples of commands like echo, cp, and pwd. It then explains that man pages (accessed with "man") provide detailed documentation for commands, and includes an example of the man page for echo. The document recommends exploring new commands, reading man pages, and trying commands to learn how to use the shell.

Uploaded by

Nourhan Saad
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Operating System Lab2

This document discusses Linux commands, their structure, and how to get more information about commands using man pages. It notes that commands have a name followed by optional arguments, and arguments starting with "-" are configuration arguments. It provides examples of commands like echo, cp, and pwd. It then explains that man pages (accessed with "man") provide detailed documentation for commands, and includes an example of the man page for echo. The document recommends exploring new commands, reading man pages, and trying commands to learn how to use the shell.

Uploaded by

Nourhan Saad
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Operating Systems

(CC418)
LAB 1 – COMMAND STRUCTURE & MAN PAGES

Eng. Nour Eldehy


What are commands?
• Remember the last time we discussed the shell, we agreed that its responsibility is to take our
“commands” and give them to the kernel.
• Writing a command is basically writing a program’s name that we want to make the kernel run.
• Remember when we discussed the “/bin” directory? All of the commands we type are run from
this directory.
• Like any program, a command may or may not require additional inputs. Also, some commands
give us output in the terminal, in a file or none at all.
Command structure
• On Linux systems, commands follow this structure:
• Command name + 0 or more arguments

• Arguments are specific strings written after the command’s name to either indicate an input or
a configuration. For example, take a look at this command:

• First, we write the command’s name “echo”, then we give one argument which is the string
“Hello!”. On the next line we find that the program exited and printed the same string we gave
it... Just like an “echo”.
Command structure
• Take a look at this example:

• It is a convention in Linux programs that arguments starting with “-” or “--” are to be regarded
as configuration arguments and not as input. In this example we type “cp --help” to know what
“cp” does. It then shows us the different formats for this command, as well as all the other
arguments.
Command structure
• Finally, this is an example of a command that takes no arguments:

• For instance, “pwd” stands for “Print Working Directory”. Or in other words, print the name of
the directory from which we ran this program.
The man pages
• Sometimes we find programs that don’t follow the convention of having a “-h” or “--help”
argument. Or maybe we find the text resulting from the “-h” argument not enough, or unclear.
• Luckily, there is a solution we can do before searching on the Internet, and that is reading the
manual pages.
• Manual pages (or man pages for short) are detailed explanations provided by the developers to
tell us exactly how the command should run and what it does.
• To access a man page, we write “man” followed by the command we want to understand.
The man pages
• For example, let’s learn more about “echo” that we used before, first we type “man echo”, then
we find this:
The man pages
• As we can see, we can navigate the man pages using the arrow keys and quit with “q”. Pressing
“h” will also tell us about other navigation options.
• But did you notice this number in “ECHO(1)”? What does it mean? How about we see the man
page for “man” itself! We do this by typing “man man” then we can find the following output:
The man pages
• So, we now know that the number (1) means that “echo” is a shell command.
• Tip: using the configuration “-k” gives us one-line results when we search for a command using
a keyword, if it says “nothing appropriate” then fix it by typing “sudo mandb”. (sudo will be
covered later):

•The goal of all of this is to learn how to learn. The best way to learn using the shell is by trial,
error and learning how to read instructions and error messages. Search for new commands
you’ve never heard of before and look them up in the man pages and try to use them correctly.
Useful Resources
• For explaining the meaning of any command:
• https://explainshell.com

• An online version of the man pages:


• http://man.he.net

• A list of all shell commands:


• https://ss64.com/bash

• Those who want to prepare for the next lab should read about the following topics:
• Basic shell commands (ex: ls, cd, cp, mv, touch, rm, mkdir, cat, grep, ...etc.).
Thank You!

You might also like