The command-line on Bianca¶
Objectives
- Being able to navigate to home folder, project folder and wharf
- Extra: Being able to view/create/move/delete files
Notes for teachers
Teaching goals:
- The learners demonstrate they can navigate to home folder, project folder and wharf
- Extra: The learners demonstrate they can create, move and delete files
- Extra: The learners demonstrate they can create and delete folders
Schedule:
gantt
title Lesson plan Command line
dateFormat X
axisFormat %s
Prior knowledge: prior, 0, 5s
Theory: theory, after prior, 5s
Exercises: crit, exercise, after theory, 25s
Feedback: feedback, after exercise, 10s
Why use the command-line?¶
You always need the command-line to start your calculations.
Besides that, whatever you type in the command-line can be put in a program and you can start automating your work.
Introduction¶
Bianca is a cluster with the Linux operating system. We must use a Linux terminal to work with Bianca, therefore we must learn some Linux commands.
Navigate through the file system¶
Like any operating system, Linux has directories (also called 'folders').
Use cd
to change directory:
Where to | Example command |
---|---|
The root folder | cd / |
The project folder | cd /proj/sens2025560 |
Your home folder, using full path | cd /home/richel |
Your home folder, using tilde | cd ~ |
The wharf | cd /proj/sens2025560/nobackup/wharf |
Up one folder | cd .. |
Into a folder, using relative path | cd myfolder |
The previous location | cd - |
See the content of a folder
Use ls
to see the content of a folder
See the current location
Use pwd
to see your current location
The Silence Is Golden Rule
When your command 'just works' there is no output
(try, for example cd ~
).
This is due to The Silence Is Golden Rule
Extra: Read the manual¶
Use man
to see the help pages about a command:
These command give the help pages about the programs man
, cd
and ls
respectively.
man
does not need an internet connection, hence works perfectly well on Bianca.
Press q
(short for 'quit') to exit man
Extra: Work with directories¶
Linux can create, move and delete folders.
Do what | Example command |
---|---|
Create a folder | mkdir myfolder |
Move a folder | mv from_folder to_folder |
Delete an empty folder | rmdir myfolder |
Delete a folder | rm -r myfolder |
See the content of a folder
Use ls
to see the content of a folder
See the current location
Use pwd
to see your current location
See the current real location (advanced)
For sysadmins: use pwd -P
to see your real current location on the hardware
Extra: Work with files¶
Linux can create, view, rename, move and delete files. Additionally, there are some text editors that allow one to edit files.
Do what | Example command |
---|---|
Create an empty file | touch myfile.txt |
View a file using cat |
cat myfile.txt |
Edit a file using nano |
nano myfile.txt |
Delete a file | rm myfile.txt |
Copy a file | cp myfile.txt mycopy.txt |
Rename a file | mv myfile.txt mycopy.txt |
Move a file to one folder up | mv myfile.txt ../ |
Move a file to the home folder | mv myfile.txt ~ |
- Note:
nano
is one of many text editors. It is the one recommended to beginners, as its interface is closest to what one expects
Exercises¶
Use the materials shown above to answer the questions below.
Video with solutions
There is a video that shows the solution of all these exercises: YouTube.
The video, however, follows a different order.
Exercise 1: file navigation¶
- Navigate to your home folder
Answer
The syntax to move to your home folder is:
where [username]
is your UPPMAX username, for example:
The squiggle/tilde (~
) is a shorter notation,
that does exactly the same:
- Navigate to the project folder of this course
Don't know the project code?
In our case, the project code is sens2025560
,
hence the project folder is /proj/sens2025560
.
To go there:
The wharf
is an important folder: it is the only folder where files
can be transferred to/from.
- Navigate to the wharf folder of the project of this course
Cannot find it?
Still cannot find it?
It is at /proj/nobackup/[project_id]/wharf/[user_name]/[user_name]-[project_id]
,
hence, /proj/nobackup/sens2025560/wharf/[user_name]/[user_name]-sens2025560
,
or, for a user with username sven
, at
/proj/nobackup/sens2025560/wharf/sven/sven-sens2025560
To go there:
Extra: Exercise 2: view help¶
View the help of the command cd
Answer
Use man
to view the help of any command, in this case cd
:
This will fail, because Bianca has (close to) no internet access.
Extra: Exercise 3: folder management¶
- Create a folder
/proj/sens2025560/workshop/[your_login_name]
, for example,/proj/sens2025560/workshop/richel
"
Answer
Or navigate there first:
Extra: Exercise 4: file management¶
- Create a file, e.g.
richel.txt
- Copy the file (e.g. to
richel_again.txt
)
- Move the copied file (e.g. move it one folder up to
../richel_again.txt
)
- Delete the copied file
(optional) Other useful commands¶
These are some commands that we enjoy, but are not part of the learning objectives.
Command name | Purpose |
---|---|
cat |
Show the content of a file |
less |
Navigate through the content of a file |
head |
Show the first lines of a file |
tail |
Show the last lines of a file |
less |
Show the content of a file |
wc |
Count words, lines and/or characters |
> |
Write to file (removes existing content if any) |
>> |
Append to file |
A command that cannot be put in a (Markdown) table:
|
: pipe, the output of one command to serve as input for the next
With ls /usr/bin | wc --lines
one can see that there are more than 1700
commands on Bianca.