Basic Linux¶
Learning outcomes
- Practice some basic Linux commands:
echo,printf,cat,wc,rev - Practice with Linux pipes
- Use the output of one process as the input for
awk
For teachers
Teaching goals are:
- The learners have practiced with UNIX pipes
Lesson plan:
- 5 mins: prior knowledge
- 5 mins: presentation
- 15 mins: challenge
- 5 mins: feedback
Overview¶
Most UNIX (i.e. Linux and MacOS) distributions includes awk
as it is a tool
that is part of a common standard for what operating systems should have.
The UPPMAX clusters, running Linux, also have awk.
Here we discuss the most relevant Linux programs and terms.
flowchart TD
subgraph basic_linux[Basic Linux]
awk
pipes
echo
printf
stdin
files[Files]
input[Input]
cat
editor[Text editor]
wc
rev
tr
end
%% Basic Linux
stdin --> |need to know| pipes
printf --> |need to know| echo
pipes --> |need to know| printf
files --> |need to know| cat
files --> |need to know| editor
files --> |a type of| input
stdin --> |a type of| input
awk --> |reads| input
Exercises¶
Exercise 1: echo¶
Learning outcomes
- Use
echo
Read:
Do, in a terminal:
man echoecho helloecho hello worldecho hello\nworldecho hello\\nworldecho -e hello\nworldecho -e hello\\nworldecho "Hello world"echo -e "Hello\\nworld"echo -e 'Hello\\nworld'
Answer the following questions:
echocan create output that spans multiple lines yes/no- When putting a newline in a string, the type of quotes (i.e. single or double) matters yes/no
Express in your own words: what does echo do?
Exercise 2: printf¶
Learning outcomes
- Use
printf
Read:
Do, in a terminal:
man printfprintf helloprintf hello\nprintf hello\\nprintf hello worldprintf hello\nworldprintf hello\\nworldprintf -e hello\nworldprintf -e hello\\nworldprintf "Hello world"printf -e "Hello\\nworld"printf -e 'Hello\\nworld'
Answer the following questions:
printfcan create output that spans multiple lines yes/no- When putting a newline in a string, the type of quotes (i.e. single or double) matters yes/no
Express in your own words: what does printf do?
Exercise 3: cat¶
Learning outcomes
- Use
cat
Read:
Do:
- create a file called
why_awk.txtwith the following content (from this post from the AWK archives ):
"The Enlightened Ones say that....
You should never use C if you can do it with a script;
You should never use a script if you can do it with awk;
Never use awk if you can do it with sed;
Never use sed if you can do it with grep."
Then, in a terminal, in the same folder as why_awk.txt, do:
man catcat why_awk.txtcat -b why_awk.txtcat -n why_awk.txt
Express in your own words: what does cat do?
Exercise 4: wc¶
Learning outcomes
- Use
wc
Read:
Then, in a terminal, do:
man wcwc why_awk.txt
Express in your own words: what does wc do?
Exercise 5: a UNIX pipeline¶
Learning outcomes
- Use a pipeline
Read:
The pipe symbol | is used in a UNIX pipeline.
Do, in a terminal:
echo hello world | revecho hello world | rev | revcat why_awk.txt | wccat why_awk.txt | revcat why_awk.txt | wc | revcat -n why_awk.txt | revrev --version | rev
Express in your own words: what does the pipe symbol | do?