You are on page 1of 284

Chapter 1

Introduction to UNIX
What is an Operating System?

An Operating System is a special computer program (software) that


controls the computer (hardware). The Operating system serves as a liaison
between the consumers and the resources, often coordinating the
allocation of limited resources among numerous consumers.

Disks
Users
Memory
CPU
Operating System
Programs Network
Printers

Consumers Resources
UNIX Operating System
An operating System can be thought of as
1. Resource Allocator – the operating system manages the
different computer resources such as CPU time,
memory space, file storage space, I/O devices, etc. and
allocates them to different application programs and
users.
2. Control Program – it controls the execution of programs
and the various I/O devices.
Unix Services
An operating system provides the following services for users:
1. Program Execution – loads the user program in memory and
runs it.
2. I/O Operations – responsible for reading and/or writing data
from I/O devices such as disks, tapes, printers, keyboards, etc.
3. File System Handling – handles the way files are organized
within the disk or tape. It takes care of the creation and
deletion of files for users.
4. Error Detection – detect errors within the computer system
(CPU, memory, I/O, or user program) and take the appropriate
action.
History of UNIX

1969 UNIX developed by AT&T Bell Labs


1980 UC Berkeley BSD UNIX 4.2 becomes widely used
Early 1980s Hewlett-Packard introduces HP-UX
Early 1990s POSIX, Portable Operating System Interface
UNIX Variants
•AIX – from IBM
•HP-UX – from Hewlett-Packard
•Ultrix – from DEC
•Xenix – from Microsoft
•OSF/1 – from Open Software Foundation
•Solaris – from Sun Microsystems
•Linux – Linus Torvalds
•Ubuntu
•Suse (Novell Netware)
•Red Hat
•Debian
UNIX Varieties and Benefits

Benefits of UNIX
based on an open standard
supported on a wide variety of computers
TCP/IP tightly integrated
true 64bit architecture
Hierarchical File System
Multi-tasking; Multi-user
File System - group of directories that
File System Directory Hierarchy can be thought of as a separate tree
structure
similar to logical partitions in the
Windows/DOS world (like C: or D:
drive)
made available (mounted) or
unavailable (unmounted) at the
administrator’s discretion
can either be local (on your computer)
or remote (on another computer)
Directory - location for other files and
subdirectories
like a file drawer in a file cabinet
Subdirectory - Any directory below
another directory
Files - contained in directories and
subdirectories
/usr directory - executables, system
Common Subdirectories admin utilities, and library routines
/opt (optional) directory -
applications and third party
applications
/dev (devices) directory - files
which are pointers to device names
/etc (etcetera) directory - system
admin files (passwd file)
/export/home directory - user
home directories
/kernel directory - basic operating
system files (main UNIX kernel
genunix)
/var (variable) directory - print
spooling and mail system error
messages
Operating System Components
Shells

Bourne shell ($)


developed by Stephen Bourne for AT&T
original shell program
Provides a UNIX system command interpreter
Supports a programmable interface to develop shell programs
Korn shell ($)
developed by David Korn at Bell Labs
An enhanced Bourne shell
added features such as aliasing and history
most widely used shell and is industry standard for users
this course is based primarily on the Korn shell
Shell cont..

C shell (%)
•developed at the University of California Berkley by Bill Joy
•Short California Shell
•based on the C programming language
•Allows recalling and editing of previously entered commands and
aliasing
POSIX shell
•Similar to Korn shell
•Command programming language and command interpreter
•It supporst command history, line editing, file name completion,
aliasing, and job control
Chapter 2
Logging In and General Orientation
Login ID and Password
Login ID
•user’s “public name”
•must be unique and limited to eight lower case letters and numbers
•stored in the password (/etc/passwd) file which can be viewed by all users
•encrypted passwords are stored in the /etc/shadow file

Passwords
•no less than six and no more than eight characters
•different from the Login ID
•at least two alphabetic characters and one numeric or special character
•case sensitive
•new password must differ by at least three characters
•may contain spaces and special characters
•these password rules do not apply to the root account!
User Accounts
Root or "super user"
•system admin
•set up by default during the installation process
•owns all system files and has access to all files
•used to create new users, manage file systems, install software and
perform other high-level system admin tasks
•Most sysadmins have a regular user account and only login as root when
necessary to perform administrative tasks

Regular User
•created and maintained by the sysadmin when logged on as root
•can run applications programs and customize working environment
•can also create and modify files in their home directory
Changing Password

•must be done at command line


•can be done by regular user
$ passwd
passwd: Changing password for user02
Enter login password: ABC 123
New password: abc 456
Re-enter new passwd: abc 456
Command-line Format
Syntax:
$ command [-options] [arguments] return
Examples:
$ date
$ls
•case sensitive
•Can type 2 commands on a single command
line, separated by a semicolon $ ls;pwd
The Secondary Prompt

$ banner ‘hi

