Linux Essentials
Linux command line essentials
pwd: Print current working directory (where am I?)ls: File listingls –l: Detailed file listing, including permissionscd: Change directorychmod: Change file permissionsecho: Print something to the terminalmore: Show contents of a text filenano: Text editorman: Documentation on any Unix command
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:
vi/vim: lightweight, complex, powerful, difficult to useemacs: heavyweight, complex, powerful, difficult to usenano: possibly the simplest editor to use
To edit a file:
$ nano filename
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:
$ 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:
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
$ 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!