Skip to content

Use the console environment

Learning objectives

  • Practice using the UPPMAX documentation
  • Understand what the prompt is
  • Can navigate the file system
  • Can do basic file management: create, copy, move and delete a file and folder
  • Can copy-paste text between local computer and the terminal (in both directions)
  • Can use tab-completion with the prompt
For teachers

Teaching goals are:

  • Learners practice using the UPPMAX documentation
  • Learners understand what the prompt is
  • Learners have navigated the file system
  • Learners have done basic file management: create, copy, move and delete a file and folder
  • Learners have copy-pasted text between local computer and the terminal (in both directions)
  • Learners have used tab-completion with the prompt

Lesson plan:

gantt
  title Using the terminal
  dateFormat X
  axisFormat %s
  section First hour
  Prior : prior, 0, 5s
  Present: present, after prior, 2s
  %% It took me 16 mins, here I do that time x2
  Challenge: crit, challenge, after present, 32s
  %% Here I use the same time it took me to give feedback
  Feedback: feedback, after challenge, 16s

Prior questions:

  • Do you expect it to be hard to use a console environment?
  • Do you expect there to be much different behavior when using a console environment?
  • Does someone have already tried to copy-past text between local computer and a terminal?

Why?

Every UPPMAX user need to use the terminal at some point. Let's make sure we use it well :-)

Here we do the same exercises as when using the remote desktop environment.

The goal is to make sure you can indeed do all these 'simple' things, as maybe you'll be too afraid to ask a colleague later.

Learning Linux

Using a terminal and getting comfortable with Linux may not be the most intuitive. Luckily, Linux is heavily used and there are many fora, websites and books written about it.

One such book is The Linux Command Line, which is available in both print and online:

Book cover of 'The Linux Command Line'

Book cover of 'The Linux Command Line'

Exercises

Need a video?

Here is a video that shows the solution of these exercises

It is assumed you are logged in to the console environment of Rackham with a terminal. In case you did not get this to work, login via the remote desktop website and start a terminal there.

You are encouraged to search the internet for the answer yourself. Or, if you prefer, use the links to the relevant chapters in the book 'The Linux Command Line'. Or any other way!

Try to do these exercises by trying out things yourself first. There are usually multiple ways to solve the exercise. Feel encouraged to explore this new environment too!

Exercise 1: the prompt

You are in a terminal on a Rackham login node. You see this:

[sven@rackham2 ~]$ 

What does that all mean: the [, sven, @, rackham2, ~, ] and $?

Tips
  • Tip 1: search for 'terminal prompt'
  • Tip 2: search the UPPMAX documentation for 'terminal'
Answer
  • [ and ]: indicates the beginning and end of information
  • sven: the username
  • @: at which cluster
  • rackham2: the remote node's name, in this case Rackham's second login node
  • ~: the user in the home folder
  • $: indicate to be ready for user input

Exercise 2: file navigation

  • You are in a terminal on a Rackham login node. Find out the directory you are in: which command do you use?
Tips
Answer

The command to use is pwd, short for 'Present working directory':

pwd

You output will look similar to this:

[sven@rackham2 ~]$ pwd
/home/sven

Exercise 3: file management

You are in a terminal on a Rackham login node, in your home folder.

From there:

  • Find out which files are in your home folder from the terminal. This is exactly the same as displayed in the file explorer in the remote desktop
Tips
Answer

The command to use is ls, short for 'List':

ls

You output will look similar to this:

[sven@rackham3 ~]$ ls
bin  GitHubs  glob  lib  private  R  users
[sven@rackham3 ~]$ 
  • create a file called test.txt
Tips
  • Tip 1: search for 'Linux create file'
  • Tip 2: this command is not mentioned in the book 'The Linux Command Line'
Answer

The command to use is touch:

touch test.txt

You output will look similar to this:

[sven@rackham2 ~]$ touch test.txt
[sven@rackham2 ~]$ 
  • Find out which files are in your home folder from the terminal again, to confirm test.txt is indeed created
Answer

The command to use is ls:

ls

You output will look similar to this:

[richel@rackham3 ~]$ ls
bin  GitHubs  glob  lib  private  R  test.txt  users
[richel@rackham3 ~]$ 
  • copy the file test.txt to copy.txt and confirm that it worked
Tips
Answer

The command to use is cp:

cp test.txt copy.txt

You output will look similar to this:

[richel@rackham3 ~]$ cp test.txt copy.txt
[richel@rackham3 ~]$ ls
bin  copy.txt  GitHubs  glob  lib  private  R  test.txt  users
  • delete the file copy.txt and confirm that it worked
Tips
Answer

The command to use is rm:

rm copy.txt

You output will look similar to this:

