Unix Tutorial - PowerPoint PPT Presentation

About This Presentation
Title:

Unix Tutorial

Description:

dumps a file to stdout in different formats, including octal, decimal, floating ... f|-F floating point (-f) or long (double) floating point (-F) dump ... – PowerPoint PPT presentation

Number of Views:1064
Avg rating:3.0/5.0
Slides: 83
Provided by: Ton16
Category:
Tags: dump | tutorial | unix

less

Transcript and Presenter's Notes

Title: Unix Tutorial


1
Unix Tutorial
  • CSU480

2
Outline
  • Getting Started
  • System Resources
  • Shells
  • Special Unix Features
  • Text Processing
  • Other Useful Commands

3
The Unix Operating System
  • Kernel
  • System calls
  • Multi-user, multi-tasking OS

4
(No Transcript)
5
File System
  • FS is the focus point of Unix
  • Looks like an inverted tree
  • Root directory /
  • Each node is either a file or a directory
  • Path name
  • Absolute path
  • Relative path
  • . The current directory
  • .. The parent of current directory

6
(No Transcript)
7
Directory, File and I-node
  • Every directory and file is listed in its parent
    directory
  • The roots parent is itself
  • All Unix files are non-structured (bit stream)
  • A directory is a special file
  • File name
  • I-node number

8
(No Transcript)
9
(No Transcript)
10
Unix Programs
  • Shell between user and the kernel
  • Commands
  • Built-in shell command (pwd)
  • Source compiled, object code file (ls)
  • Shell script (.sh)
  • PATH/bin/usr/bin/usr/local/bin, etc

11
Getting started
  • Logging in
  • Linux Command Line Structure
  • Control Keys
  • stty terminal control
  • Getting Help
  • Directory Navigation and Control
  • File Maintenance Commands
  • Display Commands

12
Logging in
  • Username password
  • Unux is case sensitive
  • Changing password
  • passwd
  • Choosing an hard-to-crack password
  • Exiting system
  • Ctrl-D

13
Identity
  • usernamelt-gtuserid
  • groupnamelt-gtgroupid
  • A user can belong to more than one group
  • Primary group /etc/passwd
  • Additional groups /etc/group

14
Identity
  • id
  • uid1101(frank) gid10(staff)
  • id
  • uid1101(frank) gid10(staff) groups10(staff),5(
    operator),14(sysadmin),110(uts)
  • groups
  • staff sysadmin uts operator

15
Unix Command Line Structure
  • Format command options arguments
  • Arguments action object, usu. files
  • Options change the way it performs
  • command -optionoptionoption
  • ls -alR
  • command -option1 -option2 -option3
  • ls -a -l -R

16
Control Keys
  • Used to perform special functions
  • Ctrl-Key (-Key)
  • -U line-kill signal
  • -A go to the beginning of the line
  • -E go to the end of the line
  • -K kill until the end of the line

17
Getting Help
  • man command
  • man -k password
  • passwd (5) - password file
  • passwd (1) - change password information
  • man 5 passwd

18
Getting Help
19
Directory Navigation and Control
20
cd
21
mkdir rmdir
  • mkdir
  • -p create the intermediate (parent) directories,
    as needed
  • -m mode access permissions (SVR4).
  • rmdir directory must be empty

22
ls
23
ls
24
File Maintenance Commands
25
File Maintenance Commands
  • cp r recursively copy a directory
  • mv Actually all youve done is to update the
    directory table entry to give the file a new
    name. The contents of the file remain where they
    were.
  • rm Actually, all youve done is to remove the
    directory table entry and mark the inode as
    unused. The file contents are still on the disk,
    but the system now has no way of identifying
    those data blocks with a file name.
  • -r recursively
  • -f force

26
chmod
  • u user
  • g group
  • o other

read4, write2, execute1 or readr, writew,
executex
add permissions - remove permissions set
permissions
27
chmod
  • chmod 755 file1 or chmod urwx,gorx file1
  • As for directory
  • r can read the content of the directory
  • w can create/delete files of the directory
  • x can go through the directory

28
chown
  • chown new_usernew_group file
  • Note On most versions of Unix this can only be
    done by the super-user, i.e. a normal user cant
    give away ownership of their files.

29
Display Commands
30
echo
31
echo
32
more, less, pg
33
more, less, pg
34
System Resources
35
df
  • df is used to report the number of disk blocks
    and inodes used and free for each file system.
  • Options
  • -l local file systems only (SVR4)
  • -k report in kilobytes (SVR4)

36
du
  • du reports the amount of disk space in use for
    the files or directories you specify.
  • Options
  • -a display disk usage for each file, not just
    subdirectories
  • -s display a summary total only
  • -k report in kilobytes (SVR4)

37
ps
  • ps is used to report on processes currently
    running on the system.
  • Options
  • -e Select all processes.
  • -f does full-format listing.

38
kill
39
who
  • who reports who is logged in at the present time.
  • Syntax
  • who am i

40
whereis
41
which
  • which will report the name of the file that is be
    executed when the command is invoked. This will
    be the full path name or the alias thats found
    first in your path.
  • Syntax
  • which command(s)

42
hostname/uname
  • hostname (uname -n on SysV) reports the host name
    of the machine the user is logged into
  • uname has additional options to print information
    about system hardware type and software version.

43
script
  • script creates a script of your session input and
    output. Using the script command, you can capture
    all the data transmission from and to your
    terminal screen until you exit the script
    program. This can be useful during the
    programming-and-debugging process, to document
    the combination of things you have tried, or to
    get a printed copy of it all for later perusal.
  • Syntax
  • script -a file lt. . .gt exit

