Let's enter our final section for this Linux101 class! And this sections starts with...

Parameters ⚙️

Parameters! Parameters are important : they are options you can add to your commands in order to change their behavior.

For instance, when you type :

$> ls -a

“-a” is a parameter that you add to the command ls.

When you type :

cat challenge_0.txt 

“challenge_0.txt” is a parameter that you add to the command cat.

You can add an infinite number of parameters depending on the ones your script/program supports.

Note : Basically anything written after a single command is a parameter. Parameters are separated by a space.

Shortcuts and wildcards 🃏

History

In a Linux shell, you have multiple syntax helpers and keyboard shortcuts to avoid typing long commands or typing the same thing twice or more.

For instance if you want to run the same command that you just ran again, Key Up will go through your history and display the last command-lines you entered.

Note : The command history will also print the whole command-line history for your shell session.

You can also type :

$> !!

To run the last command again.

Autocompletion

Tab will autocomplete files and directories names, for instance if you type :

$> ls chall

In your home directory and then press Tab, your terminal will automatically replace “chall” with “challenges”.

In case of ambiguity, your shell will not automatically be able to autocomplete your commands, in that case, nothing will be displayed when you press Tab.

Pressing Tab twice in that situation will print the ambiguous file or directory names.

$> ls c # Press Tab twice and observe what is printed

Wildcards

A wildcard is a “magic” character that means everything.

In a Linux shell, a wildcard is represented by the * character, if you type it in your shell, it will be replaced before executing your command by every (non-hidden) files and directories in the current directory.

You can actually test this in your terminal using the following commands :

$> echo * # Will print every file and directory name
$> cat * # Will cat every file in the local directory

Wildcards can also be used in conjunction with other characters, at the start or the end of any character string.

$> echo chall*
$> echo *enge

Permissions

In a Linux filesystem, every file has associated permissions.

Permissions define which actions users or groups of users can do regarding those files and directories.

Users

If you can enter commands on a computer, you are logged in as a user.

The command :

 $> whoami 

Will print your username, this is your identity on the machine.

The $USER environment variable also contains your username, you can display its value with :

$> echo $USER

Your Linux system does not always uses usernames in order to identify users, but each user have a numeric ID called a UID. You can also print your UID using :

$> echo $UID.

Groups

To make permissions management easier, users are divided in groups.

By default on Linux, whenever a user is created, it is part of its own, single-member group whose name is its own.

On term.hack.courses, your group should be “nointernet”, you can display the groups you are part of using the command :

$> groups

You can also display your username, UID, groups name and groups IDs (GIDs) using id :

$> id

Group IDs are the same as UIDs... but for groups! Unique identifier that are used by Linux instead of names that could be ambiguous.

Read, write, execute

Do you remember the ls -l listing we reviewed earlier? Let’s look at it again.

$> ls -l challenges/command_line_101/
total 28
drwxrwxr-x    3 root     root          4096 Jan 11 21:59 .
drwxr-xr-x    3 root     root          4096 Jan 11 21:59 ..
-rw-rw-r--    1 root     root            96 Jan 11 21:59 .challenge_4
-rw-rw-r--    1 root     root           276 Jan 11 21:59 challenge5.sh
-rw-rw-r--    1 root     root           111 Jan  9 15:44 challenge_0.txt
-rw-rw-r--    1 root     root            77 Jan  9 20:57 challenge_1.txt
drwxrwxr-x    3 root     root          4096 Jan 11 21:58 challenge_2

It’s finally time to explain what all of this means, let’s start by investigating in details the first column of this list, the one with characters like -rw-rw-r--.

As I told you earlier, the first character can be either - (which represents an empty space) or d for “directory”.

Then, you have three sequences of “rwx”, each character of each sequence can also be a single -.

Those sequences describe the permissions associated to the file or directory :

  • r - is for read

  • w - is for write

  • x - is for execute

Following this logic, r-- means “read permissions only”, rw- means “read/write permissions only, and rwx means read+write+execute permissions!

Why three consecutive sequences then?

The first sequence is for the user who owns the file/directory (specified in the third column), the second one is for the group who owns the file/directory (specified in the fourth column) and the third one is for everyone else on the computer.


Now, I'll leave you a small quizz before your final challenge, the challenge 8! Good luck and hopefully I'll see you again for the part 2 of this course 😉!