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)

Slides:



Advertisements
Similar presentations
Jump to first page Unix Commands Monica Stoica Jump to first page Introduction to Unix n Unix was born in 1969 at Bell Laboratories, a research subdivision.
Advertisements

Using Linux Commands Lab 4 1. Create empty files To create an empty file $ touch apple banana grape grapefruit watermelon $ ls -l Using file-matching.
Linux File & Folder permissions. File Permissions In Ubuntu, files and folders can be set up so that only specific users can view, modify, or run them.
File security and Permissions A file is owned by the user who created it That user can then specify who can read, write and execute that file A file when.
Linux+ Guide to Linux Certification, Second Edition
Linux Linux File System.
UNIX Chapter 00 A “ Quick Start ” into UNIX Operating System Mr. Mohammad Smirat.
Linux File Security. What is Permission ? Specifies what right are granting to users to access the resources available in the computer. So that important.
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)
Linux Commands LINUX COMMANDS.
L INUX C OMMAND L INE I NTERFACE G UNAANBAN.G
COMP1070/2002/lec4/H.Melikian COMP1070 Lecture #5  Files and directories in UNIX  Various types of files  File attributes  Notion of pathname  Commands.
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.
CHAPTER 1 UNIX FOR NONPROGRAMMERS By U ğ ur Halıcı.
Linux Directory Navigation. File & Directory Commands This is a minimal list of Unix commands that you must know for file management: ls (list) mkdir.
Linux environment ● Graphical interface – X-window + window manager ● Text interface – terminal + shell.
1 Lecture 2 Working with Files and Directories COP 3344 Introduction to UNIX.
Chapter Nine Advanced Shell Scripting1 System Programming Advanced Shell Scripting.
Unix Basics Chapter 4.
An Introduction to Unix Shell Scripting
Basic unix commands that everyone should know (Even if you have a mac) Slightly more advanced:
The UNIX Shell. The Shell Program that constantly runs at terminal after a user has logged in. Prompts the user and waits for user input. Interprets command.
LIN Unix Lecture 3 Hana Filip. LIN UNIX Resources UNIX Tutorials UNIX help for.
Linux+ Guide to Linux Certification, Second Edition
Working with Linux Lab 1 1. Login and logout Account – username & password – Note: Linux is case-sensitive Administrator: username = root Logout: exit,
System Administration Introduction to Unix Session 2 – Fri 02 Nov 2007 Reference:  chapter 1, The Unix Programming Environment, Kernighan & Pike, ISBN.
File Permission and Access. Module 6 File Permission and Access ♦ Introduction Linux is a multi-user system where users can assign different access permission.
Introduction to Bash Programming Ellen Zhang. Previous three classes What have we learnt so far ?
Scripting Languages Course 2 Diana Trandab ă ț Master in Computational Linguistics - 1 st year
Workbook 6 – Part 2 The Bash Shell
Unix/Linux cs3353. The Shell The shell is a program that acts as the interface between the user and the kernel. –The shell is fully programmable and will.
Managing Files. Module 5 Managing Files ♦ Introduction “On a Linux system, everything is a file; if something is not a file, it is a process.” ♦ Topics.
File Security and Permissions. File Permissions (1) u With respect to a particular file, Unix divides the set of all users on a system into three categories:
Shell Advanced Features. Module 8 Shell Advanced Features ♦ Introduction In Linux systems, the shells are often referred to as command line interfaces.
E X C E E D I N G E X P E C T A T I O N S Basic LINUX Linux System Administration Dr. Hoganson Kennesaw State University Operating Systems Directory structure:
Linux+ Guide to Linux Certification, Third Edition
Linux+ Guide to Linux Certification, Third Edition
LIN Unix Lecture 5 Unix Shell Scripts. LIN Command Coordination ; && || command1 ; command2 Interpretation: Do command 1. Then do command.
Λειτουργικά Συστήματα – Lab2 Γιάννης Πετράκης. Directory Navigation and Control  The Unix file system is set up like a tree branching out from the root.
Linux Commands C151 Multi-User Operating Systems.
2 Manual & Filestore Mauro Jaskelioff. Introduction Using the manual The UNIX filestore File permissions.
1 Lecture 2 Working with Files and Directories COP 3353 Introduction to UNIX.
UNIX filesystem CS 2204 Class meeting 2 *Notes by Doug Bowman and other members of the CS faculty at Virginia Tech. Copyright
File System Security ls -l. First Columm d = directory l = symbolic link b = block special file c = character special file p = fifo (or named pipe) special.
1 CS3695 – Network Vulnerability Assessment & Risk Mitigation – Introduction to Unix & Linux.
Basic Unix Commands. Listing files and directories ● ls:command is used to list the files and ● directories in present working directory ● ls command.
© Prepared By: Razif Razali 1 TMK 265: UNIX SYSTEM CHAPTER FOUR – QUOTING IN DETAIL.
UNIX file systems Learning Objectives: 1. To understand the basics of file systems 2. To understand the hierarchical structure in Unix file system 3. To.
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).
Linux Tutorial Lesson Two *Getting Help in Linux *Data movement and manipulation *Relative and Absolute path *Processes Note: see chapter 1,2,3 from Linux.
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.
Laboratory 1.2a1 First steps with Unix - Lab Boris Steipe Department of Biochemistry Department.
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
Commands Basic syntax of shell commands UNIX or shell commands have a basic structure command -options target command comes first (such as cd or ls) any.
Prepared by: Eng. Maryam Adel Abdel-Hady
Linux 101 Training Module Linux Basics.
Lecture 2 Working with Files and Directories
Useful Linux Commands.
Tutorial of Unix Command & shell scriptS 5027
Basic UNIX OLC Training.
Tutorial of Unix Command & shell scriptS 5027
Using Linux Commands Lab 3.
Permission and CHMOD.
Tutorial of Unix Command & shell scriptS 5027
Linux Shell Script Programming
Module 6 Working with Files and Directories
Lab 2: Terminal Basics.
Linux Commands LINUX COMMANDS.
January 26th, 2004 Class Meeting 2
Presentation transcript:

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)  Argument: is an extra piece of information (ex.: a file name)  Environment variables : where the shell stores information that may be useful to the user’s shell session. Examples of environment variables include $SHELL (which identifies the shell you are using )and$PS1 (which defines your shell prompt) Meta characters: that have special meaning to the shell (>) (>) used to direct the output of a command to a file. ( | ) ( | ) pipe the output to another command.

