Introduction to unix linux solaris
This presentation is the property of its rightful owner.
Sponsored Links
1 / 43

Introduction to Unix/Linux/Solaris PowerPoint PPT Presentation


  • 80 Views
  • Uploaded on
  • Presentation posted in: General

Introduction to Unix/Linux/Solaris. Text console mode Usually a black screen with white text All commands are typed in You cannot use a mouse You must hit <enter> after every command to activate the command To logout, type logou t <enter> or hit <ctrl>d.

Download Presentation

Introduction to Unix/Linux/Solaris

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Introduction to unix linux solaris

Introduction to Unix/Linux/Solaris


Introduction to unix linux solaris

  • Text console mode

  • Usually a black screen with white text

  • All commands are typed in

  • You cannot use a mouse

  • You must hit <enter> after every command to activate the command

  • To logout, type logout<enter> or hit <ctrl>d


Shells

“A Unix shell is a command-line interpreter that provides a traditional user interface for the Unix operating system and for Unix-like systems.”

“Users direct the operation of the computer by entering commands as text for a command line interpreter to execute or by creating text scripts of one or more such commands.”

from wikipedia

Shells create processes that execute user commands.

SHELLS


Shells1

most popular:

csh (%)

bash ($)

tcsh

ksh

SHELLS


Which shell is my default shell

WHICH SHELL IS MY DEFAULT SHELL?


Introduction to unix linux solaris

You can also see the shells supported on your machine by typing cat /etc/shells$ cat /etc/shells/bin/bash/bin/csh/bin/jsh/bin/ksh/bin/pfcsh/bin/pfksh/bin/pfsh/bin/sh/bin/tcsh/bin/zsh/sbin/jsh/sbin/sh/usr/bin/bash/usr/bin/csh

To switch to another shell, just type in the name of the shell

  • bash <enter>

  • csh <enter>

  • To go back to your original shell, enter <ctrl>d, logout, or exit

  • To see which shell you are using, enter echo $SHELL


Configuration files

When you log in, the shell will load your configuration file (if present). It "sets up" your shell environment.

These files start with a period (.) and should be located in your home directory.

These files are not listed by ls by default. (They are “invisible.”) To have ls list them, use the –a option.

Use .cshrc for csh; use .bashrc for bash.

.cshrc is executed every time a new c-shell is started (and is executed first when you login)

CONFIGURATION FILES


Example cshrc

EXAMPLE .CSHRC


Environment variables

Environment variables

  • The settings and values that control the way you work on the system.

  • Environment variables are managed by the shell

  • Any program that you start (including another shell) receives a copy of these variables which then may be read, modified, and passed on to their own child processes

  • Type env to see your environment variables and their values.


Setenv

setenv

  • The following example sets the PATH variable to search for

  • files in the /bin, /usr/bin, and /usr/sbin directories, in that order:

  • In c-shell: setenv PATH "/bin:/usr/bin:/usr/sbin“

  • setenv  VARIABLE value

  • To add the path /usr/ucb to the environment variable PATH:

  • csh% setenv PATH $PATH:/usr/ucb

  • To avoid having to type this every time you login, put it in your .cshrc startup file


Introduction to unix linux solaris

setenv (csh) vs. export (bash)

setenv PATH /home/fatalay/mpich2-install/bin:$PATH

export PATH=/usr/ccs/bin:$PATH

alias (csh) vs. alias (bash)

alias emacs /home/fatalay/emacs-23.4/src/emacs

alias emacs=/home/fatalay/emacs-23.4/src/emacs


Commands

Commands

  • Here are the most basic commands in Unix

    • ls displays a list of files in the current directory

    • cd directory change directories

    • passwd change the password for the current user

    • cat textfile throws content of textfile on the screen

    • pwd display present working directory

    • exit or logout leave this session

    • man command read man pages on command


Commands1

