Différences
Ci-dessous, les différences entre deux révisions de la page.
| 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:46] – admin | linux_essential [2017/04/19 08:52] (Version actuelle) – [File permissions] admin | ||
|---|---|---|---|
| Ligne 4: | Ligne 4: | ||
| - | * “pwd”: Print current working directory (where am I?) | + | * '' |
| - | * “ls”: File listing | + | * '' |
| - | * “ls –l”: Detailed file listing, including permissions | + | * '' |
| - | * “cd”: Change directory | + | * '' |
| - | * “chmod”: Change file permissions | + | * '' |
| - | * “echo”: Print something to the terminal | + | * '' |
| - | * “more”: Show contents of a text file | + | * '' |
| - | * “nano” : Text editor | + | * '' |
| + | * '' | ||
| + | ===== Basic Unix Exercises: Making directories ===== | ||
| + | What directory am I currently in? | ||
| + | <code bash> | ||
| + | $ pwd | ||
| + | / | ||
| + | </ | ||
| + | Create a directory named '' | ||
| + | <code bash> | ||
| + | $ mkdir test_1 | ||
| + | </ | ||
| + | <code bash> | ||
| + | $ ls | ||
| + | test_1 | ||
| + | </ | ||
| + | |||
| + | |||
| + | Change into that directory, and verify that we are there. | ||
| + | |||
| + | <code bash> | ||
| + | $ cd test_1 | ||
| + | </ | ||
| + | |||
| + | <code bash> | ||
| + | $ pwd | ||
| + | |||
| + | / | ||
| + | </ | ||
| + | |||
| + | Return to your home directory: | ||
| + | '' | ||
| + | |||
| + | <code bash> | ||
| + | $ cd | ||
| + | </ | ||
| + | |||
| + | |||
| + | ===== File editing ===== | ||
| + | |||
| + | List of well known editors: | ||
| + | |||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | |||
| + | To edit a file: <code bash>$ nano filename</ | ||
| + | |||
| + | ===== Hello World in '' | ||
| + | |||
| + | **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! | ||
| + | </ | ||
| + | |||
| + | |||
| + | create a file named '' | ||
| + | |||
| + | < | ||
| + | |||
| + | <code bash> | ||
| + | $ nano hello.sh | ||
| + | </ | ||
| + | |||
| + | Exit nano. Verify the contents of the file: | ||
| + | |||
| + | <code bash> | ||
| + | $ more hello.sh | ||
| + | |||
| + | echo "hello world!" | ||
| + | </ | ||
| + | |||
| + | Then invoke it using the '' | ||
| + | |||
| + | <code bash> | ||
| + | $ 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. | ||
| + | |||
| + | <code bash> | ||
| + | $ nano hello.sh | ||
| + | </ | ||
| + | |||
| + | <code bash> | ||
| + | #!/bin/bash | ||
| + | |||
| + | echo "hello world” | ||
| + | </ | ||
| + | |||
| + | ===== File permissions ===== | ||
| + | |||
| + | Files have properties: | ||
| + | |||
| + | * '' | ||
| + | * Three different types of user: '' | ||
| + | |||
| + | |||
| + | 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-- | ||
| + | </ | ||
| + | |||
| + | <code bash> | ||
| + | |||
| + | $ chmod +x hello.sh | ||
| + | |||
| + | </ | ||
| + | |||
| + | <code bash> | ||
| + | $ ls -al | ||
| + | -rwxrwxr-x | ||
| + | </ | ||
| + | |||
| + | **Execute the hello world script** | ||
| + | |||
| + | <code bash> | ||
| + | $ ./hello.sh | ||
| + | |||
| + | Hello World! | ||
| + | </ | ||