[richel@rackham3 ~]$ rm copy.txt
[richel@rackham3 ~]$ ls
bin  GitHubs  glob  lib  private  R  test.txt  users
  • rename the file test.txt to test2.txt and confirm that it worked. Use tab-completion on the first filename
Tips
Answer

The command to use is mv, short for 'Move'.

The full command looks like this:

mv test.txt test2.txt

with tab-completion, one can type ...

mv t

... and then press TAB to autocomplete the first filename.

You output will look similar to this:

[richel@rackham3 ~]$ mv test.txt test2.txt
[richel@rackham3 ~]$ ls
bin  GitHubs  glob  lib  private  R  test2.txt  users
  • create a folder my_folder and confirm that it worked
Tips
Answer

The command to use is mkdir, short for 'Make directory'

mkdir my_folder

You output will look similar to this:

[richel@rackham2 ~]$ mkdir my_folder
[richel@rackham2 ~]$ ls
bin  GitHubs  glob  lib  my_folder  private  R  test2.txt  users
[richel@rackham2 ~]$ 
  • copy the my_folder folder to my_copy and confirm that it worked
Tips
What does cp: omitting directory ‘my_folder’ mean?

This happens if you copy non-recursively, i.e. if you forget the -R flag. You'll see:

[richel@rackham2 ~]$ cp my_folder my_copy
cp: omitting directory ‘my_folder’

When trying to copy a folder without -R, this warning is given and no folder is copied.

Answer

The command to use is cp with the -R flag, where -R denotes 'recursively':

cp -R my_folder my_copy

You output will look similar to this:

[richel@rackham2 ~]$ cp -R my_folder my_copy
[richel@rackham2 ~]$ ls
bin  GitHubs  glob  lib  my_copy  my_folder  private  R  test2.txt  users
[richel@rackham2 ~]$ 

If you forget the -R flag, you'll see:

[richel@rackham2 ~]$ cp my_folder my_copy
cp: omitting directory ‘my_folder’

When trying to copy a folder without -R, this warning is given and no folder is copied.

  • delete the my_copy folder and confirm that it worked
Tips
Answer

The command to use is rm with the -R flag, where -R denotes 'recursively':

rm -R my_copy/

You output will look similar to this:

[richel@rackham2 ~]$ rm -R my_copy/
[richel@rackham2 ~]$ ls
bin  GitHubs  glob  lib  my_folder  private  R  test2.txt  users

If you forget the -R flag, you'll see:

[richel@rackham2 ~]$ rm my_copy/
rm: cannot remove ‘my_copy/’: Is a directory

When trying to rename a folder without -R, this warning is given and no folder is renamed.

  • rename the my_folder folder to my_best_folder and confirm that it worked
Tips
Answer

The command to use is mv:

mv my_folder my_best_folder

You output will look similar to this:

[richel@rackham2 ~]$ mv my_folder my_best_folder
[richel@rackham2 ~]$ ls
bin  GitHubs  glob  lib  my_best_folder  private  R  test2.txt  users

If you add the -R flag, you'll see:

[richel@rackham2 ~]$ mv -R my_folder my_best_folder
mv: invalid option -- 'R'
Try 'mv --help' for more information.

When trying to move a folder with -R, this warning is given and no folder is renamed.

Exercise 4: starting xeyes

  • From the terminal, start the program xeyes by typing xeyes and press enter,
Answer

These eyes will show up:

These eyes will show up

  • Close xeyes
Answer

Here is how to close a program in the terminal:

Press CTRL + C

Exercise 5: starting a text editor

  • Create a file called my_file.txt, if not already present
Answer
touch my_file.txt
  • Edit the file by opening it with the nano text editor
Answer

Type:

nano my_file.txt

To be able to search the web for questions on this graphical text editor, its name will be useful to know:

  • What is the name of this text editor?
Answer

This text editor is called 'nano'.

  • Save the file. There are multiple ways!

  • Close nano. There are multiple ways!

Answer

These are some of the more conventional ways to close gedit:

  • Press CTRL + X to close. nano asks if you want to save the buffer (in this case: the file). Press Y. nano asks for a filename and shows the current filename. Press enter.

Exercise 6: copy-paste text

  • Copy text from your local computer to your terminal
Tips
  • Tip 1: search for 'how to paste into terminal'
  • Tip 2: search the UPPMAX documentation for 'terminal'
Answer

Copying from your local computer uses a regular CTRL + C.

How to paste depends on the terminal you use. The most common keyboard shortcut is CTRL + SHIFT + V for pasting into a terminal

  • Copy text from your terminal to your local computer
Answer

How to copy depends on the terminal you use. The most common keyboard shortcut is CTRL + SHIFT + C for copying from a terminal

Pasting to your local computer uses a regular CTRL + V.