You are on page 1of 10

Operating Systems

(CC418)
LAB 2 – BASIC COMMANDS

Dr. Karma Fathalla Eng. Nour Eldehy


Basic commands
• Since we covered how commands work and how to search and learn about them, we can
quickly try some of the most popular ones. It is encouraged to get creative with them and trying
different configuration flags/arguments.
• One of the most common commands is “pwd”. It stands for “Print Working Directory”, it tells us
exactly which directory or folder we’re using the shell from:

• Since we know which directory we’re in, we can see its contents by using “ls”. The most
commonly used configuration flags are “-l” which shows us more info about each result, and
“-a” which shows all results including hidden files (hidden files start with a “.”):
Basic commands
Basic commands
• Since we’re comfortable with showing the contents of the current directory in different ways,
we should be able to navigate between those directories. This can be achieved by using “cd”
which stands for “Change Directory”:

• “.” and “..” are two important symbols often used with “cd”. “.” refers to the current folder
while “..” refers to the previous folder. This means that typing “cd .” shouldn’t change anything
at all since we’re already here. Typing “cd ..” takes us back to the parent of the folder we’re
currently inside. Using the same logic, “cd ../..” should take us 2 steps back:
Basic commands
Basic commands
• It is also worth noting that we can arrange two commands to execute after each other by using
the “&&” operator. In this example we navigate to “test_folder” and immediately show its
contents in one line:

• Another command that is often used is “cat”. Originally, “cat” is made for concatenating two or
more files by merging their contents then printing everything. However, Most people use “cat”
to just view the contents of one file in the terminal:
Basic commands
• One other useful command is “grep”. We use it to search for a specific keyword in text file and
know if they exist. We use it by first typing the desired keyword then by typing the file we want
to search inside. In this example, we search for the word “file” in the first file and “second” in
the second file, we also search for “mohamed” in the second file but the command returns
nothing which means that this word doesn’t exist in the second file:

• Speaking of words, the command “wc” which stands for “Word Count” might be useful. We use
it with the flags “-l” to get the number of lines, “-w” to get the number of words, and “-c” to get
the number of characters in a given text file, or we can leave it with no flags to get everything:
Basic commands
• One other useful command is “cp”. We use it to copy files from source to destination. If the
command contains two file names, it copies the contents of the 1st file to the 2nd file. If the 2nd
file doesn’t exist, then first it creates one and content is copied to it. But if it existed then it is
simply overwritten without any warning.
Useful Resources
• An interactive tutorial for different commands:
• https://linuxsurvival.com/linux-tutorial-introduction

• An text-based game that uses the terminal to move around:


• http://web.mit.edu/mprat/Public/web/Terminus/Web/main.html

• Check the resources for the previous labs too.


• Those who want to prepare for the next lab should read about the following topics:
• Wildcard characters.
Thank You!

You might also like