Table des matières

Linux Essentials

Linux command line essentials

Basic Unix Exercises: Making directories

What directory am I currently in?

$ pwd
 
/Home/Users/kmazouzi

Create a directory named test_1

$ mkdir test_1
$ ls
 
test_1

Change into that directory, and verify that we are there.

$ cd test_1
$ pwd
 
/Home/Users/kmazouzi/test_1

Return to your home directory: cd with no arguments

$ cd

File editing

List of well known editors:

To edit a file:

$ nano filename

Hello World in ''Bash''

Bash is a shell scripting language.

$ echo "Hello World!"
 
Hello World!

create a file named hello.sh containing a single line:

echo "hello world!"
$ nano hello.sh

Exit nano. Verify the contents of the file:

$ more hello.sh
 
echo "hello world!"

Then invoke it using the bash interpreter:

$ bash hello.sh
 
Hello World!

Hello world script

We can run automatically the script without calling bash. The #! line tells the system to automatically run bash.

$ nano hello.sh
#!/bin/bash
 
echo "hello world”

File permissions

Files have properties:

To take a script you have written and turn it into an executable program, run “chmod +x” on it

$ ls -al 
-rw-rw-r--   1 kmazouzi staff   33 avril 19 10:48 hello.sh
$ chmod +x hello.sh
$ ls -al 
-rwxrwxr-x   1 kmazouzi staff   33 avril 19 10:48 hello.sh

Execute the hello world script

$ ./hello.sh
 
Hello World!