Presentation is loading. Please wait.

Presentation is loading. Please wait.

Prepared by: Eng. Maryam Adel Abdel-Hady

Similar presentations


Presentation on theme: "Prepared by: Eng. Maryam Adel Abdel-Hady"— Presentation transcript:

1 Prepared by: Eng. Maryam Adel Abdel-Hady eng.maryamadel@yahoo.com
“ UBUNTU “ lab3 Prepared by: Eng. Maryam Adel Abdel-Hady

2 Commands To see a date To know who use the system
To see more about currently login person(yourself) who am i To clear the screen clear To Print Working Directory pwd To List the files or folders in the current working directory ls To List the files in the working directory in long format (vertically) ls -1 To get a file listing that contains a wealth of information about the files being listed.  la -l To move from a directory to another cd {the_new_directory} To create more files touch {file1_name} {file2_name} {file3_name}

3 Commands To create folders To create a text file
mkdir {folder_name} To create a text file cat > {file_name} You can insert the text in the file and stop by click (ctrl + D) To see the text in the text file less {file_name} Or cat < {file_name} To stop you can click Q To edit the text in the file gedit {file_name} To move or rename file or folder mv {file_name} {new_file_name} To remove the file rm {file_name} To remove all files in the given directory/subdirectories rm –rf {folder_name}

4 Commands To count lines, words and characters of a given file
wc {file_name} To search in a file for specific word or sentence grep {word_to_lookup} {file_name} To print file pr {file_name} To copy file to another (created or no) cp {file_name} {new_file_name} To put the output of “ls” command to file name ls > {file_name} If this file was found, it will remove all its data and write the output of “ls” in it If the file wasn’t found, it will be created ls >> {file_name} If this file was found, it will leave all its data and write the output of “ls” in the end of the file We can execute this rules “ > “ and “ >> “ for any command out put

5 Commands To get the header of a file. Outputs the first few lines of its input. header Ex. ( header -3 file1) >> this will output the first 3 lines of file1 to get the footer of a file. Outputs the last few lines of its input. Useful for things like getting the most recent entries from a log file. tail Ex. ( tail -3 file1) >> this will output the last 3 lines of file1

6 Commands To print out its text arguments on standard output echo
Ex: to print “this is a test “ ( echo this is a test ) , to print all files and folders in the working directory ( echo * ) , To print all files/folders that start by “D” (echo D*) To print all files/folders that end by “s” (echo *s) To print all files/folders that start by upper case character ( echo [[:upper:]]* )

7 Commands You can use the shell prompt as a calculator:
 echo Five divided by two equals $((5/2)) To print a range of letters in reverse order: echo {Z..A} To print “Number_1 Number_2 Number_3 Number_4 Number_5” echo Number_{1..5} Example:   To create a series of directories named in numeric “Year-Month” format.

8 To use the backslash characters, use the echo command with the -e option
For new line  echo -e "Inserting several blank lines\n\n\n this is a test“ For an alert  echo -e "\a My computer went beep” For print a backslash   echo -e "DEL C:\\WIN2K\\LEGACY_OS.EXE"

9 Shell Script

10 What is shell script? With the thousands of commands available for the command line user, how can you remember them all? The answer is, you don't. The real power of the computer is its ability to do the work for you. To get it to do that, we use the power of the shell to automate things. We write scripts Scripts are collections of commands that are stored in a file. The shell can read this file and act on the commands as if they were typed at the keyboard. A shell script is a file that contains ASCII text. To create a shell script, you use a text editor. A text editor is a program, like a word processor, that reads and writes ASCII text files. Text editor such as gedit, kwrite and emacs

11 Getting started with Shell Programming
To successfully write a shell script, you have to do three things: Write a script Give the shell permission to execute it Put it somewhere the shell can find it Write a script: Open your text editor for example: “gedit” by writing: $ gedit Write in the file : #!/bin/bash # My first script echo "Hello World!“ Save the file Give the shell permission to execute it: The next thing we have to do is give the shell permission to execute your script. This is done with the ”chmod” command as follows: $ chmod +x my_script The "755" will give you read, write, and execute permission. Everybody else will get only read and execute permission. Run your script file: $ ./my_script

12 chmod $ chmod u+x,g+wx,o+x myscript NOTE: This command set permission for file called 'myscript' as User (Person who creates that file or directory) has execute permission (u+x) Group of file owner can write to this file as well as execute this file (g+wx) Others can only execute file but can not modify it, Since we have not given w (write permission) to them. (o+x).

13 Variables In Linux (Shell), there are two types of variable:
System variables - Created and maintained by Linux itself. This type of variable defined in CAPITAL LETTERS. Ex. “ BASH , HOME , SHELL” You can write $ echo $SHELL  /bin/bash User defined variables (UDV) - Created and maintained by user. This type of variable defined in lower letters. How to create a variable? To create a variable, put a line in your script that contains the name of the variable followed immediately by an equal sign ("="). No spaces are allowed. After the equal sign, assign the information you wish to store. Note that no spaces are allowed on either side of the equal sign. Ex: n=4  To define variable called n having value 4

14 Rules for Naming variable name
Variable name must begin with Alphanumeric character or underscore character (_), followed by one or more Alphanumeric character. For e.g. Valid shell variable are as follows HOME SYSTEM_VERSION vech no  Don't put spaces on either side of the equal sign when assigning value to variable. For e.g. In following variable declaration there will be no error no=10 But there will be problem for any of the following variable declaration: no =10 no= 10 no = 10 Variables are case-sensitive, just like filename in Linux.  You can define NULL variable as follows (NULL variable is variable which has no value at the time of definition) For e.g. $ vech= $ vech="" Try to print it's value by issuing following command echo $vech Do not use ?,* etc, to name your variable names.

15 Example1 Program that read two numbers and print the summation and the average of them Note: If you need to edit the script file in the terminal screen You can write nano my_script  where my_script is the script file To save your editing click  “ctrl + x “  then “ y”  then “enter”

16 Example Program that read your name , your age , your Address and print “ your name is ……. , your age is and your address is ……..”

17 For more about shell script


Download ppt "Prepared by: Eng. Maryam Adel Abdel-Hady"

Similar presentations


Ads by Google