Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentes Révision précédente
Prochaine révision
Révision précédente
linux_essential [2017/04/19 07:47] – [Linux command line essentials] adminlinux_essential [2017/04/19 08:52] (Version actuelle) – [File permissions] admin
Ligne 11: Ligne 11:
   * ''echo'': Print something to the terminal   * ''echo'': Print something to the terminal
   * ''more'': Show contents of a text file   * ''more'': Show contents of a text file
-  * ''nano'' : Text editor     +  * ''nano'': Text editor     
-  * ''man'': Documentation on any Unix command:+  * ''man'': Documentation on any Unix command
  
 +===== Basic Unix Exercises: Making directories =====
  
 +What directory am I currently in?
  
 +<code bash>
 +$ pwd
  
 +/Home/Users/kmazouzi
 +</code>
  
  
 +Create a directory named ''test_1''
  
 +<code bash>
 +$ mkdir test_1
 +</code>
  
 +<code bash>
 +$ ls
  
 +test_1
 +</code>
 +
 +
 +Change into that directory, and verify that we are there.
 +
 +<code bash>
 +$ cd test_1
 +</code>
 +
 +<code bash>
 +$ pwd
 +
 +/Home/Users/kmazouzi/test_1
 +</code>
 +
 +Return to your home directory:
 +''cd'' with no arguments
 +
 +<code bash>
 +$ cd
 +</code>  
 +
 +
 +===== File editing =====
 +
 +List of well known editors:
 +
 +  * ''vi/vim'': lightweight, complex, powerful, difficult to use
 +  * ''emacs'': heavyweight, complex, powerful, difficult to use
 +  * ''nano'': possibly the simplest editor to use
 +
 +To edit a file: <code bash>$ nano filename</code>
 +
 +===== Hello World in ''Bash'' =====
 +
 +**Bash** is a shell scripting language.
 +  * It is the default scripting language that you have at the terminal.
 +  * I.e: You are already using it.
 +  * We will take this command:
 +
 +<code bash>
 +$ echo "Hello World!"
 +
 +Hello World!
 +</code>
 +
 +
 +create a file named ''hello.sh'' containing a single line:
 +
 +<code>echo "hello world!"</code>
 +
 +<code bash>
 +$ nano hello.sh
 +</code>
 +
 +Exit nano. Verify the contents of the file:
 +
 +<code bash>
 +$ more hello.sh
 +
 +echo "hello world!"
 +</code>
 +
 +Then invoke it using the ''bash'' interpreter:
 +
 +<code bash>
 +$ bash hello.sh
 +
 +Hello World!
 +</code>
 +
 +**Hello world script**
 +
 +We can run automatically the script without calling bash. 
 +The **#!** line tells the system to automatically run bash.
 +
 +<code bash>
 +$ nano hello.sh
 +</code>
 +
 +<code bash>
 +#!/bin/bash
 +
 +echo "hello world”
 +</code>
 + 
 +===== File permissions =====
 +
 +Files have properties:
 +
 +  * ''Read'', ''Write'', ''Execute''
 +  * Three different types of user: ''owner'', ''group'', ''everyone''
 +
 +
 +To take a script you have written and turn it into an executable program,
 +run “chmod +x” on it
 +
 +<code bash>
 +$ ls -al 
 +-rw-rw-r--   1 kmazouzi staff   33 avril 19 10:48 hello.sh
 +</code>
 +
 +<code bash>
 +
 +$ chmod +x hello.sh
 +
 +</code>
 +
 +<code bash>
 +$ ls -al 
 +-rwxrwxr-x   1 kmazouzi staff   33 avril 19 10:48 hello.sh
 +</code>
 +
 +**Execute the hello world script**
 +
 +<code bash>
 +$ ./hello.sh
 +
 +Hello World!
 +</code>
  
  • linux_essential.1492588076.txt.gz
  • Dernière modification : 2017/04/19 07:47
  • de admin