Prepared by: Eng. Maryam Adel Abdel-Hady

Slides:



Advertisements
Similar presentations
Learning Unix/Linux Bioinformatics Orientation 2008 Eric Bishop.
Advertisements

Introducing the Command Line CMSC 121 Introduction to UNIX Much of the material in these slides was taken from Dan Hood’s CMSC 121 Lecture Notes.
Now, return to the Unix Unix shells: Subshells--- Variable---1. Local 2. Environmental.
Information Networking Security and Assurance Lab National Chung Cheng University 1 What Linux is? Free Unix Like Open Source Network operating system.
Guide To UNIX Using Linux Third Edition
T UTORIAL OF U NIX C OMMAND & SHELL SCRIPT S 5027 Professor: Dr. Shu-Ching Chen TA: Samira Pouyanfar Spring 2015.
Unix Basics. Systems Programming: Unix Basics 2 Unix Basics  Unix directories  Important Unix file commands  File and Directory Access Rights through.
Introduction to Linux and Shell Scripting Jacob Chan.
Shell Script Examples.
Linux Commands LINUX COMMANDS.
L INUX C OMMAND L INE I NTERFACE G UNAANBAN.G
CS 141 Labs are mandatory. Attendance will be taken in each lab. Make account on moodle. Projects will be submitted via moodle.
Using Macs and Unix Nancy Griffeth January 6, 2014 Funding for this workshop was provided by the program “Computational Modeling and Analysis of Complex.
Introducing UNIX EMBnet slide 1 Introducing the UNIX Operating System.
Chapter 9 Part II Linux Command Line Access to Linux Authenticated login using a Linux account is required to access a Linux system. The Linux prompt will.
Linux environment ● Graphical interface – X-window + window manager ● Text interface – terminal + shell.
1 Operating Systems Lecture 3 Shell Scripts. 2 Brief review of unix1.txt n Glob Construct (metacharacters) and other special characters F ?, *, [] F Ex.
Essential Unix at ACEnet Joey Bernard, Computational Research Consultant.
Agenda User Profile File (.profile) –Keyword Shell Variables Linux (Unix) filters –Purpose –Commands: grep, sort, awk cut, tr, wc, spell.
Linux+ Guide to Linux Certification, Third Edition
Unix Tutorial for FreeSurfer Users. Helpful To Know FreeSurfer Tutorial Wiki:
System Administration Introduction to Unix Session 2 – Fri 02 Nov 2007 Reference:  chapter 1, The Unix Programming Environment, Kernighan & Pike, ISBN.
Unix Tutorial for FreeSurfer Users. Helpful To Know FreeSurfer Tutorial Wiki:
Week 3 Exploring Linux Filesystems. Objectives  Understand and navigate the Linux directory structure using relative and absolute pathnames  Describe.
Introduction to Bash Programming Ellen Zhang. Previous three classes What have we learnt so far ?
UNIX Shell Script (1) Dr. Tran, Van Hoai Faculty of Computer Science and Engineering HCMC Uni. of Technology
1 Operating Systems Lecture 2 UNIX and Shell Scripts.
Writing Scripts Hadi Otrok COEN 346.
40 Years and Still Rocking the Terminal!
Introduction to Programming Using C An Introduction to Operating Systems.
Using Linux Commands Lab 4. Using the Shell in Linux Commands Syntax  Options: could be added to the commands to change their behavior (-a, -la, --help)
Lesson 3-Touring Utilities and System Features. Overview Employing fundamental utilities. Linux terminal sessions. Managing input and output. Using special.
PTA Linux Series Copyright Professional Training Academy, CSIS, University of Limerick, 2006 © Workshop III - Part A Shell Commands Professional Training.
Introduction to Unix (CA263) Command File By Tariq Ibn Aziz.
Shell Script Reference: Linux Shell Scripting Tutorial v1.05r3 A Beginner's handbook
File Management commands cat Cat command cat cal.txt cat command displays the contents of a file here cal.txt on screen (or standard out).
 Prepared by: Eng. Maryam Adel Abdel-Hady
 Prepared by: Eng. Maryam Adel Abdel-Hady
Learning Unix/Linux Based on slides from: Eric Bishop.
Linux Administration Working with the BASH Shell.
 Prepared by: Eng. Maryam Adel Abdel-Hady
Lab 7 Shell Script Reference: Linux Shell Scripting Tutorial v1.05r3 A Beginner's handbook
Shell scripts – part 1 Cs 302. Shell scripts  What is Shell Script? “Shell Script is series of command written in plain text file. “  Why to Write Shell.
INTRODUCTION TO SHELL SCRIPTING By Byamukama Frank
Bash Scripting CIRC Summer School 2016 Baowei Liu CIRC Summer School 2016 Baowei Liu.
Introduction to Unix for FreeSurfer Users
GRID COMPUTING.
UNIX To do work for the class, you will be using the Unix operating system. Once connected to the system, you will be presented with a login screen. Once.
Tutorial of Unix Command & shell scriptS 5027
Introducing the UNIX Operating System.
CIRC Winter Boot Camp 2017 Baowei Liu
Getting started with CentOS Linux
Linux 101 Training Module Linux Basics.
CSE 390a Lecture 5 Intro to shell scripting
Some Linux Commands.
The Linux Operating System
Shell Script Assignment 1.
INTRODUCTION TO UNIX: The Shell Command Interface
Tutorial of Unix Command & shell scriptS 5027
Basic UNIX OLC Training.
Introduction to UNIX.
Tutorial of Unix Command & shell scriptS 5027
Using Linux Commands Lab 3.
LING 408/508: Computational Techniques for Linguists
Tutorial of Unix Command & shell scriptS 5027
Getting started with CentOS Linux
Linux Shell Script Programming
Intro to shell scripting
Lab 7 Shell Script Reference:
Linux Commands LINUX COMMANDS.
Presentation transcript:

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

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}

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}

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

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

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:]]* )

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.

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"

Shell Script

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

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

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).

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

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.

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”

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

For more about shell script http://linuxcommand.org/lc3_learning_the_shell.php http://www.youtube.com/watch?v=QGvvJO5UIs4&feature=share&list=PL9C76917D6B09D8E3 http://www.mediafire.com/view/?qhuqxxxm7puejm5