Commands

  • A command usually has three partsFormat:

    command [options(s)] arguments

  • The command

    • ls

  • The options

    • Almost always preceded by a hyphen ( - ) and no space between the hyphen and the option

      • ls -l

    • May group multiple options together, in any order

      • ls -la

      • ls -al

    • Many commands can be used without options

      • ls

    • Some commands have no options

  • The arguments

    • Specifications for the object(s) on which you want the command to take effect

      • ls /homes

    • some options take arguments

      • gcc -o myprog.out myprog.c

      • gcc myprog.c -o myprog.out


Listing files

Listing Files

  • ls   displays a list of files in the current working directory

  • -l   long listing format

    • -rw-rw-r--    1 fatalay    MACS         703 Jan  6  2014 test2.c

      • File type and permissions

      • Number of hard links

      • Owner name

      • Group name

      • Size in bytes

      • Timestamp (by default, the modification time)

      • file name

  • -a   list all files/directories including hidden files (those that begin with .)

  • -R   List the contents of all directories recursively


Changing directories

Changing Directories

cd   Change directories

  • You can use relative path names or absolute pathnames

    • cd CSC310

    • cd /home/fatalay/CSC310

  • . references the current directory

    • cd .

  • .. references the parent director

    • cd ..

    • cd ../..

  • cd with no arguments will take you to your home directory from anywhere

    • cd ~ will take you to home directory

  • cd / will take you to system root


Manual pages

Manual Pages

The man pages are the standard manual pages on all commands, system calls, etc that exist on a Linux or Unix system. The pages are very structured.

e.g. man man

  • The man pages are automatically formatted to show only one screen of information at a time

    • To go to the next page, press the space bar

    • To quit, just hit q


The file system

The file system

  • On a Unix system, almost everything is a file.

  • A directory is just a file containing names of other files

  • Programs, images, etc. are all just files

  • Input, output, and most other devices are considered to be files

  • Most files are called regular files

    • Text files

    • Data files

    • Source code

    • Executable code

  • Files types that are not regular files

    • Directories (d)

    • Special files (c or b) - files representing input and output devices, and others

    • Links (l) - this file is linked to another file

    • Named pipes (p) - one way to facilitate interprocess communication

    • Sockets (s) - another way to facilitate interprocess communication, but over a network

    • ls -l

    • ls -l /dev

    • ls -l /


Introduction to unix linux solaris

Typical directories under root (/)


The path

The path

  • When we type in a command, say ls, we should have to type in its entire path name (/bin/ls) in order for the system to find the utility and then execute it

  • So why are we able to just type in the command (in most cases)?When we log on, certain environment variables are set

  • One is the PATH variable which defines the directories to search, and the order to search, for any command we enter

  • To see what your PATH variable is set to

    • echo $PATH

  • My PATH is:/home/fatalay/bin/sun4:/fs/unsupported/ical/bin/sun4:.:/home/fatalay/bin:

    /usr/local/bin:/bin:/usr/bin:/etc:/opt/local/bin:

  • If you enter a command, and it is not in one of the directories on your PATH, then the command will not be found    You must then enter its entire path name to use it


File manipulation commands

File manipulation commands

NOTE: Most of these commands are not reversible, and they will overwrite/delete existing files with no asking "Are you sure you want to do this?" SO BE CAREFUL

  • mkdir - makes a directory in the current directory

    • mkdir my_new_directory

  • mv - moves a file from one name/place to another

    • In the arguments the source comes first then the destination

      • mv from_file to_file

    • There is no rename command, so you must use mv to rename a file

      • mv oldName newName

    • If you want to move a file from one directory to another, keeping the file names the same, then just list the "to directory" name as the destination

      • mv myFile /home/fatalay/newPlace


Introduction to unix linux solaris

  • cp - copies a file from one name/place to another

    source comes first then the destination

    • cp from_file to_file

  • To copy a file from one directory to another keeping the same name, then just list the "to directory" as the destination

    • cp myFile newDirectory

  • If you want to copy an entire directory

    • cp -r this_dir that_dir


