Basic commands

Several commands are available to navigate inside the filesystem. Test and explain the following commands:

pwd
cd
ls
cat

Locating binaries

which is the binary locator command on Linux.

  1. Try typing which ls and explain the result.
  2. Try typing which cd and explain the result.

Getting help

man is the manual utility on Linux. It’s used to get documentation on a given command.

  1. Try typing man ls and explain the result.
  2. Try typing man man and explain the result.
  3. Try typing man cd and explain the result.
  4. What’s the difference between man chmod and man 2 chmod

Playing with files

As seen previously, Linux comes with a set of commands to perform basic operation. This part focuses on file management. Test and explain the following commands:

touch foo
cp foo bar
mv bar foo.bar
rm foo.bar

Playing with directories

Directories are particular files that can contain other files. The command used to act on them differs a little. Test and explain the following commands:

mkdir meh
mv meh foo-bar
rm foo-bar

Is the directory removed ? Find a solution to delete it.

Reading files

Create a file and open it with your preferred file editor. (For instance Kate for KDE)

Write the following text and save the file:

Lorem ipsum dolor sit amet, consectetur adipiscing elit. In quis.
Nulla placerat, odio id sollicitudin semper, dui lorem finibus massa, vel finibus tellus lectus ut odio.
Etiam malesuada consequat lectus, ac dapibus odio venenatis auctor.
Proin nec enim id eros commodo venenatis.
Phasellus vitae mollis tellus. Integer ultricies justo eu erat gravida pellentesque.
Etiam volutpat, augue a fermentum convallis, augue ante ultrices dui, quis malesuada nunc mauris eget est.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. In quis.
Nulla placerat, odio id sollicitudin semper, dui lorem finibus massa, vel finibus tellus lectus ut odio.
Etiam malesuada consequat lectus, ac dapibus odio venenatis auctor.
Proin nec enim id eros commodo venenatis.
Phasellus vitae mollis tellus. Integer ultricies justo eu erat gravida pellentesque.
Etiam volutpat, augue a fermentum convallis, augue ante ultrices dui, quis malesuada nunc mauris eget est.
  1. Use the head command to display the beginning of the file.
  2. Use man head to display the two first lines of the file.
  3. Use the tail command to display the end of the file.
  4. Use man tail command to display the two last lines of the file.
  5. Use tail -n 0 -F <FILE_NAME>. Open the file again with your preferred editor, add a line and save it. Describe what is happening in the terminal.

Environment variables

  1. How to initialize a variable ?
  2. How to visualize a variable ?
  3. How to delete a variable ?
  4. What is the default value for HOME and PATH variables ?
  5. What is the difference between exported and standard variables ?
  6. List environment variables using set and envcommands.

File permission

Create a new file using the touch command then change the file permission using the chmod 321 <FILE_NAME> command.

  1. Which users can execute the file ?
  2. Which users can write to the file ?
  3. Write the command to remove execution permission to all possible users.

Redirection

Simple redirection

Explain the result of the following commands:

MY_VARIABLE="Hello"
echo -n ${MY_VARIABLE} > MY_FILE
echo " World" >> MY_FILE

Redirection & Pipes

Cat usage

What is the result of the following command cat > MY_FILE ?

Note: CTRL-d can be usefull to stop the command

Redirect stderr

Given that some-command > some-output is redirecting stdout (standard output) to some other output. And that 2>&1 is redirecting stderr (standard error) to stdout.

Write a command that list the content of a non existing directory and redirect standard error to a file.

More commands

Explain the result of the following commands:

cat > file.txt
cat file.txt
sort < file.txt
cat >> file.txt
sort < file.txt
sort < file.txt > sorted.file.txt
cat file.txt sorted.file.txt

Pipes

Explain the result of the following commands:

ls -al /bin | more
ls -l /bin | sort
ls -l /bin | wc -l

Compile C programs

Create a file named sample_program.c and write the following source code :

#include <stdio.h>

int main (void) {
	printf("Hello World !\n");
}

  1. Use gcc command (GNU C Compiler) to compile the C source code file.
  2. Use the -o option to name the executable sample-program.
  3. Use strings command on the generated binary. What is outputted ?
  4. Use ldd command on the generated binary. What is outputted ?

Extra command

Explain what is performed by this command :

:(){ :|:& };:

:warning: launch it at your own risks :stuck_out_tongue_winking_eye: