zzzAOS FinalNPrelims SecretScroll
zzzAOS FinalNPrelims SecretScroll
zzzAOS FinalNPrelims SecretScroll
Introduction to UNIX
What is an Operating System?
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
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
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
$ banner ‘hi
there’
$(
$ if
*press ctrl c if you want to terminate currently running
program
Some Beginning Commands
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:
/home ..
/home/user2 ../user2
/home/user1/f1 ../user1/
f1
/ ../..
.
./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
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
$ 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
Op - Operator
set (=)
remove (-)
give (+)
• 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
• 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:
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
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
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
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
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
• 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 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 - ‘
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 >>
$ 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 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:
$ 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:
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
$ chmod +x color3
$ gedit myinstall
$ chmod +x myinstall
$ myinstall color3
Shell Variables - # and *
# the number of command line arguments
* The entire argument string
$ gedit color4
$ chmod +x color4
$ 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
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.
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
21. Create a file using cat command with filename science.txt and enter the following text
The Electronic Telegraph Thursday 28 September 1995 Science
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?
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.
"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.
3. Check the directory name in which you are now by typing (print working directory)
5. Change the current directory. Get into Capstone_2020 and redo number 3
15. Get back out of trydir (one step higher in the tree of directories)
Check in which directory you are.
16. Remove trydir
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
$vim /etc/hosts
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.
In case you want to quit vim without saving the file, enter:
$ vim menu
$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
# 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
# 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
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
Question 2
Dosan want to exit from VIM editor without saving the changes, What must be the correct way to do it?
Question 3
Which of the following command must be used to create a new user in Ubuntu named as Dalmi
Question 4
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
Question 6
What will be displayed after executing is ??? Given the following list of files…zz abc abcd abcdef abcz
bbabb cyz zzayy
Question 7
Which of the following will display files or directory with at least 3 characters?
Question 8
Question 9
It is used to replace a command with its output within the same command line.
What will be displayed after executing is abc? Given the following list of files…zz abc abcd abcdef abcz
bbabb cyz zzayy
Question 11
What will be the effect of chmod 421 when applied to file FAILED.txt
Question 12
How can we find the process name from its process id?
Question 13
What will be the effect of chmod 261 when applied to file FAILED.txt
Question 14
Injae want to view all the assigned alias in her Ubuntu terminal, Which command she need to execute to
do this?
Question 15
It is convenient when you want to access a file that has a long file name.
Question 16
Which of the following file contains the encrypted password of the users?
Question 17
Question 18
JP type in vim STARTUP and it open the VIM editor, how can he change the mode to insert mode?
Which of the following octal mode permission will satisfy the given permission r-rwx-x?
Question 20
Question 21
How can you set the default rwx permission to all users on every file which is created in the current
shell?
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?
Question 23
Question 24
What will be displayed after executing is ??c? Given the following list of files…zz abc abcd abcdef abcz
bbabb cyz zzayy
Question 25
Question 26
What will be displayed after executing ls * .dat Given the following list of files…profile ab.dat abcd.dat
abcde abcde.data
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”
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.
Question 30
Correct Answer:
Evaluation Method Correct Answer Case Sensitivity
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
• 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
• 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
• 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
• 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
• 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
False
Hostname
Ifconfig
Ipconfig
Uname
True
Pwd
Del
False
False
A component of a computer’s OS, this is a user interface for access to the operating system’s services.
Command line
Gui
True or false
Tree
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
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?
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
➢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
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:
/home ..
/home/user2 ../user2
/home/user1/f1
../user1/f1
/ ../..
.
./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
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
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
Op - Operator
set (=)
remove (-)
give (+)
• 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
• 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: