Comparaison des versions

Légende

  • Ces lignes ont été ajoutées. Ce mot a été ajouté.
  • Ces lignes ont été supprimées. Ce mot a été supprimé.
  • La mise en forme a été modifiée.

...

To edit a file it is best to use an editor. For example:

      emacs Reference Card (more intuitive)
      vi Reference Card (available on all Linux systems)

Wild cards

A number of characters are interpreted by shell before any other action takes place. These characters are known as wildcard characters. Usually these characters are used in place of filenames or directory names.

*An asterisk matches any number of characters in a filename, including none.
?The question mark matches any single character.
[ ]Brackets enclose a set of characters, any one of which may match a single character at that position.
-A hyphen used within [ ] denotes a range of characters.
~A tilde at the beginning of a word expands to the name of your home directory. If you append another user's login name to the character, it refers to that user's home directory.


Here are some examples:

  • cat c* : displays any file whose name begins with c including the file c, if it exists.
  • ls *.c : lists all files that have a .c extension.
  • cp ../rmt? .  : copies every file in the parent directory that is four characters long and begins with rmt to the working directory. (The names will remain the same.)
  • ls rmt[34567] : lists every file that begins with rmt and has a 3, 4, 5, 6, or 7 at the end.
  • ls rmt[3-7] : does exactly the same thing as the previous example.
  • ls ~ : lists your home directory.
  • ls

...

  • ~username : lists the home directory of the guy with the user

...

  • name username.

Change File & Directory Access Permissions

(These are the permission you see with the 'ls -l' command - see above.)

      chmod [ who option permission ] filename
who file-/directory-name(s)

'who' can be any combination of:
    u (user)
    g (group)
    o (other)
    a (all) (i.e. ugo)

'option' adds or takes away permission, and can be:
    + (add permission),
    - (remove permission), or
    = (set to exactly this permission).

'permission' can be any combination of
    r (read)
    w (write)
    x (execute)

Example: chmod a+x filename - makes filename executable by everyone.

Display a message

      echo"message" : diaplaysdisplays/prints 'message'.

Examples:
     $ echo Hello
             Hello
     $ echo "Hello there"
             Hello there

Variables

Quotes: single vs. double

Single quotes preserve all special characters and treat everything inside them as a literal string, including variables and commands. On the other hand, double quotes allow variable expansion and command substitution within the string and interpret some special characters as escape characters.

Examples:

      a="Hello there"
      echo $a
         Hello there
      echo "$a"
         Hello there
      echo '$a'
         $a

Variables

You can create You can create variables and assign values to them.
There are two kinds of variables: local variables and environment variables.
The difference between the two is that environment variables are passed down to child processes (sub shell, scripts, programs)
There are already several environment variables set which you can see with the command:
    env

A variable name always needs to start with a letter.
To get the content of a variable the variable needs to be preceded with a dollar sign ($)

Examples:
    person=Alex     person=Alex          #  Never put a space before or after the equal sign!
    echo person
            person
    echo $person
            Alex
    echo $personis
   
    echo ${person}is
            Alexis
    echo "$person"
            Alex                         # => double quotes evaluate
    echo '$person'
            $person                   # => single quotes: No evaluation done !!!

...

If you just set 'variable=word' the variable will only be known in the current shell/script in which it is set.
If you "export" the variable becomes an environment variable and will also be know in all scripts which get executed in this shell/script.
For example ifyou export a variable in your file '~/.profile_usr' resp. '~/.profile.d/.interactive_profile' it will be available in all sub shells.

      export
variable=wordcontent

The value of the variable is set to word 'content'.

Example:
    $ export CMCLNG=english
or
    $ CMCLNG=english
    $ export CMCLNG
   

Alias

      alias alias-string='command-string'
Alias
And alias abbreviates a command string with an alias string. For multi-command strings, enclose commands in single quotes.

Examples:
    $       alias data='cd ~data/Validation'
    $       alias vo='voir -iment'
    $       alias rd=r.diag
    $       alias rg='r.diag ggstat'

If you put aliases in your file '~/.profile.d/.interactive_profile' they will be available in all terminals/windows after a new login.

Date

      date : display time and date
Check 'man date' for different format options.

Evaluate a command

You can evaluate a command and store the answer in a variable.
For example if you want to store the current date in a variable you can use:
    $ 
      current_date=`date`
or
    $  the newer method:
      current_date=$(date)
    $        echo $current_date

...

Arithmetic

    $        year=2013
    $        next_year=$((  year + 1 ))
or
          (( next_year = year + 1 ))
    $        echo $next_year
              2014

% : modulo / remainder
    $        echo $(( 10 % 3 ))
              1

Just be careful and never try arethmetic arithmetic operations on numbers starting with a zero!!!

Formatted print

      printf : produces  output  according to a format.

Example:
    $        printf '%3.3d\n' $(( 1 + 15 ))
              016

'\n' give you gives a new line.
For more information check: man 3 printf

History

      history : lists the most recent commands

Exit/Close a

...

terminal or exit a script

To close a window do not just click on the "x" but type 'exit' and then press <Enter>.
For each window some temporary files and directories are created with will only get cleaned up when using 'exit'The easiest way to exit a script/process is by pressing the keys Ctrl-c.
The easiest way to close a terminal by pressing the keys Ctrl-d.

Escape character

      \ : back slash, escape character

'\' prevents the following character from being "interpreted". There are several "special characters" in shell which have a certain "meaning" and functions as little "commands".
Unfortunately '\' has different meanings depending on where/how it gets used.
Examples:
    $  person=Alex
    $  echo $person
    Alex
    $  echo \$person
    $person              => No evaluation done !!!
    $  echo "\$person"
    $person              => No evaluation done !!!
    $  echo '\$person'
    Alex                   => Evaluation done !!!

When used as the very last character in a line it will surpress the "new line".
    $ cat > text_file << EOF
    > Hello
    > How are you?
    > EOF
    $ cat text_file
    Hello
    How are you?

    $ cat > text_file << EOF
    > Hello, \
    > how are you?
    > EOF
    $ cat text_file
    Hello, how are you?

...