text: mail, program sources, scripts, configuration…
executables: programs in binary code
Directory files (we talk about directory)
they are container files that contain references to other files true framework
of the tree structure, they allow to organize files by categories.
Special files
located in /dev, these are access
points prepared by the system to the devices. Mounting will perform a mapping of
these special files to their directories.
Link files
These are files that contain only a reference (pointer) to another file. This
makes it possible to use the same file under several names without having to
duplicate it on the disk.
Application
The command ls allows you to see a part of the tree structure. For example, on
my personal account, the command ls -l (-l gives details about the contents
of the tree) gives the following result.
Once you are logged in, launch a terminal (Terminal, Konsole…)
Launch a program (for example xeyes) in interactive mode xeyes & and in
non-interactive mode xeyes. What is the difference? Type the command
CTRL+C to kill the xeyes process.
Directory navigation
When you launch the terminal, in which directory are you located?
Type (successively) the following commands:
Look at the result. Which directory does the ~ (tilde) match? You can
always go to your main / home directory, your home (in system jargon) by
simply doing cd or cd ~. Similarly cd - allows you to go to the
directory where you were previously.
Create the se3 directory in your main directory :
or equivalent with :
Display the contents of this directory with the command ls.
Create an empty file (in the se3 directory) named empty_file.txt with the
touch empty_file.txt command.
Display the contents of your se3 directory
It can also be used in this way:
Type cd to return to your home.
What is the content of your home?
Create a tmp directory. What is now the content of your home?
Delete the tmp directory with the rm command.
Display the contents of your home.
Try deleting tmp again, what happens?
Be the following command sequence:
What is the difference in display? What are the “the” and “a” options used
for?
Delete the se3 directory with its contents via:
See the help of rm (via man rm) and tell why this command is dangerous.
Search in text
By always being in the /etc/dictionaries-common directory
What does the command wc <filename> do? What do the - and -c options do?
What does the grep command do with e.g. the grep house words or grep
house words commands?
Edit / modify a file
In your home directory, create a text file using the vim editor via the
command vim test.txt.
Press the i key to switch to vim insertion mode, you can then type text
(e.g. your first and last name).
Then press ESC to exit insertion mode.
Then press :w to save the file and then :q to exit vim (it is possible
to combine the 2 commands into one by typing :wq)
Check with less that the file contains what you wrote.
How big is this file?
Search for files in a directory
Consult the help of the search command with man find.
Then type:
What is the meaning of the character * here?
What is the purpose of the -name option?
What is the difference between ls -R and find?
Try the two commands find /etc -exec wc '{}' + and find /etc -name "*.cfg"
-exec wc '{}' +. What does the -exec option do?
Standard Input (stdin)
We remind you that the standard input corresponds to what is typed on the keyboard.
What does the sort command do? Look specifically at what happens when
sort has no file as a parameter.
Try it:
then type CTRL+D.
Similarly, try to sort the numbers 2, 11, 1. Explain why 11 is considered to
be smaller than 2. Use the appropriate option to get a numeric sort.
Standard Output
What does the echo command do?
Do the following (notice that the second call to echo overwrites the
contents of file):
With >> we add at the end without overwriting the file
Using sort, generate an .sorted file containing the numbers 2, 1, 11 sorted
in ascending order. The result is displayed in the terminal?
Type the following commands and explain what happens:
Why are the file.sorted and file2.sorted files different? You can use the
diff command to see the differences.
The pipe
The pipe allows to connect the result of a command to the input of a new command.
View the lines in file.sorted that contain the 1 character (look at the
grep command).
Count the number of lines in this file
How do I count the number of lines that contain 1 in file.sorted?
Try grep 1 file.sorted | wc to check that this command answers the previous
question and that it does not generate temporary files.
The .bashrc file
This file contains commands that are executed each time you open a terminal.
This file usually contains shortcuts or options for the terminal.
With a text editor1, create / open your .bashrc file and write alias
ll='ls -l' in it.
Exit the editor and type ll. What happens? Open a new terminal (without
closing the first one) and type ll. What happens? In the first terminal,
type source .bashrc and check that the command ll now works.
Reload .bashrc in the terminal
You can enrich your .bashrc file to customize your terminal with for
example:
You will find below some commands that will be very useful for this year (and
used very often in TP control for example):
View / copy public files from another account. If you know the login of
another person of Polytech Lille, you can consult the authorized files of
this account via:
Connect to the school’s machines/servers from the outside:
at Polytech Lille, you can connect to another machine with the following command
such as for example:
Useful shortcuts
The terminal uses a specific software library called
Readline to read the commands you
type. It provides several shortcuts to improve your productivity. These
shortcuts could be used either using emacs syntax or vi syntax. By default,
the emacs syntax is enabled. Below are the most useful shortcuts (the complete
list is detailed in the previous link).
Tab
auto-complete commands and files
Up Arrow_ or Down Arrow
allow to navigate through your command history (previous command or next command)
CTRL + r or CTRL + s
backward or forward search in your command history
CTRL + a / CTRL + f
moves the cursor to the beginning / end of the line
ALT + b / ALT + f
moves the cursor backward / forward one word
CTRL + l
clears the screen
CTRL + u
clears the line and copies it to the clipboard
CTRL + k
clears the line after the cursor and copies it to the clipboard