there’
$(

$ if
*press ctrl c if you want to terminate currently running
program
Some Beginning Commands

$who – is used to determine the users currently


logged in the system.
$finger – same as who
$whoami – is used to determine who is currently
logged-in at a particular terminal.
$date - reports the date and time
$passwd - assign a login password
Some Beginning Commands cont.
• $echo - writes arguments to the terminal
• $clear - clears the terminal screen
• $write - sends message to username if logged in
• $talk -
• $mesg [y|n] - allows or denies writes to your terminal
Some Useful Keys to Remember

• Ctrl+C – Use this to abort a running UNIX program


• Ctrl+S – Use this freeze a screen output
• Ctrl+Q – Use this to unfreeze a screen output
• Ctrl+R – Use this to refresh or redraw your screen
• Ctrl+L – Use this if Ctrl+R does not work
• Backspace – Use this to erase mistakes before pressing the Enter key
Logging out
• Ctrl+D
• exit
man pages

UNIX Programmer’s Manual


describes the system’s on-line commands, system
calls, file formats, and system maintenance
installed by default
character-based screen displays and are not graphical
command prompt to access
man command

$ man name - help on particular command


$man -k keyword - Searches the man pages table of contents for
the specified keyword and displays one-line summary for each entry
$ man -s section name - Displays a particular section of the man
pages which can include multiple commands
Chapter 3
Getting Help
man Page Output NAME - name of command
and other commands that do
the same thing
SYNOPSIS - syntax of
command with options and
arguments
DESCRIPTION - overview of
what command does
OPERANDS - target of the
command
OPTIONS - switches that
change the function or effect of
the command; normally
preceded by a dash (-)
SEE ALSO - Refers you to
other related commands and
subjects
whatis Command

display the header line


from the manual section
brief definition of the
command
helpful if you can
remember the command
name but forgot what it
does
man Pages Scrolling

man pages can be many screens of output


Troubleshooting

Unresponsive Terminal:
•Enable screen scroll using Control –Q (Ctrl + q keys)
•Interrupt the process using Control –C (Ctrl + c keys)
•Enter EOF (end of file) using Control –D (Ctrl + d keys)
•Quit the window and restart a new one.

Unresponsive Application:
•Determine the process ID number associated with the
application and kill that process (chap 13)
•Logout and log back in again then restart the application.
Chapter 4
Accessing Files and Directories
Path Names
• A path name represents the route through the hierarchy that is
traversed to reach the desired file or directory
Types of Pathnames
Absolute Pathname
•Specifies the entire file hierarchy
•Start at root (/) and list each directory along the path to the
destination
•Slash (/) between each directory name in the path
•Example:
/home/user3/f1

Relative Pathname
•Always starts at your current location in the hierarchy
•If a pathname does not begin with a slash, it is a relative
pathname
•you must know what directory you are currently in since that is
your starting point
Absolute Path
Absolute Path
• Absolute pathname to the user2 directory
• /home/user2
• Absolute pathname to the dir1 directory
• /home/user2/dir1
• Absolute pathname to the coffees directory
• /home/user2/dir1/coffees
Relative Path
Relative Path
• If your current directory is /home:

• Relative pathname to the user2 directory


• user2
• Relative pathname to the dir1 directory
• user2/dir1
• Relative pathname to the coffees directory
• user2/dir1/coffees
Some Special Directories
Absolute Relative to
/home/user3

/home ..
/home/user2 ../user2
/home/user1/f1 ../user1/
f1
/ ../..

The entry called dot(.) represents your current directory position

•The entry called dot dot(..) represents the directory immediately


above your current directory position
Examples of DOT
If you are currently in the directory /home/user3:

.
./f1
./memo/f1
Examples of dot dot
• If you are currently in the directory /home:

• ..
• ../..
• ../tmp
• ../tmp/f1
• If you are currently in the directory /home/user3:

• ..
• ../..
• ../user2../user1/f1
• ../../tmp/f1
Using Navigation Shortcuts
pwd (print working directory) command -
•no options or arguments
•displays directory using absolute path name

cd (change directory) command -


•used with absolute or relative pathnames to navigate
•by itself takes you to your home directory

cd .. command takes you up one level


cd ~/ command takes you to a directory under your
home directory (tilde = home)
cd- Change Directory
Syntax:
cd [dir-pathname]
Examples:
$ pwd
/home/user3
$ cd memo; pwd
/home/user3/memo
$ cd .. /..; pwd
Using ls Command
ls
(list) listing of files and directories within the current directory or specified directories

ls –a
list all files in a directory, including hidden (.) files and current (.) and parent (..)
directories

ls –F
displays listing with a symbol to tell what the type the file is:
directory – A forward slash (/) after the name
ASCII Text File - no symbol
Executable – asterisk (*) after the name
Symbolic Link – An at sign (@)
Displaying Long Listing
Recursive Listing

ls -R (recursive) command
- Displays the contents of all directories, subdirectories and their contents for a particular part of
the directory tree
- If done at a high level in the directory structure, the output can be substantial!
Creating & Removing Files & Directories
mkdir - creates directories or folders
must have the appropriate permissions to create a directory
–p (parent) option creates parent directories while creating lower level directories, including all
the directories in a pathname

rm - removes a single file or multiple files


specify their names or use wildcard metacharacters (*) (?)
files that are deleted are permanent and cannot be recovered!
rm -i (interactive) - prompts the user before removing files
rm –r (recursive) - removes directories
removes the directory including all subdirectories and files in it!
rm -ri (or rm -ir) - removes directories interactively
mkdir and rmdir – create and remove directories

Syntax: mkdir [-p] dir_pathname (s)


rmdir dir_pathname (s)…
Example:

$ pwd
$ mkdir fruit
$ mkdir fruit/apple
$ cd fruit
$ mkdir grape orange
$ rmdir orange
$ cd ..
$ rmdir fruit
$ rmdir fruit/apple fruit/grape fruit
Chapter 5
Basic Directory and File Management
Command Line Control Characters
What can we do with files?
ls -look at the characteristics of a file
cat -look at the contents of a file
more -look at the contents of a file, one screenful at a time
lp -print a file
cp -make a copy of a file
mv -change the name of a file or directory
mv -move a file to another directory
ln -create another name for a file
rm -remove a file
cat more head tail Commands
head
•displays the first n lines
•first 10 lines are displayed by default if the -n
option is omitted.

tail
•displays the last n lines of a file
•last 10 lines are displayed by default if the -n
option is omitted.
•allows you to check the end result of the backup
without looking at the whole file
•-n option allows you to start displaying lines from a
specific point in a file
wc and diff Commands
wc (word count) command
•displays line, word, byte or character counts for a text file
•without options will give a line, word, and byte count of the contents of the file
Option Function
-l Counts lines
-w Counts words
-c Counts bytes
-m Counts characters

diff (difference) command compares two text files and finds differences
Command Format: $ diff [option] file1 file2
–i option ignores the case of the letters
–c option performs a detailed comparison and produces a listing of differences with three lines of
context
Copy Files
• Syntax:
• cp [-i] file1 new_file
• cp [-i] file [file…] dest_dir
• cp –r [-i] dir [dir…] dest_dir

• Examples:
• $ ls –F
• $ cp f1 f1.copy
• $ ls –F
• $ cp note remind memo
Move or Rename Files
• Syntax:
• mv [-i] file1 new_file
• mv [-i] file [file…] dest_dir
• mv [-i] dir [dir…] dest_dir
• Examples:
• ls –F
• mv f1 file1
• ls –F
• mv f2 memo/file2
• ls –F
• ls –F memo
diff Output
Link Files
Syntax:
ln file new_file
ln file [file. . .] dest_dir
Example:
$ ls –l f1
$ ln f1 /home/user2/f1.link
$ ls –l f1
$ ls –l /home/user2
$ ls –i /home/user2/f1.link
Chapter 6
File System Security
Filename Specifications
•Maximum of 14 characters
•Maximum of 255 characters if long
filenames are supported
•May contain alphabetic, numeric, dot,
dash and underscore
Security Policies
•The UNIX system incorporates a 3-tier structure to define who has
access to each file and directory:
User Group Others
•The ls –l command displays the owner and group who has access to
the file
•Default for Files
Read/Write for User and read only for Group and Other
•Default for directories
Read/Write/Execute for User and Read/Execute for Group and Other
File Types
•- regular file
•d directory
•l symbolically linked file
•n network special file
•c character device file
•b block device file (disks)
File System Permissions

- rw-r-- r--
drwxr-xr-x
user - owner / creator of file or directory
group – permissions used by members of the group that owns the file or directory
other – all users other than the file owner, and members of the group that owns
the file or the directory.
Permissions
User & Group ID

$ ls -n
displays the UID and the GID
$ id
displays numeric and alphabetic User ID and Group ID for your Effective User ID (EUID)
$ groups
displays all of the groups you are a member of
Changing Permissions Syntax
$ chmod mode filename
We use the chmod command to change the access mode of a file

The mode portion is made up of three parts:


Who - Category you are working with
u = user
g = group
o = others
a = all

Op - Operator
set (=)
remove (-)
give (+)

Permission(s) assigned – Read (r), Write (w) or Execute (x)


Changing Permissions - Symbolic
Permissions - Octal Mode
octal - eight possible numbers in group
bits are either on (1) or off (0)
7 r w x 1 1 1
6 r w - 1 1 0
5 r - x 1 0 1
4 r - - 1 0 0
3 - w x 0 1 1
2 - w - 0 1 0
1 - - x 0 0 1
0 - - - 0 0 0
Changing Permissions - Octal
umask  The umask (UNIX shorthand for "user file-creation mode mask") is a
four-digit octal number that UNIX uses to determine the file
permission for newly created files
 The umask specifies the permissions you do not want given by default
to newly created files and directories. umask works by doing a bitwise
AND with the bitwise complement of the umask. Bits that are set in
the umask correspond to permissions that are not automatically
assigned to newly created files.
 By default, most UNIX variants specify an octal mode of 666 (any user
can read or write the file) when they create new files. Likewise, new
programs are created with a mode of 777 (any user can read, write, or
execute the program)
 Octal umasks are calculated via the bitwise AND of the unary
complement of the argument (using bitwise NOT) and the permissions
specified by the program: typically 666 in the case of files, and 777 in
the case of directories.
Octal umask example
• Assuming the umask has the value 174, any new file will be
created with the permissions 602 and any new directory will
have permissions 603 because:

• 666 AND NOT(174) = 602


• while
• 777 AND NOT(174) = 603

• Computation:
• 7778 = (111 111 111)2
• 1748 = (001 111 100)2
• NOT(001 111 100)2 = (110 000 011)2
• (111 111 111)2 AND (110 000 011)2 = (110 000 011)2
• 7778 NOT (174)8 (603)8
Other commands
touch - either creates one or more files with zero bytes if
none exists; or updates date/time stamp if file already exists
-a time change access time to time
-m time change modify time to time
-t time use time as your current time
-c if the file does not already exists, do not create it

Example: To create/update more than 1 file:


$touch f1.txt f2.txt f3.txt
The chgrp Command
• Changes access to a file; only the owner of file can
change the group of the file

• Syntax:
• $ chgrp newgroup filename
su - switch user id
• Changes your user id and group id designation

• Syntax:
• $ su [username]
The newgrp command
• Changes the group id.

• Syntax:
• $ newgrp [group_name]
chown
Change file ownership
Syntax:

$ chown owner [:group] filename . . .


Example:
$ id
$ cp f1 /tmp/user2/f1
$ ls -l /tmp/user2/f1
$ chown user2 /tmp/user2/f1
$ ls -l f1 /tmp/user2/f1
Chapter 7

Shell Basics
What is the shell?
• A shell is an interactive program that serves as a command line
interpreter
• It is separate from the operating system
• A shell’s job is to allow you to type in your command, perform several
functions, and pass the interpreted command to the operating
system (kernel) for execution.
Commonly Used Shells
• /usr/bin/sh POSIX shell
• /usr/bin/ksh Korn shell
• /usr/bin/csh C shell
• /bin/bash Bourne (Again) SHell
• /usr/old/bin/sh Bourne shell
POSIX shell
The POSIX shell is a POSIX-compliant
command programming language and
commands interpreter. It can execute
commands read from a terminal or a file. It
contains a history mechanism, supports
job control, and provides various other
useful features.
Korn Shell
The Korn shell is a command programming
language and commands interpreter. It can
execute commands read from a terminal or a
file. Like the POSIX shell, it contains a history
mechanism, supports job control and
provides various other useful features. The
Korn shell was developed by David Korn of
AT&T Bell Labs.
Bourne shell
• Lacks many features contained in the POSIX and Korn shells.
• Developed by Stephen R. Bourne
• It was the original shell available on the AT&T releases of UNIX
C Shell
• A command language interpreter that incorporates a command
history buffer
• C-language-like syntax, and job control facilities
• developed by William Joy of the University of California at Berkeley
Comparison of Shell Features
Features Description Posix Bour Kor C
ne n

Command A feature allowing commands to be stored in Yes No Yes Yes


History a buffer, then modified and reused

Line Editing The ability to modify the current or previous Yes No Yes No
command lines with a text editor

File name The ability to automatically finish typing file Yes No Yes Yes
completion names in command lines

Alias A feature allowing users to rename Yes No Yes Yes


command commands, automatically include command
options, or abbreviate long command line
Restricted A security feature providing a controlled Yes Yes Yes No
shells environment with limited capabilities

Job control Tools for tracking and accessing processes Yes No Yes Yes
that run in the background
Aliasing
• An alias is a new name for a command
Syntax:
$ alias [name[=string]]
Example:
$ alias dir=ls
$ alias d=“ls –l”
$ alias mroe=more
• alias - displays aliases currently defined
$ alias
Command History
• The shell keeps a history file of commands that you enter.
• The history command displays the last 16 commands.
• You can recall, edit, and re-enter previously entered
commands
Syntax:
$ history [-n| a z]
Example:
$ history –2
$ history 3 5
Re-entering commands
Type r c to re-enter command number c
Example:
$ history 3 5
$ r 4
Recalling Commands
• Uses the history mechanism
• Must have the EDITOR environment variable set.
$ EDITOR=vi
$ export EDITOR
-At $, press ESC and use normal vi commands to
scroll through previous commands.
k -scrolls backwards
j -scrolls forward
-Press RETURN to execute the command.
Command line editing
• Provides the ability to modify text entered on current or previous
• press ESC to enter command mode.
• To recall press k, until the command appears
• To position the cursor
Use l or space to move right
Use h or backspace to move left
Command line editing cont.
To modify text:
-press x to delete a character
-press i to insert or append
-press ESC to stop adding characters
-press return to execute the modified command
The User Environment
Your environment describes your session to the programs you run
Syntax:
$ env
Setting Shell Variables
• A shell variable is a name that represents a value
• Some shell variables are defined during the login process
• A user can define new shell variable
Syntax:
$ name=value
$ PATH=/usr/bin/X11:/usr/bin
$ PS1=“Jess$ “
No space before and after the = sign
Looking for commands
• whereis [-b| -m| -s] command
- Searches a list of directories for command

Examples:
$ whereis if
$ whereis ls
$ whereis cd
Chapter 8

Shell Advanced Features


Shell Variable Storage

1. Local
• Private to the current shell
2. Environment
• Visible to all shells
Examples:
PATH, HOME, TERM, SHELL
Setting Shell Variables
Syntax:
variablename=value
(no space before and after the = sign)
Examples:
$ color=fuschia
$ count=3
Variable Substitution
Syntax: $variablename
• directs the shell to perform variable
substitution.
Examples:
$ echo $PATH
$ PATH=$PATH:$HOME
$ echo $PATH
$ echo $HOME
$ filename=$HOME/sample.txt
$ more filename
Variable Substitution
• The use of an absolute path name for the value of variable
that references a file or directory allows you to be anywhere
in the file hierarchy and still access the desired file or
directory.

$ dir_name=tree/car.models/ford
$ echo $dir_name
$ ls –f dir_name
$ my_ls=“ls –aFC”
$ my_ls
$ my_ls $dir_name
Command Substitution
• Used to replace a command with its output within the same command line
Syntax: $(command)
• Examples:
$ pwd
$ curdir=$(pwd)
$ echo $curdir
$ cd /temp
$ pwd
$ cd $curdir
$ pwd
Tilde Substitution
• If a word begins with a tilde (~), tilde expansion is performed on that word.
RULES:
• A tilde by itself or in front of a / is replaced by the path name set in the
HOME variable
$ echo $HOME
$ echo ~
• A tilde followed by a + is replaced with the value of the PWD variable
$ cd tree
$ echo $PWD
$ ls ~+/tree
Tilde substitution
• A tilde followed by a – replaced with the value of the OLDPWD
variable

$ echo $OLDPWD
$ ls ~ -
Displaying Variable Value
• The env command can be used to display all of the
variables that are currently held in the environment

• The set command will display all of the currently


defined variable.

• The unset command can be used to remove the


current value of the specified variable.
Transferring local variables to the environment
Syntax:
$ export variable
Example:
$ n=5
$ export n
ps Command
$ ps [-options]

use to check the PID and then “kill” the process if it is taking too
long or has stopped
ps Command Output
Parent Child Processes

-First identity the PID of the lowest level unresponsive process


-Sometimes necessary to kill the Parent of process and on rare occasions even the
Parent of the Parent
-Killing a parent process will kill all child processes spawned by it
-Look at output to be able to trace from the child up the hierarchy to the parent
processes that spawned them
Terminating Processes
$ kill -15 - soft kill
$ kill -9 - sure kill

$ pkill cmd name -


Solaris
Chapter 9

File Name Generation


File Name Generations and Dot Files

• File name generating characters will never generate a file name that
has a leading dot
• The leading dot in dot files must be explicitly provided
File name Generation - ?
? - Matches any single character
Examples:
$ ls –a
. .. .zz abc abcd abcdef abcz
bbabb cyz zzayy
$ls ???
$ls abc?
$ls ??a??
$ls .??
$ls ?
File name Generation – [ ]
[] - defines a class of characters from which one will be
matched
Examples:
$ls –a
. .. .zz 1G 2G 7G 15G Ant Cat Dog abc
abcdef ba cyz

$ls [abc]???
$ls [1-9][A-Z]
$ls [!A-Z]??
File name Generation – *
* - Matches zero or more characters except a
leading dot (.)
Examples:
$ ls –a
. .. .profile ab.dat abcd.dat
abcde abcde.data
$ls *
$ls .*
$ls *.dat
$ls *e
Review
$ ls –a
. Abc e35f
.. Abcd efg
.test1 abc fe3f
.test2 abcdemf fe3fg
Given the directory, list all file names that
1. Contain only 5 characters
2. Contain at least 5 characters
3. Begin with an “a” or an “A”
4. Have at least 4 characters and begin with an “a” or an “A”
5. End with a sequence “e”, a single number, and an “f”
6. Begin with a dot
7. Begin with a dot, except .
8. Begin with a dot, except . and . .
Chapter 9

File Name Generation


File Name Generations and Dot Files

• File name generating characters will never generate a file name that
has a leading dot
• The leading dot in dot files must be explicitly provided
File name Generation - ?
? - Matches any single character
Examples:
$ ls –a
. .. .zz abc abcd abcdef abcz
bbabb cyz zzayy
$ls ???
$ls abc?
$ls ??a??
$ls .??
$ls ?
File name Generation – [ ]
[] - defines a class of characters from which one will be
matched
Examples:
$ls –a
. .. .zz 1G 2G 7G 15G Ant Cat Dog abc
abcdef ba cyz

$ls [abc]???
$ls [1-9][A-Z]
$ls [!A-Z]??
File name Generation – *
* - Matches zero or more characters except a
leading dot (.)
Examples:
$ ls –a
. .. .profile ab.dat abcd.dat
abcde abcde.data
$ls *
$ls .*
$ls *.dat
$ls *e
Review
$ ls –a
. Abc e35f
.. Abcd efg
.test1 abc fe3f
.test2 abcdemf fe3fg
Given the directory, list all file names that
1. Contain only 5 characters
2. Contain at least 5 characters
3. Begin with an “a” or an “A”
4. Have at least 4 characters and begin with an “a” or an “A”
5. End with a sequence “e”, a single number, and an “f”
6. Begin with a dot
7. Begin with a dot, except .
8. Begin with a dot, except . and . .
Quoting
-removes the special meaning of the special characters
Quoting - \
Removes the special meaning of the next character
examples:
$echo the \\ escapes the next character
$color=red\ white\ and\ blue
$echo the value of \$color is $color
$echo one two\
> three four
Quoting - ‘

Removes the special meaning of all the characters surrounded


by the single quotes
$color=‘red white and blue’
$echo ‘the value of \$color is $color’
$echo ‘the value of \$color is’ $color
$echo ‘this doesn’t work’
$echo ‘***********’
Quoting - “
Removes the special meaning of all characters surrounded by the
double quotes except \,$,{variable name},$(command), and “
$color=“red white and blue”
$echo “the value of \$color is $color”
$cur_dir=”$LOGNAME - your pwd is $(pwd)”
$echo $cur_dir
$echo “they’re all here, \\, ‘,\” “
Input and Output
Redirection
Input Redirection - <

Any command that reads its input from the stdin can have its
input redirected to come from another file

$cat filekoh
$mail user3 < filekoh
Output Redirection - > and >>

Any command that produces output to stdout can have its


output redirected to another file.
Create/Overwrite Create/Append
$ date > date.out $ ls >> ls.out
$ date > who.log $ who >> who.log
$ cat > cat.out $ ls >>
who.log
Error Redirection - 2> and 2>>

Any command that produces error messages to stderr can have


those messages redirected to another file

$ cp 2> cp.err
$ cp 2>> cp.err
$ more cp.err
What is a Filter?
• Filters the contents of the input stream or a file
• Sends results to screen, never modifies the input stream or file
• Process the output of other commands when they are used in
conjunction with output redirection
wc - Word Count

wc (word count) command displays line, word, byte or character counts for a
text file without options will give a line, word, and byte count of the contents
of the file

Option Function

-l Counts lines

-w Counts words

-c Counts bytes

-m Counts characters
Sort
Alphabetical or Numerical Sort
sort [-ndutX] {-k field_no] [file...]
Sort Option Sort Type
none ASCII Type
-d dictionary
-n numerical
-u unique
Sort (cont.)

$ tail -1 names
$ sort -nt: -k 3 < names
$ who > whoson
$ sort whoson
$ sort -u -k 1,1 whoson
grep - pattern matching

grep [-cinv] [-e] pattern [file. . .]


grep [-cinv] -f pattern_list_file [file. . .]

-c only a count of matching lines is printed


-i tells the grep to ignore the case of the letters in
the pattern
-n prepends line numbers to each line displayed
-v displays the lines which do not contain the pattern grep
Chapter 12
Pipes
Why Use Pipelines?
Pipelines allow you to transfer the output of one
command directly as the input of another command
Example:
$ ps –f | more
$ ls | more
$ ls | sort –r | more
$ who > who.out
$ sort < who.out who | sort
Redirection in a Pipeline
$ grep one myfile | sort > sorted.users

$ grep one < myfile 2> grep.err | sort > sorted.users 2> sort.err

$ grep one < myfile | sort 2> sort.err | wc –l > wc.out 2> wc.err
cut
Cuts out specified columns or fields of text from standard input or a file and display the result
to stdout. The -c option is for cutting columns, and the -f is for cutting fields.
Syntax:
cut –clist [file. . .]
cut –flist [-dchar][-s][file. . .]
Examples:

$ date | cut –c1-3


$ tail -1 myfile
$ cut –f1, 6 –d: myfile
$ cut –f1, 6 –d: myfile | sort –r
$ ps –ef | cut –c49- | sort -d
Cont.
A-B Fields or Columns A through B inclusive
A- Fields or Columns A through the end of the line
-B Beginning of line through field or column B
A, B Fields or columns A and B

*any combination of the above is also permissible


Example:

$ cut –f1,3,5-7 myfile


tr
Translates characters. It can be used to convert many consecutive
blank spaces to a single blank space. IT can be used to substitute
literal strings or convert text from lowercase to uppercase and vise
versa.
Syntax:

$ tr [-s] [string1][string2]
Examples:

$ who | tr –s “ “
$ date | cut –c1-3 | tr “[:lower:]” “[:upper:]”
tee
Reads from standard input and writes its output to standard
output and to the specified file

Syntax:
tee [-a] file [file. . .]
Example:
$ who | sort
$ who | tee unsorted | sort
$ who | tee unsorted | sort | tee sorted
$ who | wc -l
$ who | tee whoson.txt | wc -l
pr
Print to stdout; it is used to format the standard input stream or
the contents of spedified files. It sends its output to the screen,
not the printer. Useful for printing long files because it will insert a
header on the top of each new page that includes the file name,
and a page number.
Syntax:

pr [-option] [file . . . ]
Examples:

$ pr –n3 funfile
$ pr –n3 funfile | more
$ ls | pr -3
The pr command supports many options:

-k produces k-column output; prints down the column


-a produces multicolumn output; used with -k; prints across
-t removes the trailer and header
-d doublespaces the output
-wN sets the width of a line to N characters
-lN sets the length of a page to N lines.
-h users the following string as the header text
-p pauses and waits for return before each page
Printing from a Pipeline
. . . | lp

Examples:

$ pr -158 funfile | lp
Intro to Shell Programming
Shell Programming Overview
• A shell program is a regular file containing UNIX
system commands.
• The file’s permission must be at least “read” and
“execute”.
• To execute, type the name of the file at the shell
prompt.
• Data can be passed into a shell program through
environment variables, command line arguments
and user input.
Example Shell Program
Step 1. Include your HOME directory in the system PATH variable.
$ PATH=$PATH:$HOME <enter>
Step 2. Create your shell program.
$ gedit myprog <enter>
#this is a comment
ls
date
Step 3. Execute your program.
$ chmod +x myprog <enter>
$ myprog <enter>
Passing data to a shell program
$ color=fuschia
$ gedit color1
echo you are now running program: color1
echo the value of the variable color is: $color

$ chmod +x color1
$ color1
$ export color
$ color1
Arguments to Shell Programs
$ program argument1 argument2 . . . argumentX
$0 $1 $2 ... $X
Example:

$ gedit color3

echo you are now running program: $0


echo the value of command line argument \#1 is: $1
echo the value of command line argument \#2 is: $2

$ chmod +x color3

$ color3 red green


Cont.
$ mkdir bin

$ gedit myinstall

echo $0 will install $1 to your bin directory


chmod +x $1
mv $1 $HOME/bin
echo Installation of $1 is complete

$ chmod +x myinstall

$ myinstall color3
Shell Variables - # and *
# the number of command line arguments
* The entire argument string

$ gedit color4

echo there are $# command line arguments


echo they are $*
echo the first command line argument is $1

$ chmod +x color4

$ color4 red green yellow blue


The shift command
-Shifts all strings in * left n positions
-Decrements # by n (default value of n is 1)
Syntax: shift [n]
After a shift [n], all parameters in * are moved to the
left n positions and # is decremented by n. The default
for n is 1. The shift command does not affect the
positional parameter 0.
Once you have completed a shift, the arguments that have
been shifted off of the command line are lost.
Example (shift)
$ gedit color5
orig_args=$*
echo there are $# commandline arguments
echo they are $*
echo shifting two arguments
shift 2
echo there are $# commandline arguments
echo they are $*
echo shifting two arguments
shift 2; final_args=$*
echo original arguments are: $orig_args
echo final arguments are: $final_args

$ chmod +x color5
$ color5 red green yellow blue orange black
The read command
Syntax: read variable [variable. . . .]
Example:
$ gedit color6
echo this program prompts for user input
echo “Please enter your favorite two colors -> \c”
read color_a color_b
echo the colors you entered are: $color_b $color_a
$ chmod +x color6
$ color6
Young, Jesse Ian R. 3-ITH
I observed that files and other privileges can access using terminal . I observed that in Linux such
as ubuntu, the command in terminal has some similar to the command in windows. The print
working directory is used in Linux command and windows the command use in cmd is Dir
means directory this command line use for printing the current working directory . There are
many commands also that I can use like $passwd, $date, $ who and other basic command. I
learned that in root the slash (/) command is a user directory that contains executables ,system
admin utilities ,and library routines. In some command like cd .. in Linux you can type that
command cd and then space to input .. means move the parent directory or current directory or
the directory one level up from the current directory. But on windows we can move even without
space that’s what I observed. I learned some shortcut keys used in Linux this will help me to be
more productive and efficient. If something happen like error or stuck on using shell, some
useful keys I used is Ctrl+C , Ctrl+D and etc. I also learned Sudo command this command allows
to run programs with the security privileges of another user. It prompts from me for personal
password, that’s why there is a system admin or what we called root or super user and regular
user. I also observed that Linux runs faster than windows in some cases I observed that windows
run more programs in the background and they eat up the Ram while Linux the file system is
very much organized. Files in Linux are located in chunks which close to each other. This makes
the read-write operations very fast.
Young, Jesse Ian R. 3-ITH

DOS Screenshot Linux Screenshot

cd

cd

mkdi
mkdi r
r

cat
type

dir
ls
DOS Screenshot Linux Screenshot

del rm -iv

echo echo

DOSKEY/h history

Date
Date
DOS Screenshot Linux Screenshot

Ipconfig ifconfig

tree
ls -R
I see that Linux and DOS commands have some similar commands while other commands in
Linux and DOS have same process but different name of command. The difference of both is
that DOS can input a command without space while Linux needs to have space in order to work
the command in a terminal. Like for example cd .. means cd space dot dot. In DOS using
windows you can enter cd.. without space. I observed the difference of using Linux and DOS,
Linux uses Bash or Bourne Shell or Enhanced shell while Windows uses the MS-DOS
command.
I notice that using the different commands help me to access the folder, create files, and access
file system. Basically a shell is a program that receives commands from a user and give it to the
operating system to process, and it shows the output in a terminal or command prompt. I see in
Linux terminal some access like system admin or admin utilities need to prompt the password in
order to access some files and data while in dos command uses in windows I notice if both user
is an admin user you can access other files in another user. The difference between DOS and
LINUX from what I observed is that DOS was designed for single-user systems while LINUX
was designed for systems with many users.
I also learned Sudo command that this command allows to run programs with the security
privileges of another user. It prompts from me for personal password, that’s why there is a
system admin or what we called root or super user and regular user. So basically in Linux the
terminal has some security purposes to protect from your files and data while dos command in
windows has less security because Linux terminal is more powerful than DOS in Windows . In
some cases I can access files in some command that it can directly process by the operating
system and access does files and other data in a DOS command in Windows using cmd.
Young, Jesse Ian R. 3-ITH
I observed that using different command can access file system and other directories in a users.
All of these command have an access to the user which are being used from home directory. I
learned how to create a file, moved a file to the directory folder, and then put some text in a
file like for example a txt file and edit a file. Some command is committing error that is being
stated no such file or directory so I fix it and correct those commands like for example moving a
file to a different file is not applicable because a file must be moved or copied in a directory
folder. I also learned on how to know the information in my operating system. The command I
used are whoami, uname, logname, hostname. This type of command use is to know the
information of your operating system and the current user you are using to login in your
operating sytem. I can also know what is the current date or search a date using the command
cal in a terminal.
Terminal is a powerful thing to use for those who are experiencing using the command in linux.
This will help me to learn a lot without the use of GUI (Graphical User Interface). If you have
something to do like open an file, copy a file , move a file from a directory, know your
information about your operating system and other system admin utilities practicing using
different command in linux that can help you to access information and other utilities in an
operating system.
Young, Jesse Ian R. 3-ITH

AOS Activity 5

Perform the necessary command based on the given statement, screenshot the result as you proceed.

Don’t forget to include your name.

1. From your main directory create a new directory called unixstuff

2. List the directory

3. Create a text file using touch command and name it as file1.txt, eg $touch file1.txt

4. Create a text file using redirection “>” command and name it as file2.txt, eg $> file2.txt

5. Create a text file using cat command and name it as file3.txt, and store the text “Hello Unix”
eg $cat > file3.txt

6. Echo the text “Hello Unix” to file1.txt using redirection

7. List the directory

8. Move file1.txt, file2.txt and file3.txt to unixstuff, eg. mv file [destination]


9. List the directory

10. Copy file1.txt to file.bak, eg cp file1.txt file.bak

11. List the directory

12. Create a new directory called “backup” inside unixstuff directory

13. Move file.bak inside backup directory

14. List the directory

15. Copy file1.txt to tempfile.txt

16. List the directory

17. Remove/delete the file temp

18. List the directory


19. Clear the screen

20. Access unixstuff directory

21. Create a file using cat command with filename science.txt and enter the following text
The Electronic Telegraph Thursday 28 September 1995 Science

This summer the Royal Observatory at Herstmonceux


found new life as a science centre. Andro Linklater
celebrates a partial victory for the heritage

THE SIGHT of a child's top spinning unsupported in mid-air should have been
surprising. Rotating there in space, it not only defied the rules of gravity,
it defied common sense, and at least three Fellows of the Royal Society gazed
at it in something close to wonder.

But this was Fabricators' Week at the Herstmonceux Science Centre, with
exhibitors from science centres all over Europe arriving to demonstrate
prototypes of experiments they hoped to produce as hands-on displays - a tube
of rocket-propelled rubber balls, a solar-powered toy car, a model of planetary
movement. They had a much tougher audience in mind. Would it astonish a child?

"Well I certainly found it surprising," Prof Michael Berry FRS, an expert in


gravitational physics and the top's demonstrator, said a trifle indignantly.
"The physics of why the top doesn't topple over are extraordinarily complex,
and so far as I know, no one has ever demonstrated the experiment before."

So challenging are the physics indeed that Berry has written a paper on the
spinning top, invented by Bill Hones of Seattle, for the scientific journal
Nature. Its position in mid-air was maintained by the straightforward method of
positioning a magnet beneath it with reverse polarity, but its stability was
acquired in far more complicated fashion, through the interaction of the
magnetic field and the forces created by its spin. In technical terms, it had
become an adiabatic trap.

"A child brought up on cinema special effects might think it quite normal to
have a top spinning in space"
But Prof Richard Gregory, another FRS and emeritus professor of
Neuro-Psychology at Bristol University, was not convinced that this was enough
to surprise a more blasŽ audience.

"A scientist might be impressed," he objected, "but a child brought up on


cinema special effects might think it quite normal to have a top spinning in
space. The problem, then, would be to demonstrate how surprising it really is."

For Gregory, one of the world's leading authorities on the psychology of


perception, the challenge presented by the encounter of science with a child's
imagination has long been a passionate interest. In 1987 it led him to set up
the Exploratory, Britain's first hands-on science centre housed in Temple Meads
station in Bristol. All the exhibits, demonstrating phenomena as diverse as the
electrical effects of lightning and the length of sound waves, were designed to
be operated by children.

"The point about a science centre is that the exhibits should be fun," he said.
"By which I don't mean frivolous but interesting. They should trigger some
response in the child's mind - what I call a 'cortickle'."

22. Display the content of science.txt to the screen using less command, type q if you want to quit after executing
the command (Don’t forget to screenshot the output) eg. less science.txt
23. Now use head command to display science.txt, eg. head science.txt

24. Now use head -5 command to display science.txt, what have you observed? eg. head -5 science.txt
I observed that it display the output of 5 lines including the space from the start to the end of the line 5.

25. Now use tail command to display science.txt, eg. tail science.txt
Young, Jesse Ian R. 3-ITH

AOS Activity 6

Perform the necessary command based on the given statement, screenshot the result as you proceed.

Don’t forget to include your name.

1. Login to Ubuntu and open the terminal


2. Create a directory of the name “Capstone_2020”

3. Check the directory name in which you are now by typing (print working directory)

4. Check the contents of your current directory (list)

5. Change the current directory. Get into Capstone_2020 and redo number 3

6. Create a file with filename “linux_logfile”

7. Change the file permission of “linux_logfile” by performing the following command


chmod a+r linux_logfile
“a” means “all” and “+r” means “add read permission”. With ls -l you can check the permissions of any file and
directory. The first three digits specify your permissions, the last three digits specify the permissions of
everybody else. In each case the digits are for executable, reading and writing. Change the reading and writing
permissions of the linux_logfile and check after each change with
ls -l linux_logfile
8. Check again the contents of the current directory.

9. Create another file called “tryfile” with content


hello
good bye

10. Redo number 4

11. Look at the contents of the tryfile with cat command

12. Do the same with the logfile.

13. Next remove (delete) the tryfile using rm -i

14. Create a directory with name “trydir” and get into it

15. Get back out of trydir (one step higher in the tree of directories)
Check in which directory you are.
16. Remove trydir

17. Get back to your home directory either with


cd
or with
cd ~
or with
cd ~yourusername

18. Look at the contents of your linux_logfile with


cat ~/Capstone_2020/linux_logfile

19. Execute the following command once


cd
mkdir share.dir
chmod 755 share.dir

20. Check with ls -l what the last command did. Then go to the directory where your assigned program
cd ~/Capstone_2020/
21. Then copy the file you want to have accessible
cp linux logfile ~/share.dir/
chmod a+r ~/share.dir/*

I observed that in Unix when it comes to file permission there is 3-tier structure to define who access to each
file and directory. I learned how to use the command chmod, this command use to change the access mode of a
file like the command that I perform in Ubuntu terminal. I learned how to use the mode portion like u= user, g=
group, o= others. I can change the file permission based on what command I’m going to execute. I also observed
and recall the command that I used before like for example the cat command, redirection command, removing
file using command rm -I to prompt the user and etc. I can use the command chmod for changing permission
access to a file or a directory, applying this command can help to remove or add permission to the user, group or
other. I also learned from the lesson that I can use octal mode from changing permission in a file or directory.
Changing file permission in Ubuntu terminal is a big help for me because I can access directly and input the
command, this will help me to be more productive.
Young, Jesse Ian R. 3-ITH

1. Create new user in ubuntu


$ sudo adduser undas
Password: Undas123
Fullname: Undas
Room Number: 11

2. Verify if account is created


$ cat /etc/passwd
$ grep '^undas' /etc/passwd ----note the single quote is included(‘)
3. Screenshot the output of grep command

4. Change the Password of the newly created account


$sudo passwd undas
5. Install vim, text editor in ubuntu
$sudo apt install vim
$vim

6. Execute the example for editing of the file /etc/hosts

$vim /etc/hosts

:i[enter] ------------- to insert

The word --insert-- will appear at the bottom of the editor window to show that you are in
insert mode now.

Now you can edit the file by navigating to the line that you want to change with the cursor keys
and then start typing the text. When you are finished with editing, press the [esc] key to go
back to the command mode.

To save the file and exit the editor, enter:


:x[return] -------------- to save and exit

In case you want to quit vim without saving the file, enter:

:q![return] --------------------- to exit without saving


Vim Command Reference
save: :w
save and exit: :wq
exit: :q
force: ! (example :w! :q!)
vertical split: open a document and then type :vsplit /path-to-document/document and this will
open the specified document and split the screen so you can see both documents.
copy: y
copy a line: yy
paste: p
cut: d
cut a line: dd
7. Write a menu- driven program for the following options
• List of files
• Processes of Users
• Today’s Date
• Quit out of Unix

A. Create a file by encoding

$ vim menu

echo “enter the option between [1-4]”


read choice
case $choice in
1) ls -1;;
2) ps;;
3) date;;
4) exit;;
*)echo “choose option between 1-4”
break;;
esac
Note: esac is used to close the case statement
B. Run the code

$sh menu

Note: try each menu and observe what will happen for each number, screenshot each
output.
8. Write a shell program which accepts the name of a file from the standard input and then performs
the following test on it.
• File Existence
• File Readable and Writable

Encode the following command

# vi exist
echo “Enter the filename:”
read fname
if [ -f $fname –a –r $fname –a –w $fname ]
then
echo “$fname is Exist”
echo “$fname is readable”
echo “$fname is writable”
else
echo “$fname is not Exist “
fi

Note: Exit and save exist file from vi

# sh exist
9. Screenshot the output and observe what happen to the output.

I learned how to add a user in ubuntu and also changed the password. I learned how to install the vim
and use the vim command reference for editing the file and put some code to perform an action using
sh command. I learned how to code the case and if statement inside the specific file using vim [file] or vi
[file]. I observed in number 9 that when I enter menu it goes to the if statement because the file exist
and it is readable and writable also based on the condition of the code, then if the file doesn’t exist it
will go to else statement that does not exist. I observed on each output of sh in case it will print the
output, it depends on which case that I enter. I observed that using the case and if statement is also
similar logic from my programming language that I learned but I notice that it has a different syntax
because this type of code will run in ubuntu terminal. I learned how to perform different commands for
the vim editor. I noticed that some command in latest Ubuntu doesn’t work but some are working so
basically searching for the latest command is the best thing to know what command will work in
Ubuntu.
Young, Jesse Ian R. 3-ITH
Take note to screenshot each of the given activity and placed it in MS Word,
save it and create a pdf file.

1. Navigate to home directory and create a file named .vimrc, and enter the following text and save it
then exit
set nu

2. Now create a file named new_vim and enter the following text and save it then exit. Write your
observation with vim.
Vim’s design is based on the idea that a lot of programmer time is spent reading, navigating, and making
small edits, as opposed to writing long streams of text. For this reason, Vim has multiple operating
modes.
Normal: for moving around a file and making edits
Insert: for inserting text
Replace: for replacing text

Visual (plain, line, or block): for selecting blocks of text


Command-line: for running a command
I notice everytime I create vim file name for editor I can edit and input some text inside the editor.
I can also used the command reference or shortcut for exit, saving insert and other useful command
inside the vim editor file.

3. Write a menu driven program that will compute the area of the following shapes, rectangle, square,
triangle
I learned how to use vim editor as usual. Everytime I used vim and other command it helps me to
memorize the command, use it at all time. I learned how to code inside the vim editor. I notice that
some command are case sensitive some code and similar to my programming language that I
learned so far, the difference is they have different syntax. Here in vim I notice also the spacing is
important and some command or old command doesn’t exist. In order to update and know the
command help or search online is the one I do.
Question 1

A file permission that contents can be executed

Correct Answer: Execute

Question 2

Dosan want to exit from VIM editor without saving the changes, What must be the correct way to do it?

Correct Answer: Press ESC key, then :q! then enter

Question 3

Which of the following command must be used to create a new user in Ubuntu named as Dalmi

Correct Answer: $sudo adduser Dalmi

Question 4

A file permission that can be displayed or copied

Correct Answer: Read

Question 5

Which of the following command must be used in order to verify if you have the installed and updated
version of vim editor

Correct Answer: $sudo apt install vim

Question 6

What will be displayed after executing is ??? Given the following list of files…zz abc abcd abcdef abcz
bbabb cyz zzayy

Correct Answer: abc cyz

Question 7

Which of the following will display files or directory with at least 3 characters?

Correct Answer: Is ???*

Question 8

It refers to an interactive program that serves as a command line interpreter?

Correct Answer: shell

Question 9

It is used to replace a command with its output within the same command line.

Correct Answer: Command Substitution


Question 10

What will be displayed after executing is abc? Given the following list of files…zz abc abcd abcdef abcz
bbabb cyz zzayy

Correct Answer: abcd abcz

Question 11

What will be the effect of chmod 421 when applied to file FAILED.txt

Correct Answer: r-w-x

Question 12

How can we find the process name from its process id?

Correct Answer: ps – Process ld

Question 13

What will be the effect of chmod 261 when applied to file FAILED.txt

Correct Answer: -w-rw-x

Question 14

Injae want to view all the assigned alias in her Ubuntu terminal, Which command she need to execute to
do this?

Correct Answer: alias

Question 15

It is convenient when you want to access a file that has a long file name.

Correct Answer: Filename Completion

Question 16

Which of the following file contains the encrypted password of the users?

Correct Answer: /etc/shadow

Question 17

Which command can be used to find a word from a text file?

Correct Answer: grep

Question 18

JP type in vim STARTUP and it open the VIM editor, how can he change the mode to insert mode?

Correct Answer: He can type or press :i or press shift i


Question 19

Which of the following octal mode permission will satisfy the given permission r-rwx-x?

Correct Answer: 471

Question 20

A file permission that contents can be modified.

Correct Answer: Write

Question 21

How can you set the default rwx permission to all users on every file which is created in the current
shell?

Correct Answer: umask 777

Question 22

A linux administrator created a file called SUM and he executed the command chmod a+r SUM, What
will happen to the permission of the file?

Correct Answer: all will have read permission

Question 23

A command language interpreter that incorporates a command history buffer?

Correct Answer: C shell

Question 24

What will be displayed after executing is ??c? Given the following list of files…zz abc abcd abcdef abcz
bbabb cyz zzayy

Correct Answer: abcd abcz

Question 25

How do you get all files with on the 3 rd place an r,g or i?

Correct Answer: Is ??(rgi)*

Question 26

What will be displayed after executing ls * .dat Given the following list of files…profile ab.dat abcd.dat
abcde abcde.data

Correct Answer: ab.dat abcd.dat

Question 27

What will be the effect of chmod 701 when applied to file PASS.txt
Correct Answer: rwx------x

Question 28

Which of the following command that will list only the file “error.txt”

Correct Answer: Is error.txt

Question 29

Unix identifies every process by a Process Identification Number(PID) which is assigned when the
process is initiated. When we want to perform an operation on a process, we refer to its PID or
Processid.

Correct Answer: True

Question 30

How do you stop a process?

Correct Answer: kill pid


• Question 1
Erases the command line in Ubuntu
Correct Answer:
Ctrl + U
• Question 2
"Assuming ""aos"" directory is not empty, write the UNIX command that will delete the given directory."

Correct Answer:
Evaluation Method Correct Answer Case Sensitivity
Exact Match rm -r aos

Exact Match rm -r "aos"

Exact Match rm -r ""aos""

• Question 3
"The head and tail commands, allow you to view the first few or last few lines of a file
(15 lines by default)."
Correct Answer: False
• Question 4
How would you write the code that will display the current calendar month

Correct Answer:
Evaluation Method Correct Answer Case Sensitivity
Exact Match cal oct 2020

Exact Match cal

• Question 5
How to suspend current foreground process in Unix
Correct Answer:
CTRL + Z
• Question 6
Write a command that will create a file called file1.txt

Correct Answer:
Evaluation Method Correct Answer Case Sensitivity
Exact Match touch file1.txt

Exact Match >file1.txt

Exact Match > file1.txt

Exact Match cat>file1.txt

• Question 7
The usrs directory contains configuration files that the system uses when the
computer starts.
Correct Answer: False
• Question 8
Command that will allow you to move a file in another directory
Correct Answer:
mv
• Question 9
Most shells keep a list of your recently used commands and allow you to recall a
command without retyping it.
Correct Answer: True
• Question 10
"How would you display the current calendar year, were the current day is selected"
Correct Answer:
Evaluation Method Correct Answer Case Sensitivity
Exact Match cal -y

• Question 11
"The less command scrolls only down, whereas more enables you to scroll down and
up."
Correct Answer: False
• Question 12
Write the UNIX comannd that will create a directory called LONGTEST
Correct Answer:
Evaluation Method Correct Answer Case Sensitivity
Exact Match mkdir LONGTEST

• Question 13
It indicates EOF end of file or exit
Correct Answer:
CTRL + D
• Question 14
Command that will allow you to create another name for a file
Correct Answer:
ln
• Question 15
The rm -r command can be used to delete a directory that is not empty.
Correct Answer: True
• Question 16
"Assuming you have newfile1.txt in your home directory home/leo/, how would you
copy newfile1.txt to a directory called backup"
Correct Answer:
Evaluation Method Correct Answer Case Sensitivity
Exact Match cp newfile1.txt ./backup

• Question 17
"How would you list the content of the directory called ""Project"" that will show the permission of files in UNIX"

Correct Answer:
Evaluation Method Correct Answer Case Sensitivity
Exact Match ls -l

Exact Match ls -l ./Project

Exact Match ls -l ./"Project"

Exact Match ls -l ./""Project""

Exact Match ls -l Project

Exact Match ls -l "Project"

Exact Match ls -l ""Project""

• Question 18
Creates empty file and modifies the last modified timestamp
Correct Answer:
touch
• Question 19
You can use the date command to show the system calendar.
Correct Answer: False
• Question 20
Write the command that will display the current date following the sequence day month year

Correct Answer:
Evaluation Method Correct Answer Case Sensitivity
Exact Match date +%d/%m/%y

Exact Match date '+%d/%m/%y'

• Question 21
It specify the entire file hierarchy
Correct Answer:
Absolute Path
• Question 22
UNIX/Linux systems interpret a single dot character to mean the current working
directory.
Correct Answer: True
• Question 23
How would you redirects the output of a command and appends to the file in Unix
Correct Answer:
>>
• Question 24
"How would you list the content of the directory called ""Project"" that will include hidden files in UNIX"

Correct Answer:
Evaluation Method Correct Answer Case Sensitivity
Exact Match ls -a

Exact Match ls -a ./Project

Exact Match ls -a ./"Project"

Exact Match ls -a ./""Project""

Exact Match ls -a Project

Exact Match ls -a "Project"

Exact Match ls -a ""Project""

• Question 25
"You use the ls command to display a directory's contents, including files and other
directories."
Correct Answer: True
• Question 26
It reprresent the current directory position
Correct Answer:
.
• Question 27
Command that will allow you to compare to text files in UNIX

Correct Answer:
diff
• Question 28
Write the UNIX comannd that will delete a directory called project
Correct Answer:
Evaluation Method Correct Answer Case Sensitivity
Exact Match rmdir project

• Question 29
Stops screen output
Correct Answer:
CTRL + S
• Question 30
"Which among the following command line that will create files as series named f1,
f2, f4"
Correct Answer:
Both A and B
• Question 31
How would you redirects the output of a command to a file and overwrites the current
content of the file.
Correct Answer:
>
• Question 32
How would clean or clear the screen in UBUNTU
Correct Answer:
Evaluation Method Correct Answer Case Sensitivity
Exact Match clear

• Question 33
The command cd source uses relative path addressing.
Correct Answer: True
• Question 34
"Assuming you have file1.txt inside project directory, how would you copy file1.txt to
the home directory "
Correct Answer:
Evaluation Method Correct Answer Case Sensitivity
Exact Match cp file1.txt ../

• Question 35
Create a link file of science.txt and name it as science.link
Correct Answer:
Evaluation Method Correct Answer Case Sensitivity
Exact Match ln science.txt science.link

• Question 36
"Assuming you have the following files ""fruits"" and ""prutas"", write a UNIX command
that will compare the the two files"
Correct Answer:
Evaluation Method Correct Answer Case Sensitivity
Exact Match diff fruits prutas

• Question 37
It represents the route through the hierarchy that is traversed to reach the desired file
or directory
Correct Answer:
pathname
• Question 38
It reprresent the directory immediately above your current position
Correct Answer:
..
• Question 39
"In UNIX, what command should you use to rename or move a file to a different
directory"
Correct Answer:
Evaluation Method Correct Answer Case Sensitivity
Exact Match mv

• Question 40
"wc is a command in UNIX used to print newline, word, and byte counts of a file"
Correct Answer: True

Cal reports the date and time

False

Set/Display network information

Hostname

Ifconfig

Ipconfig

Uname

One of the variation of Unix was called Linux

True

Command use to displays directory using absolute path name

Pwd

A command used with absolute or relative pathnames to navigate


Cd not sure

Dos command that deletes one or more files

Del

Ls command in UBUNTU is similar to pwd in MS DOS

False

Man is the command for bringing up online help in MS DOS

False

A component of a computer’s OS, this is a user interface for access to the operating system’s services.

Command line

Shell not sure

Gui

All of the above

Clear a command line screen/window for a fresh start

True or false

Dos Command showing drive C tree

Tree

A family of multitasking, multiuser computer operating systems

Unix
1. An __________________ serves as a liason between the consumers and the resources, often
coordinating the allocation of limited resources among numerous consumers.
▪ operating system
2. Give the equivalent UNIX-LINUX command of the given DOS command: ATTRIB +h or -h
▪ mv file .file
3. _______ shell that was developed at the University of California Berkley by Bill Joy that allows
recalling and editing of previously entered commands and aliasing.
▪ C
4. ________ an operating system components that manages the operation of the computer.
▪ Kernel
5. _________ is a location for other files and subdirectories.
▪ Directory
6. Program Execution _________ the user program in memory and runs it.
▪ Loads
7. Unix Variants and its manufacturer
▪ Linus Torvalds - LINUX
▪ Sun Microsystems -SOLARIS
▪ Open Software Foundation – OSF/1
▪ Microsoft - FENIX
▪ Hewlett-Packard – HP-UX
▪ IBM - AIX
▪ Digital Equipment Compaq (DEC) – ULTRIX
8. __________ shell is similar to Korn shell, it is a command programming language and command
interpreter which supports command history, line editing, filename completion, aliasing, and job
control.
▪ POSIX
9. A __________________ is the operating system feature that manages the different computer
resources such as CPU time, memory space, file storage space, I/O devices, etc. and allocates
them to different application programs and users.
▪ resource allocator
10. ______________ (3 words) handles the way files are organized within the disk or tape. It takes
care of the creation and deletion of files for users.
▪ File system handling
11. _________ shell which is an original shell program that was developed for AT&T, provides a
UNIX system command interpreter and supports a programmable interface to develop shell
programs.
▪ Bourne
12. Common Subdirectories
▪ executables, system admin utilities, and library routines - /usr directory
▪ applications and third-party applications - /opt directory
▪ files which are pointers to device names - /dev directory
▪ system admin files (passwd file) - /etc directory
▪ user home directories Correct - /export/home directory
▪ basic operating system files - /kernel directory
▪ print spooling and mail system error messages - /var directory

13. ____________ is any directory below another directory.


▪ Subdirectory
14. Give the equivalent UNIX-LINUX command of the given DOS command: BREAK ON
▪ Trap
15. A ___________ is a group of directories that can be thought of as a separate tree structure.
▪ file system
16. Give the equivalent UNIX-LINUX command of the given DOS command: SUBST V:
C:\directory\path
▪ Mount
17. _____________ controls the execution of programs and the various I/O devices.
▪ Control program
18. ___________ shell is an enhanced Bourne shell, an additional features such as aliasing and
history and is most widely used shell and is industry standard for users.
▪ Korn
19. ________ contained in directories and subdirectories.
▪ Files
20. Give the equivalent UNIX-LINUX command of the given DOS command: pkzip
▪ tar and zip
21. UNIX-LINUX Commands and its Action
IT 2625 – QUIZZIZ 1

1. Dos command that allows to advance inside the C unit - cd


2. Dos command to go back one level – cd..
3. Command showing drive C tree - tree
4. Dos command that deletes one or more files - del
5. What line is properly formatted to navigate to the windows directory? – cd .\Windows
6. What command would you use to fix errors on a hard disk? - chkdsk /F
7. Which command clears the screen? – cls
8. How would you remove ‘myfile’ from your flash drive? – del e:\myfile
9. Which command displays the read only files in a directory? – dir /A :R
10. How do you close a command prompt window? – exit
11. To copy all of the files in a directory tree, which command would you use? – xcopy
c:\Windows e:
12. The command line window is full of output from other commands and is cluttered and hard
to read. - cls
13. You want to see a list of the commands recently executed so you can choose one to run
again – F7
14. You entered a command incorrectly and would like to bring back the incorrect command so
you can correct it and run it. – up-arrow
15. You want to see all the commands available at the command line. – help
16. You are finished working at the command line and want to end the session. – exit
17. A command is generating a lot of output and is taking too long to run. You want to stop it. –
Ctrl + C
18. The basic command for creating a new directory is? – mkdir
19. The basic Linux command to delete empty directories is? – rmdir
20. The command for bringing up online help is? – man
21. To move a directory on DOS is a function of the command? – cd
22. Which of the following commands in Linux is used to display information about files and
directories contained within the current working directory? – ls
23. Which of the Linux command-line commands listed below is used for directory traversal? –
cd
24. A Linux command displaying an absolute path to (ie. full filename of) the current working
directory is called – pwd
IT 2625 – QUIZZIZ 1

25. A Linux command-line command allowing a user to change his/her own password is known
as – passwd
26. What is Terminal? – a program which enables you to access the shell
27. A command line command in Linux used for deleting files and directories is known as - rm
28. Which of the following commands allows for moving one level up in Linux directory tree? –
cd ..
29. Which of the following key combinations allows to terminate the current process in Linux
shell? – Ctrl + C
30. Which of the following commands in Linux is used to display information about files and
directories contained within the current working directory? - ls
What is an Operating System?

An Operating System is a special computer program (software) that


controls the computer (hardware). The Operating system serves as a liaison
between the consumers and the resources, often coordinating the
allocation of limited resources among numerous consumers.

Disks
Users
Memory
CPU
Operating System
Programs Network
Printers

Consumers Resources
UNIX Operating System
An operating System can be thought of as
1. Resource Allocator – the operating system manages the
different computer resources such as CPU time,
memory space, file storage space, I/O devices, etc. and
allocates them to different application programs and
users.
2. Control Program – it controls the execution of programs
and the various I/O devices.
Unix Services
An operating system provides the following services for users:
1. Program Execution – loads the user program in memory and
runs it.
2. I/O Operations – responsible for reading and/or writing data
from I/O devices such as disks, tapes, printers, keyboards, etc.
3. File System Handling – handles the way files are organized
within the disk or tape. It takes care of the creation and
deletion of files for users.
4. Error Detection – detect errors within the computer system
(CPU, memory, I/O, or user program) and take the appropriate
action.
History of UNIX
1969 UNIX developed by AT&T Bell Labs
1980 UC Berkeley BSD UNIX 4.2 becomes widely used
Early 1980s Hewlett-Packard introduces HP-UX
Early 1990s POSIX, Portable Operating System Interface
UNIX Variants
•AIX – from IBM
•HP-UX – from Hewlett-Packard
•Ultrix – from DEC
•Xenix – from Microsoft
•OSF/1 – from Open Software Foundation
•Solaris – from Sun Microsystems
•Linux – Linus Torvalds
•Ubuntu
•Suse (Novell Netware)
•Red Hat
•Debian
UNIX Varieties and Benefits

Benefits of UNIX
•based on an open standard
•supported on a wide variety of computers
•TCP/IP tightly integrated
•true 64bit architecture
•Hierarchical File System
•Multi-tasking; Multi-user
File System Directory Hierarchy
File System - group of directories that
can be thought of as a separate tree
structure
similar to logical partitions in the
Windows/DOS world (like C: or D:
drive)
made available (mounted) or
unavailable (unmounted) at the
administrator’s discretion
can either be local (on your computer)
or remote (on another computer)
Directory - location for other files and
subdirectories
like a file drawer in a file cabinet
Subdirectory - Any directory below
another directory
Files - contained in directories and
subdirectories
Common Subdirectories /usr directory - executables,
system admin utilities, and library
routines
/opt (optional) directory -
applications and third party
applications
/dev (devices) directory - files
which are pointers to device names
/etc (etcetera) directory - system
admin files (passwd file)
/export/home directory - user
home directories
/kernel directory - basic operating
system files (main UNIX kernel
genunix)
/var (variable) directory - print
spooling and mail system error
messages
Operating System Components
Shells
Bourne shell ($)
•developed by Stephen Bourne for AT&T
•original shell program
•Provides a UNIX system command interpreter
•Supports a programmable interface to develop shell programs
Korn shell ($)
•developed by David Korn at Bell Labs
•An enhanced Bourne shell
•added features such as aliasing and history
•most widely used shell and is industry standard for users
•this course is based primarily on the Korn shell
Shell cont..

C shell (%)
•developed at the University of California Berkley by Bill Joy
•Short California Shell
•based on the C programming language
•Allows recalling and editing of previously entered commands and
aliasing
POSIX shell
•Similar to Korn shell
•Command programming language and command interpreter
•It supporst command history, line editing, file name completion,
aliasing, and job control
Chapter 2
Logging In and General Orientation
Login ID and Password
Login ID
•user’s “public name”
•must be unique and limited to eight lower case letters and numbers
•stored in the password (/etc/passwd) file which can be viewed by all users
•encrypted passwords are stored in the /etc/shadow file

Passwords
•no less than six and no more than eight characters
•different from the Login ID
•at least two alphabetic characters and one numeric or special character
•case sensitive
•new password must differ by at least three characters
•may contain spaces and special characters
•these password rules do not apply to the root account!
User Accounts
Root or "super user"
•system admin
•set up by default during the installation process
•owns all system files and has access to all files
•used to create new users, manage file systems, install software and
perform other high-level system admin tasks
•Most sysadmins have a regular user account and only login as root when
necessary to perform administrative tasks

Regular User
•created and maintained by the sysadmin when logged on as root
•can run applications programs and customize working environment
•can also create and modify files in their home directory
Changing Password

•must be done at command line


•can be done by regular user
$ passwd
passwd: Changing password for user02
Enter login password: ABC 123
New password: abc 456
Re-enter new passwd: abc 456
Command-line Format
Syntax:
$ command [-options] [arguments] return
Examples:
$ date
$ls
•case sensitive
•Can type 2 commands on a single command
line, separated by a semicolon $ ls;pwd
The Secondary Prompt
$ banner ‘hi

➢there’
$(

$ if
*press ctrl c if you want to terminate currently running
program
Some Beginning Commands
$who – is used to determine the users currently
logged in the system.
$finger – same as who
$whoami – is used to determine who is currently
logged-in at a particular terminal.
$date - reports the date and time
$passwd - assign a login password
Some Beginning Commands cont.
• $echo - writes arguments to the terminal
• $clear - clears the terminal screen
• $write - sends message to username if logged in
• $talk -
• $mesg [y|n] - allows or denies writes to your terminal
Some Useful Keys to Remember
• Ctrl+C – Use this to abort a running UNIX program
• Ctrl+S – Use this freeze a screen output
• Ctrl+Q – Use this to unfreeze a screen output
• Ctrl+R – Use this to refresh or redraw your screen
• Ctrl+L – Use this if Ctrl+R does not work
• Backspace – Use this to erase mistakes before pressing the Enter key
Logging out
• Ctrl+D
• exit
man pages

UNIX Programmer’s Manual


describes the system’s on-line commands, system
calls, file formats, and system maintenance
installed by default
character-based screen displays and are not graphical
command prompt to access
man command

$ man name - help on particular command


$man -k keyword - Searches the man pages table of contents for
the specified keyword and displays one-line summary for each entry
$ man -s section name - Displays a particular section of the man
pages which can include multiple commands
Chapter 3
Getting Help
man Page Output NAME - name of command
and other commands that do
the same thing
SYNOPSIS - syntax of
command with options and
arguments
DESCRIPTION - overview of
what command does
OPERANDS - target of the
command
OPTIONS - switches that
change the function or effect of
the command; normally
preceded by a dash (-)
SEE ALSO - Refers you to
other related commands and
subjects
whatis Command

display the header line


from the manual section
brief definition of the
command
helpful if you can
remember the
command name but
forgot what it does
man Pages Scrolling

man pages can be many screens of output


Troubleshooting
Unresponsive Terminal:
•Enable screen scroll using Control –Q (Ctrl + q keys)
•Interrupt the process using Control –C (Ctrl + c keys)
•Enter EOF (end of file) using Control –D (Ctrl + d keys)
•Quit the window and restart a new one.

Unresponsive Application:
•Determine the process ID number associated with the
application and kill that process (chap 13)
•Logout and log back in again then restart the application .
Chapter 4
Accessing Files and Directories
Path Names
• A path name represents the route through the hierarchy that is
traversed to reach the desired file or directory
Types of Pathnames
Absolute Pathname
•Specifies the entire file hierarchy
•Start at root (/) and list each directory along the path to the
destination
•Slash (/) between each directory name in the path
•Example:
/home/user3/f1

Relative Pathname
•Always starts at your current location in the hierarchy
•If a pathname does not begin with a slash, it is a relative
pathname
•you must know what directory you are currently in since that is
your starting point
Absolute Path
Absolute Path
• Absolute pathname to the user2 directory
• /home/user2
• Absolute pathname to the dir1 directory
• /home/user2/dir1
• Absolute pathname to the coffees directory
• /home/user2/dir1/coffees
Relative Path
Relative Path
• If your current directory is /home:

• Relative pathname to the user2 directory


• user2
• Relative pathname to the dir1 directory
• user2/dir1
• Relative pathname to the coffees directory
• user2/dir1/coffees
Some Special Directories
Absolute Relative to
/home/user3

/home ..
/home/user2 ../user2
/home/user1/f1
../user1/f1
/ ../..

The entry called dot(.) represents your current directory position

•The entry called dot dot(..) represents the directory immediately


above your current directory position
Examples of DOT
If you are currently in the directory /home/user3:

.
./f1
./memo/f1
Examples of dot dot
• If you are currently in the directory /home:

• ..
• ../..
• ../tmp
• ../tmp/f1
• If you are currently in the directory /home/user3:

• ..
• ../..
• ../user2../user1/f1
• ../../tmp/f1
Using Navigation Shortcuts
pwd (print working directory) command -
•no options or arguments
•displays directory using absolute path name

cd (change directory) command -


•used with absolute or relative pathnames to navigate
•by itself takes you to your home directory

cd .. command takes you up one level


cd ~/ command takes you to a directory under your
home directory (tilde = home)
cd- Change Directory
Syntax:
cd [dir-pathname]
Examples:
$ pwd
/home/user3
$ cd memo; pwd
/home/user3/memo
$ cd .. /..; pwd
Using ls Command
ls
(list) listing of files and directories within the current directory or specified directories

ls –a
list all files in a directory, including hidden (.) files and current (.) and parent (..)
directories

ls –F
displays listing with a symbol to tell what the type the file is:
directory – A forward slash (/) after the name
ASCII Text File - no symbol
Executable – asterisk (*) after the name
Symbolic Link – An at sign (@)
Displaying Long Listing
Recursive Listing

ls -R (recursive) command
- Displays the contents of all directories, subdirectories and their contents for a particular part of
the directory tree
- If done at a high level in the directory structure, the output can be substantial!
Creating & Removing Files & Directories
mkdir - creates directories or folders
must have the appropriate permissions to create a directory
–p (parent) option creates parent directories while creating lower level directories, including all
the directories in a pathname

rm - removes a single file or multiple files


specify their names or use wildcard metacharacters (*) (?)
files that are deleted are permanent and cannot be recovered!
rm -i (interactive) - prompts the user before removing files
rm –r (recursive) - removes directories
removes the directory including all subdirectories and files in it!
rm -ri (or rm -ir) - removes directories interactively
mkdir and rmdir – create and remove directories

Syntax: mkdir [-p] dir_pathname (s)


rmdir dir_pathname (s)…
Example:
$ pwd
$ mkdir fruit
$ mkdir fruit/apple
$ cd fruit
$ mkdir grape orange
$ rmdir orange
$ cd ..
$ rmdir fruit
$ rmdir fruit/apple fruit/grape fruit
DOS COMMANDS
And its LINUX/UNIX Equivalent
DOS Commands and UNIX/LINUX Command (Bash or Sudo Command)
Command Comparison:
DOS Command UNIX or Bash Command Action
DIR ls -l (or use ls -lF)(-a all files)
(df -k Space remaining on List directory contents
filesystem)
DIR *.* /o-d List directory contents by reverse
DIR *.* /v /os ls -tr time of modification/creation.
DIR /s ls -ls List files and size
DIR /aa ls -R List directory/sub-directory
ls -a contents recursively.
List hidden files.
TREE ls -R List directory recursively
CD cd Change directory
DOS Command UNIX or Bash Command Action
MKDIR
mkdir Make a new directory
MD
ASSIGN ln Create a file or directory link
RMDIR
rmdir Remove a directory
RD
CHDIR pwd Display directory location
DEL
rm -iv Remove a file
ERASE
DOS Command UNIX or Bash Command Action
RMDIR /S (NT) Remove all directories and files
rm -R
DELTREE (Win 95...) below given directory
COPY cp -piv Copy a file
Copy all file of directory
XCOPY cp -R
recursivly
RENAME or MOVE mv -iv Rename/move a file
Dump contents of a file to users
TYPE cat
screen
Pipe output a single page at a
MORE more
time
HELP or COMMAND /? man Online manuals
clear
CLS Clear screen
ctrl-l
DOS Command UNIX or Bash Command Action
EXIT exit Exit a shell
EXIT0 exit 0
FIND Look for a word in files given in
grep
FINDSTR command line
Compare two files and show
COMP diff differences. Also see comm, cmp,
mgdiff and tkdiff.
Compare two files and show
FC diff differences. Also see comm, cmp,
mgdiff and tkdiff.
SET set and env List all environment variables
SET variable=value set Set environment variables
echo %variable% export variable=value Show environment variables
echo $variable
DOS Command UNIX or Bash Command Action
ECHO text echo text Echo text to screen
setenv (for C shell) or
SET variable export VAR=val (for Korn shell. Set environment variables
Also VAR=val)
Display search path for
PATH echo $PATH
executables.
PATH %PATH%;C:\DIR PATH=$PATH:/dir
Set PATH environment variable.
PROMPT $p$g export PS1='\h(\u)\W> ' Set user command prompt.
Show date. (also set date - DOS
DATE or TIME date
only)
DOSKEY /h history List command history
DOS Command UNIX or Bash Command Action
BREAK ON trap Trap ctrl-break / Trap signals.
Sort data
SORT sort
alphabetically/numerically
EDLIN ed Line mode editor
EDIT filename.txt Edit a file. The Linux editor which
looks most like DOS edit is
pico, gnp, vi, xedit, xemacs,dtpad
probably Pico. (Not a
recomendation!)
BACKUP files A:\ tar -cvf /dev/fd0 files
Save files to floppy.
mdir, mcopy
See Using DOS floppies
doswrite -a file (AIX only)
tar -xvf /dev/fd0 files
Read files from floppy.
RESTORE A:\ files mdir, mcopy
See Using DOS floppies
dosread -a file (AIX only)
DOS Command UNIX or Bash Command Action
Change file permissions. DOS:
ATTRIB [+r|-r] [+a|-a] [+s|-s]
chmod +:set to -:remove r:Read only
[path\file] /s
a:Archive s:System /s:recursively
Change file to a hidden file -
ATTRIB +h or -h mv file .file
rename file with prefix "."
PRINT lpr Print a file
CALL source script (cshrc)
Execute script from within batch
COMMAND /C (DOS), CMD (NT) . script (bash)
shell.
sh script
MEM free
Show free memory on system
top
DOS Command UNIX or Bash Command Action
SCANDISK fsck
Check and repair hard drive file system
DEFRAG C: debugfs
CHDISK du -s Disk usage.
FDISK fdisk Tool to partition a hard drive.
SUBST V: Mount a drive letter to a folder/directory on your
mount
C:\directory\path hard drive.
FORMAT mke2fs Format drive file system.
See: fdformat and mformat For floppy drive use see YoLinux Tutorial Using
for floppies DOS Floppies with Linux
uname -a
VER echo $SHELL Operating system/shell version
cat /etc/issue
pkzip Compress and uncompress files/directories. Use
tar and zip tar to create compilation of a directory before
compressing. Linux also has compress, gzip
HOSTNAME hostname Print host name of computer
PING ping Send packets to a network host
Show routes and router hops to
TRACERT traceroute
given network destination.
ifconfig
IPCONFIG (NT) Display/configure network
or
WINIPCFG (Win 95...) interface
ip addr show
Chapter 5
Basic Directory and File Management
Command Line Control Characters
What can we do with files?
ls -look at the characteristics of a file
cat -look at the contents of a file
more -look at the contents of a file, one screenful at a time
lp -print a file
cp -make a copy of a file
mv -change the name of a file or directory
mv -move a file to another directory
ln -create another name for a file
rm -remove a file
cat more head tail Commands
head
•displays the first n lines
•first 10 lines are displayed by default if the -n
option is omitted.

tail
•displays the last n lines of a file
•last 10 lines are displayed by default if the -n
option is omitted.
•allows you to check the end result of the backup
without looking at the whole file
•-n option allows you to start displaying lines from a
specific point in a file
wc and diff Commands
wc (word count) command
•displays line, word, byte or character counts for a text file
•without options will give a line, word, and byte count of the contents of the file
Option Function
-l Counts lines
-w Counts words
-c Counts bytes
-m Counts characters

diff (difference) command compares two text files and finds differences
Command Format: $ diff [option] file1 file2
–i option ignores the case of the letters
–c option performs a detailed comparison and produces a listing of differences with three lines of
context
Copy Files
• Syntax:
• cp [-i] file1 new_file
• cp [-i] file [file…] dest_dir
• cp –r [-i] dir [dir…] dest_dir

• Examples:
• $ ls –F
• $ cp f1 f1.copy
• $ ls –F
• $ cp note remind memo
Move or Rename Files
• Syntax:
• mv [-i] file1 new_file
• mv [-i] file [file…] dest_dir
• mv [-i] dir [dir…] dest_dir
• Examples:
• ls –F
• mv f1 file1
• ls –F
• mv f2 memo/file2
• ls –F
• ls –F memo
diff Output
Link Files
Syntax:
ln file new_file
ln file [file. . .] dest_dir
Example:
$ ls –l f1
$ ln f1 /home/user2/f1.link
$ ls –l f1
$ ls –l /home/user2
$ ls –i /home/user2/f1.link
Chapter 6
File System Security
Filename Specifications
•Maximum of 14 characters
•Maximum of 255 characters if long
filenames are supported
•May contain alphabetic, numeric, dot,
dash and underscore
Security Policies
•The UNIX system incorporates a 3-tier structure to define who has
access to each file and directory:
User Group Others
•The ls –l command displays the owner and group who has access to
the file
•Default for Files
Read/Write for User and read only for Group and Other
•Default for directories
Read/Write/Execute for User and Read/Execute for Group and Other
File Types
•- regular file
•d directory
•l symbolically linked file
•n network special file
•c character device file
•b block device file (disks)
File System Permissions

- rw-r-- r--
drwxr-xr-x
user - owner / creator of file or directory
group – permissions used by members of the group that owns the file or directory
other – all users other than the file owner, and members of the group that owns
the file or the directory.
Permissions
User & Group ID

$ ls -n
displays the UID and the GID
$ id
displays numeric and alphabetic User ID and Group ID for your Effective User ID (EUID)
$ groups
displays all of the groups you are a member of
Changing Permissions Syntax
$ chmod mode filename
We use the chmod command to change the access mode of a file

The mode portion is made up of three parts:


Who - Category you are working with
u = user
g = group
o = others
a = all

Op - Operator
set (=)
remove (-)
give (+)

Permission(s) assigned – Read (r), Write (w) or Execute (x)


Changing Permissions - Symbolic
Permissions - Octal Mode
octal - eight possible numbers in group
bits are either on (1) or off (0)
7 r w x 1 1 1
6 r w - 1 1 0
5 r - x 1 0 1
4 r - - 1 0 0
3 - w x 0 1 1
2 - w - 0 1 0
1 - - x 0 0 1
0 - - - 0 0 0
Changing Permissions - Octal
umask  The umask (UNIX shorthand for "user file-creation mode mask") is a
four-digit octal number that UNIX uses to determine the file
permission for newly created files
 The umask specifies the permissions you do not want given by default
to newly created files and directories. umask works by doing a bitwise
AND with the bitwise complement of the umask. Bits that are set in the
umask correspond to permissions that are not automatically assigned
to newly created files.
 By default, most UNIX variants specify an octal mode of 666 (any user
can read or write the file) when they create new files. Likewise, new
programs are created with a mode of 777 (any user can read, write, or
execute the program)
 Octal umasks are calculated via the bitwise AND of the unary
complement of the argument (using bitwise NOT) and the permissions
specified by the program: typically 666 in the case of files, and 777 in
the case of directories.
Octal umask example
• Assuming the umask has the value 174, any new file will be
created with the permissions 602 and any new directory will
have permissions 603 because:

• 666 AND NOT(174) = 602


• while
• 777 AND NOT(174) = 603

• Computation:
• 7778 = (111 111 111)2
• 1748 = (001 111 100)2
• NOT(001 111 100)2 = (110 000 011)2
• (111 111 111)2 AND (110 000 011)2 = (110 000 011)2
• 7778 NOT (174)8 (603)8
Other commands
touch - either creates one or more files with zero bytes if
none exists; or updates date/time stamp if file already exists
-a time change access time to time
-m time change modify time to time
-t time use time as your current time
-c if the file does not already exists, do not create it

Example: To create/update more than 1 file:


$touch f1.txt f2.txt f3.txt
The chgrp Command
• Changes access to a file; only the owner of file can
change the group of the file

• Syntax:
• $ chgrp newgroup filename
su - switch user id
• Changes your user id and group id designation

• Syntax:
• $ su [username]
The newgrp command
• Changes the group id.

• Syntax:
• $ newgrp [group_name]
chown
Change file ownership
Syntax:

$ chown owner [:group] filename . . .


Example:
$ id
$ cp f1 /tmp/user2/f1
$ ls -l /tmp/user2/f1
$ chown user2 /tmp/user2/f1
$ ls -l f1 /tmp/user2/f1

You might also like