Environment variables : Environment variables :

Getting Help with Using the Shell Use --help with the command (date -- help)

Use the man command  man = manual  To reading a manual and return to the shell prompt within the open terminal  press q

Understanding file permission  Why Keep users from accessing other users’ private files To protect important system files  permissions bits rwx rwx rwx Owner’s| Group | Others r = readw = writex = execute $ ls –al -rw-rw-r-- 1 chris sales 1024 May 10 01:49.. drwxr-xr-x 2 chris sales 2204 May 18 21:30.bash_history

Understanding file permission For Files:  "Read" means to be able to open and view the file  "Write" means to overwrite or modify the file  "eXecute" means to run the file as a binary files are executable only if they are programs and shell scripts, not useful for data files. For Directories:  "Read" means to be able to view the contents of the directory  "Write" means to be able to create new files/directories or delete files/directories within the directory  "eXecute" means to be able to "Change Directory" (cd) into the directory = permission to access the directory. How to view the permission for a file or directory?  $ ls -al

Understanding file permission d ≡ directory - ≡ file Permission for the owner Permission for the group Permission for the others  if the permission field is -  the permission is not given.

Understanding file permission Only the owner of a file can change its permission. How to set file permission?  Use the command chmod(change file mode bits). chmod has two notations:  Numeric(octal) notation.  Symbolic notation.

Change permission on a file - numeric the file permissions aren't represented by characters. Instead, they are represented by a three-digit octal number. 4 = read (r) 2 = write (w) 1 = execute (x) 0 = no permission (-) Octal#(421)Binarypermission x w wx r r-x rw rwx rwx-w- r-x If the permission is

Change permission on a file – symbolic Permissions are represented by characters rwx This gives “who” the specified permissions for a given filename. The “who” is a list of letters re going to be giving permissions to. These may be specified in any order. +  add the selected permission. -  remove the selected permission. chmodwho + permissionfilename - uThe user who owns the file (this means “you.”) gThe group the file belongs to. oThe other users not in the file’s group. a all of the above (an abbreviation for ugo)

Change permission on a file For r, w, x octal value is 4,2,1 respectively $ chmod 777 file-name  rwxrwxrwx $ chmod 755 file-name  rwxr-xr-x owner(u) group(g) other(o) all(a) rwxrwxrwx $ chmod a-w file-name  r-xr-xr-x $ chmod go-rwx file-name  rwx owner(u) group(g) other(o) all(a) $ chmod u+rw file-name  rw

Creating files and directories Use the command mkdir to create a new directory to the current working directory. $ mkdir directoryName 13