44
date
  • date displays the current data and time. A
    superuser can set the date and time.
  • Syntax
  • date options format

45
(No Transcript)
46
Shells
  • The shell sits between you and the operating
    system, acting as a command interpreter.
  • cat /etc/shells
  • /bin/sh
  • /bin/bash
  • /sbin/nologin
  • /bin/ash
  • /bin/bsh
  • /bin/ksh
  • /usr/bin/ksh
  • /usr/bin/pdksh
  • /bin/tcsh
  • /bin/csh
  • /bin/zsh

47
Shells
  • sh Bourne shell (not suited for interactive)
  • csh uses C type syntax (job control)
  • ksh Korn shell
  • bash Bourne Again Shell (GNU)
  • tcsh T-C shell
  • cshe extended C shell

48
Built-in Commands
  • These commands are executed directly in the shell
    and dont have to call another program to be run.

49
(No Transcript)
50
(No Transcript)
51
Environment Variables
  • Environmental variables are used to provide
    information to the programs you use.
  • Global environment variables are set by your
    login shell and new programs and shells inherit
    the environment of their parent shell.
  • Local shell variables are used only by that shell
    and are not passed on to other processes.

52
Environment Variables
53
Shell profile
  • Global
  • /etc/profile
  • User
  • /home/duanjj/.bash_profile

54
profile
  • comments
  • PATH separated by a colon and dot .
    represents current directory
  • A variable set in .profile is set only in the
    login shell unless you "export" it or source
    .profile from another shell.
  • umask 0022

55
Job control
  • put jobs into the background
  • Ctrl-Z suspend a job
  • bg put jobs into the background
  • fg bring jobs back to the foreground
  • jobs list your background jobs

56
Job control
  • Background jobs cant read from keyboard, but
    they can write onto the terminal, interspersing
    with whatever else is typed or displayed by your
    current job.
  • Solution You may want to redirect I/O to or from
    files for the job you intend to background.
  • Your keyboard is connected only to the current,
    foreground, job.

57
Changing your shell
  • chsh
  • /etc/shells

58
Working With Files
59
cmp
  • reports the location of the first difference
  • can deal with both binary and ASCII file
    comparisons.
  • does a byte-by-byte comparison

60
(No Transcript)
61
diff
  • compares two files, directories, etc, and reports
    all differences between the two.
  • deals only with ASCII files.
  • Its output format is designed to report the
    changes necessary to convert the first file into
    the second.

62
cut
  • allows a portion of a file to be extracted for
    another use.

63
cut
  • File users
  • cut -f 1,2 users
  • cut -c 1-4 users

64
paste
  • allows two files to be combined side-by-side.
  • The default delimiter between the columns in a
    paste is a tab
  • A hyphen (-) in place of a file name is used to
    indicate that field should come from standard
    input.

65
paste
  • users phone
  • method 1
  • cut f 2 phone gt temp.file
  • paste users temp.file gt listing
  • method 2
  • cut -f2 phone paste users - gt listing

66
touch
  • used to create a new (empty) file
  • or to update the last access date/time on an
    existing file

67
wc word count
  • Options
  • -c count bytes
  • -l count lines
  • -w count words
  • wc users

68
ln link to another file
  • Syntax
  • ln options source target
  • Options
  • -s make a symbolic link
  • hard link
  • symbolic link

69
Hard link
  • Only on the same file system
  • Can link to a directory
  • creates a new directory entry pointing to the
    same inode as the original file.
  • The file linked to must exist before the hard
    link can be created.
  • The file will not be deleted until all the hard
    links to it are removed

70
Symbolic link
  • Used to create a new path to another file or
    directory.
  • Can traverse file systems
  • Permissions are open to all

71
sort - used to order the lines of a file.
72
example
  • File users
  • sort users
  • sort 2 users
  • sort -r users
  • who cut -d " " -f 1 sort -u wc -l

73
tee copy command output
  • sends standard in to specified files and also to
    standard out.
  • often used in command pipelines.
  • who tee users.file
  • who tee users wc -l

74
uniq
  • filters duplicate adjacent lines from a file.

75
find
  • recursively search the indicated directory tree
    to find files matching a type or pattern you
    specify
  • then list the files or execute arbitrary commands
    based on the results.
  • Syntax
  • find directory search options actions
  • Common Options
  • For the time search options the notation in days,
    n is
  • n more than n days
  • n exactly n days
  • -n less than n days

76
(No Transcript)
77
find
  • find . -newer library -print
  • find /usr/include stdio.h -print

78
File compression
  • gzip, gunzip
  • bzip2, bunzip2

79
tar archive files
  • combines files into one device or filename for
    archiving purposes.
  • does not compress the files
  • merely makes a large quantity of files more
    manageable.
  • accept its options either with or without a
    preceding hyphen (-).

80
tar
  • Options
  • c create an archive (begin writting at the
    start of the file)
  • t table of contents list
  • x extract from an archive
  • v verbose
  • f archive file name
  • b archive block size

81
od
  • dumps a file to stdout in different formats,
    including octal, decimal, floating point, hex,
    and character format.
  • -b octal dump
  • -d-D decimal (-d) or long decimal (-D) dump
  • -s-S signed decimal (-s) and signed long
    decimal (-S) dump
  • -f-F floating point (-f) or long (double)
    floating point (-F) dump
  • -x-X hex (-x) or long hex (-X) dump
  • -c-C character (single byte) or long character
    dump (single or multi- byte characters, as
    determined by locale settings) dump
  • -v verbose mode

82
Thanks
Write a Comment
User Comments (0)
About PowerShow.com