Introduction to unix linux solaris

  • rm - removes a file

    • rm myFile

  • rmdir - removes an EMPTY directory

    • rmdir myDir

  • There will be no warning or second chance

  • There is no "Recycle Bin" in Unix

  • If you want to remove a directory that is not empy, use the -r option to rm. This does a recursive remove

    • rm -r myNotEmptyDir


Introduction to unix linux solaris

  • find - finds files

  • The find command is very powerful and complicated, but to use it for simple file location, it is easy

    • find starting_location -name filename

  • Note that . represents the current directory

    • find . -name myFile.tmp


Introduction to unix linux solaris

  • cat   Concatenates files, displays on standard output

    • cat file1 file2

  • One of the side effects of the cat command is that it displays the contents of the file on the screen

    • cat myFile

  • -n   Adds line numbers to the display

    • cat  -n myFile


I o redirection

I/O Redirection

  • Programs (including commands) typically read from stdin (typically the keyboard) and write to stdout (typically the screen).

  • stdin

    • Standard input, usually the keyboard

  • stdout

    • Standard output, usually your screen

  • stderr

    • Standard error, usually your terminal


Output redirection

Output Redirection

  • >

    • Redirects the output  into the specified file

    • If the file doesn't exist, it will be created

    • If the file does exist, it will be overwritten (with no warning, so be careful)

      • ls -la > dirListing

      • cat file1 file2 > file3

        $ ls

        a.out myDir pt1.cpp test1.c test2.c

        $ ls -la >myDir

        $ cat myDir

        total 48

        drwxr-xr-x 2 fatalay sjufacul 512 Jan 26 17:53 .

        drwxr-xr-x 75 fatalay MACS 12800 Jan 26 17:51 ..

        -rwxr-xr-x 1 fatalay sjufacul 7780 Jan 15 12:39 a.out

        -rw-r--r-- 1 fatalay sjufacul 0 Jan 26 17:55 myDir

        -rw-r--r-- 1 fatalay sjufacul 2010 Jan 15 12:37 pt1.cpp

        -rw-r--r-- 1 fatalay sjufacul 0 Jan 26 17:52 test1.c

        -rw-r--r-- 1 fatalay sjufacul 0 Jan 26 17:53 test2.c