Creating directories (Exercise) cd. 1.Go to your home directory. Type cd. pwd 2.Make sure that you got to your home directory, type pwd 3.Create a new directory called test in your home directory: 4.Check the permissions of the directory by typing: ((The -d option tells ls not to list the contents of the test directory; just show us the listing for the directory itself)). 5.Suppose that you want to prevent everyone else from using or viewing the files in this directory: 6.Make the test directory your current directory : $ mkdir test $ chmod 700 test $ cd test 14 $ ls –ld test drwxr-xr-x 2 chris sales 1024 May 18 21:30 test

Creating directories To create a directory(test) in the Desktop, we have two ways:  mkdir /home/chris/Desktop/test  cd /home/chris/Desktop mkdir test NOTE:  The -d option tells ls not to list the contents of the test directory; just show us the listing for the directory itself. 15 $ ls –ld testprovide a long listing of the test directory, without showing the contents of the test directory.

Moving, copying, and deleting files The command mv moves or renames files. - The simplest form of use is: mv oldfilename newfilename mv oldfilename newfilename. it will rename the file a.kwd to a new name b.kwd $ mv file1 file2  Renaming - It will also move a file to a directory. If you use it in the form: mv filename directoryname it will move the file into the named directory keeping its old name $ mv file2 \test or mv file2 test 16

Moving, copying, and deleting files To copy files, you use the cp command. The following will copy file to file2. Note that if file2 doesn't exist, it'll be created, but if it exists, it'll be overwritten: $ cp file file2 If you want to copy file into directory dir1: $ cp file dir1 To remove a file from the current directory rm filename $ rm file $ rm * *  remove all files in the current directory 17

Create empty files To create an empty file in the current directory use the command touch $ touch file1 file2 file3 $ touch apple banana grape grapefruit watermelon $ ls -l Using file-matching metacharacters Metacharacters help to match one or more files without typing each filename completely.  *This matches any number of characters(zero or more characters).  ?This matches any one(single) character.  […]This matches any one of the characters between the brackets, which can include a dash-separated rang of letters or numbers. 18

$ ls a* The first example matches any file that begins with a apple $ ls g* The second example matches any file that begins with g grape grapefruit $ ls g*t This example matches any file beginning with g and ending in t grapefruit $ ls *e* matches any file that contains e in the name apple grape grapefruit watermelon $ ls *n* matches any file that contains n in the name banana watermelon Using file-matching metacharacters Using file-matching metacharacters This matches any number of characters * 19

Using file-matching metacharacters Using file-matching metacharacters This matches any one(single) character? $ ls ????e The first example matches any five-character file that ends in e Apple grape $ ls g???e* The second matches any file that begins with g and has e as its fifth character grape grapefruit 20

Using file-matching metacharacters Using file-matching metacharacters This matches any one of the characters between the brackets […] $ ls [abw]* any file beginning with a,b or w is matched apple banana watermelon $ ls [agw] * [ne] any file that begins with a,g or w and also ends with either n or e is matched apple grape watermelon $ ls [a-g] * any filenames beginning with letter from a through g are matched apple banana grape grapefruit 21

Using file-redirection metacharacters $ mail root < ~/.bashrc the contents of the.bashrc file in the home directory are sent in a mail message to the computer's root user. $ echo “I finished the project on $(date)” > ~/projects < Direct the contents of a file to the command overwriting > Direct the output of a command to a file, overwriting any existing file adding >> Direct the output of a command to a file, adding the output to the end of existing file $ echo “I finished the project on $(date)” >> ~/projects 22

echo Command Use echo command to display text or value of variable. echo [options] [string, variables...] 23

Quotes "Double Quotes“  variables and command substitution(except \ and $). 'Single quotes‘  protects everything enclosed between two single quote marks.  It is used to turn off the special meaning of all characters ( NO substitution of variables and commands). `Back quote`  Used with commands only.  To execute command. 24

commandvariable Double “ “ Back ` ` $echo “My working directory is `pwd`” The output: My working directory is /home/nora/Desktop - Single ‘ ‘ Back ` ` $echo ‘My working directory is `pwd`’ The output: My working directory is `pwd` - Double “ ” $echo “My working directory is pwd” The output: My working directory is pwd $echo “the home is $HOME” The output: the home is /home/nora Single ‘ ‘ $echo ‘My working directory is pwd’ The output: My working directory is pwd $echo ‘the home is $HOME’ The output: the home is $HOME 25

echo Command Options -n Do not output the trailing new line. -e Enable interpretation of the following backslash escaped characters in the strings: \a alert (bell) \b backspace \n new line \t horizontal tab 26

Examples of quoting special characters echo –n “operating system” operating system $ echo –e “operating \t system” Operating system $ echo -e "An apple a day keeps away \a\t\tdoctor\n" An apple a day keeps away doctor 27

References 29