Introduction to unix linux solaris

  • >>

    • Redirects the output into the specified file

    • If the file doesn't exist, it will be created

    • If the file does exist, the output will be appended to the contents of the file

  • |

    • Pipe

    • Links two or more commands together

    • The output of the first command is "piped" to the second command as its input

      $ ls -la

      total 16

      drwxr-xr-x 4 fatalay fatalay 4096 Jan 27 13:47 .

      drwxr-xr-x 37 fatalay fatalay 4096 Jan 16 12:16 ..

      drwxrwxr-x 8 fatalay fatalay 4096 Jan 23 2013 Courses

      drwxrwxr-x 3 fatalay fatalay 4096 Jan 27 13:47 Research

      $ ls -la | wc -l

      5


  • Input redirection

    Input Redirection

    • <

      • When you want a file to be the input to a command (even if the command does not normally accept a file as an option)

        $ sort

        12

        1

        19

        Ctrl-d

        1

        12

        19

        $ sort < junk.data

    • Combine input/output redirection

      • $ sort < junk.data > junk-sorted.data


    Wildcards

    Wildcards

    • A metacharacter is a character that has a special meaning instead of a literal meaning to a computer program, such as a shell interpreter

    • A wildcard character:

      • Is a metacharacter since it has special meaning to the shell

      • can be used to substitute for any other character or characters in a string


    Wildcards1

    Wildcards

    • * (Asterisk)

      • Represents any number of characters including zero

      • ls *.c

    • ? (Question mark)

      • Represents one, and only one, character

      • ls ?.c will expand to only a.c

        $ ls

        a.c myDir pt1.cpp test1.c test2.c test3.c

        $ ls *.c

        a.c test1.c test2.c test3.c

        $ ls ?.c

        a.c


    Wildcards2

    Wildcards

    • [ ] (Square brackets)

      • Represents a list of characters, one of which must match

        • ls *.[Tt]mp will expand to abc.tmp, abc.Tmp, .tmp, .Tmp

      • If characters are consecutive (according to their ASCII value), a range may be listed

        • ls myfile[1-5] will expand to myfile1, myfile2, myfile3, myfile4, and myfile5, but not to myfile or myfile0

        • ls myfile[a-d1-4] will expand to myfilea, myfileb, myfilec, myfiled, myfile1, myfile2, myfile3, and myfile4

    • Combining all three metacharacters

      • ls *?myfile[A-Za-z0-9] will expand to:

        • Any number of characters, but at least one, before myfile followed by a single alphanumeric character (but not any punctuation marks)

  • ! (Exclamation point)

    • Negate a set of characters

    • ls myfile[!0-9] will expand to all files that begin with myfile and ends with a single character that isn't 0-9


  • Special characters

    Special Characters

    • These are metacharacters that have special meaning to the shell, but are not wildcards since they don't substitute for characters in a string

    • ~ (Tilde)

      • Expands to the home directory

      • $ cd ~$ pwd/home/fatalay$ cd ~tezel$ pwd/home/tezel$ cd ~/Documents$ pwd/home/fatalay/Documents

    • \ (Backslash)

      • Escape character

      • When placed before a metacharacter or special character, the literal value of the character is preserved

      • Removes the special meaning of the character

      • ls myfile\* expands to myfile*

    • $ (Dollar sign)

      • Indicates that something is a variable

      • echo $PATH

      • echo $LOGNAME

      • echo $SHELL


    Special characters1

    Special Characters

    • ' ' (Single quotes)

      • Used to preserve the literal value of each character enclosed within the quotes

      • $ echo "$SHELL"/bin/csh$ echo '$SHELL'$SHELL

    • " " (Double quotes)

      • Preserves the literal value of all characters except:

        • Dollar sign - retains its special meaning

        • Back quotes - retain their special meaning

        • Backslash - retains its meaning when followed by dollar sign, back quote, double quote, backslash or newline

    • ` ` (Back quotes)

      • Command expansion

      • Bash executes the command and replaces the command substitution with the output of the command (with any newlines deleted)

      • $ echo datedate$ echo `date`Fri Oct 10 09:34:34 EST 2008$ echo "Today, `date`, is someone's birthday"Today, Fri Oct 10 09:35:00 EDT 2008, is someone's birthday


    Commands that process the standard output

    Commands that process the standard output

    • sort - sorts lines of text files

    • uniq - removes duplicate lines from a sorted file

    • head - prints first 10 lines of each file to standard output

    • tail - prints last 10 lines of each file to standard output

    • diff - finds differences between two files

    • more – browse or page through a text file


    Fgrep

    fgrep

    • Given one or more files, print all lines in those files that contain a fixed character string

    • -i case insensitive

      $ ls -la

      total 50

      drwxr-xr-x 2 fatalay sjufacul 512 Jan 27 14:51 ./

      drwxr-xr-x 75 fatalay MACS 12800 Jan 27 15:56 ../

      -rw-r--r-- 1 fatalay sjufacul 0 Jan 27 14:51 a.c

      -rw-r--r-- 1 fatalay sjufacul 428 Jan 26 17:55 myDir

      -rw-r--r-- 1 fatalay sjufacul 2010 Jan 15 12:37 pt1.cpp

      -rw-r--r-- 1 fatalay sjufacul 0 Jan 26 17:52 test1.c

      -rw-r--r-- 1 fatalay sjufacul 0 Jan 26 17:53 test2.c

      -rw-r--r-- 1 fatalay sjufacul 0 Jan 27 14:41 test3.c

      $ ls -la | fgrep test

      -rw-r--r-- 1 fatalay sjufacul 0 Jan 26 17:52 test1.c

      -rw-r--r-- 1 fatalay sjufacul 0 Jan 26 17:53 test2.c

      -rw-r--r-- 1 fatalay sjufacul 0 Jan 27 14:41 test3.c

      $ fgrep –i xray f1.dat f2.data … fn.dat | more


    Read about grep egrep

    Read about: grep/egrep

    • Given one or more files, print all lines in those files that contain a regular expression pattern

    • You use wildcards for matching file name patterns, when you use directory or file commands

    • You use regular expressions to match text within files

      Some Basics: (there are more rules than the ones mentioned here.)

    • Surround a RE in single quotes

    • . (dot) Matches exactly one character (equivalent of the wildcard?)

    • Repetition characters:

      • ? Matches zero or one instance of the preceding character

      • * Matches zero or more instances of the preceding character

      • + Matches one or more instances of the preceding character


    Grep egrep

    grep/egrep

    • Lists and ranges

      • Works the same way as the wildcard brackets

        • [a-z] means any character between a and z

      • Note that the - (hyphen) is not a metacharacter - it assumes special meaning only when it is between two characters in a list

      • The RE '[-v-x]' would mean a match on any one of the characters '-', 'v', 'w', or 'x'

      • Example: Write a RE that would match a Social Security number

        • '[0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9][0-9][0-9]'

          $ ls

          a.c myDir pt1.cpp t.c test1.c test2.c test3.c

          $ ls | grep 't[a-z0-9]*.c'

          pt1.cpp

          t.c

          test1.c

          test2.c

          test3.c

          $ ls | grep 't[a-z]*.c'

          t.c


    File permissions

    File Permissions

    • Every file in Unix/Linux is owned by a user and a user group and has a set of permissions associated with each

    • A third category is others - anyone who is not the user or in the user's group

    • For regular files, there are three types of permissions

      • Read - permission to only read the file

      • Write - permission to modify (and delete) the file

      • Execute - permission to run the file (only valid with scripts and executable files)


    File permissions1

    File Permissions

    • For directories, again three types of permissions

      • Read - permission to read the contents of the directory (but not change to it or execute any of the files)

      • Write - permission to write to the directory (create and delete  files and/or directories)

        • Even if you don't have write permission for a file, if you have write permission for the directory, you can delete the file

      • Execute  - permission to execute files in the directory, and change to it (but not see what files are there)


    File permissions2

    File permissions

    $ ls -la

    total 34

    drwxr-xr-x 3 fatalay sjufacul 512 Jan 27 16:47 ./

    drwxr-xr-x 75 fatalay MACS 12800 Jan 27 15:56 ../

    drwxr-xr-x 2 fatalay sjufacul 512 Jan 27 16:47 TestDir/

    -rw-r--r-- 1 fatalay sjufacul 0 Jan 27 14:51 a.c

    • col 1: 'd' means directory

      'l' means link

      '-' means file

    • col 2-10: 'r' means read access 'w' means write access 'x' means execute access (traversal access for directories)

      • the first 'rwx' is user permissions

      • the second 'rwx' is user group's permissions

      • the third 'rwx' is others’ permissions


    File permissions3

    File Permissions

    • each 'rwx' group has associated with it a 3 bit octal number

      • 000 nothing

      • 001 just execute

      • 010 just write

      • 011 write and execute

      • 100 just read

      • 101 read/execute

      • 110 read/write

      • 111 read/write/execute


    Chmod

    chmod

    rwx rwx rwx

    111 000 000 //represented as 700 for chmod command

    • $ chmod 111 test.txt

      • Changes permissions to 001 001 001

    • $ chmod 755 test.txt

      • Changes permissions to 111 101 101

    • $ chmod 777 test.txt

      • Changes permissions to 111 111 111


    Introduction to unix linux solaris

    • Whenever a file or directory is created, it is given default permissions

      • A file   rw-rw-rw- (666)

      • A directory   rwxrwxrwx (777)


  • Login