0% found this document useful (0 votes)
17 views21 pages

Ch2.FilesInUNIX 21

The document provides an overview of file properties, types, and commands in the UNIX operating system, focusing on file management and system administration. It covers the characteristics of shareable and unshareable files, various file types such as ordinary files, directories, links, and special files, as well as the syntax for UNIX commands. Additionally, it discusses user login/logout procedures, password management, and essential commands for manipulating files and directories.

Uploaded by

viptaha.2001
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views21 pages

Ch2.FilesInUNIX 21

The document provides an overview of file properties, types, and commands in the UNIX operating system, focusing on file management and system administration. It covers the characteristics of shareable and unshareable files, various file types such as ordinary files, directories, links, and special files, as well as the syntax for UNIX commands. Additionally, it discusses user login/logout procedures, password management, and essential commands for manipulating files and directories.

Uploaded by

viptaha.2001
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 21

CYS492 Selected Topics (2)

The UNIX Operating System


and System Administration

Prepared by:
Dr. Adnan
Rawashdeh
Chapter-2: Files in Unix
Properties of Files in Unix
• Files have two independent binary properties: - Shareable
Vs. Unshareable and Variable Vs. Static.
 Sharable files are those that can be stored on one host and
used on others.
 Unshareable files are those that are not shareable. For
example, the files in user home directories are shareable
whereas boot loader files are not.
 Static: include binaries, libraries, documentation files and
other files that do not change without system administrator
intervention.
 Variable files are files that are not static (eg. /etc).
 A pathname is a character string that identifies a file.
Type of files
(i). Ordinary files are aggregates of characters that are
treated as a unit by Unix,
• Egs: text-file, C-program-file, binary-file & data-file of various
kinds.
 Users can create, change, and delete ordinary files as they
wish.

(ii). Directories, a directory is a file that contain other files


(including subdirectories) and contains information about the
locations and attributes of these other files, such as their
addresses, and types (ordinary, symbolic links or directories).
Type of files (cont.)
(iii). Links, a link is a reference to another file. If the
original file is deleted all associated links are deleted too.
• Advantages:
(1) Provide a way of sharing information among several
users, and the information get updated with each
change done by each of them.
(2) Save disk space; because a link is not a second copy!
• Limitations:
(1) Links can only be done on one physical hardware
(one file system).
(2) One link only can be created for a directory!
Type of files (cont.)

(iv). Symbolic Links (New), also known as Soft Links.


• Introduced in Unix Sys. V R4 from BSD.
• A symbolic link is a file that contains the name of another file.
• It overcomes the previous limitation, thus:
– It can be done across a network, and
– It can be done in multiple numbers for either a file or a directory.

(v). Special files, every physical device associated with Unix


system (eg. Printers, modem, drives, terminal, disks…etc) is
represented in the file system.
• Most of them located in /dev directory.
File Pathname
• There are two types of pathnames:
– Absolute, starts at the root. It begins with a "/"
and is followed by zero or more file names
separated by "/" characters.
– Relative, does not begin with "/”. When a process
must resolve a relative pathname so that it can
access the file, the pathname is assumed to start
in the current working directory.
File Naming Convention
• A valid file name consists of a simple series of letters
, numbers and certain punctuation marks such as ’ .
’ and ‘ _ ‘ No space or any character represents a
field separator can be used in a file name.
• Examples:
Valid : My_File, My.File, MyFile
Invalid: My File, My\file

• Remember Unix is case-sensitive, for example,


myfile & myFile are two different names.
Components of Unix Commands
• Command String (eg. ls, cd, cp, ...)
• Parameters (eg. File1, File2, …)
• Flags; modify the behavior of Unix commands
(eg. ls can be used as: ls –l ).
• Wild cards ( * Represents any number of
characters) ( ? Represents single character).
• Syntax of Unix Commands:
$ ComString Arguments + WildCards -Flags
Logging In
• login:
Name: USER_NAME
Password: * * * * * *
Last login: Fri Mar 7 08:35:39 on tty02
UNIX System V , Release 4
$
{ Your system prompt can also be (#),(%) or
something customized by your Sys. Admin.}
Logging Out
• The normal way to log out from any shell is to
type exit; causes your shell to stop running.
$ exit
• Once you have successfully logged off the
system you see the Unix login message on
screen
• login: _
Shutting Down the System
• UNIX initiates the shutdown utility by examining its
current state, closing applications and files that are
open and then terminating its processes in an orderly
manner, once complete, your display shows this:
system is down

• **caution**
"only now it is safe to remove system power from the
computer and peripherals, shutting down Unix in any
other way can result in damage to file structure of the
operating system."
Changing Your Password
• {For security reasons you may need to change your
password regularly}
Restriction on Choosing the Password:
 Six characters or more (Unix-System V has few restriction)
• The Command passwd is used to change the Password:
• $ passwd <RT>
----msg…..changing password for user_name……..
Old password: ******** <RT>
New password: ********** <RT>
Retype new password: ********** <RT>
• $
Show Password Status
•  To Shows the status of your password:
$ passwd –s <RT>
_______________ output __________________
adnan pw 03\1\22 x 30 5 .

Login password last min days between max days between #of
day
status change change change
Directory Related Unix Command
pwd print the path of the current working directory
(pwd).
ls [<dir1>] [<dir2>] ... list the contents of the pwd, or
<dir1> , <dir2> , ... if supplied.
cd [<dir>] change pwd to HOME directory, or <dir> if it is
given.
mkdir <dir> [<dir2>] ... create new directory (and
<dir2>...) in the pwd.
rmdir <dir> [<dir2> ] ... remove the EMPTY directory
<dir> (and [<dir2> ...).
rm -r <dir> remove all contents of <dir> and the <dir>
itself. Dangerous!
File Status
• File Attributes
– Time created
– Last time modified
– Size
– Etc.
• File Mode: Attributes that describe
restrictions on access to the file.
• File Contents, some files do not have
contents, they merely interfaces used by the
OS.
Viewing File Contents
• cat [<files>] display file contents.
• more [<files>] display file contents a screen at a
time.
• less [<files>] display file contents a screen at a
time with more options.
• pg [<files>] display file contents a screen at a
time. (?!)
• head [-<n>] [<file>] display the first <n> lines of
a file, default n = 10.
• tail [-<n>] [<file>] display the last <n> lines of a
file, default n = 10.
Creating, Removing, Copying Files/Links
• ln <file1> <file2> create a new link for file <file1>
named <file2>.
• rm <files> delete a link or name for a file.
• mv <file1> <file2> rename file <file1> with the
new name <file2>.
• mv <files> <dir> move all files into the
destination directory <dir>.
• cp <file1> <file2> copy <file1> to the new name
<file2> .
• cp <files> <dir> copy all files into the destination
directory <dir>
Notes
• The ln command can only be used on files, not
directories.
• ˆ The rm command is irreversible; once a link is
removed, it cannot be recovered.
• The mv command has two forms:
– Moving files to a directory (last argument)
– Renaming file1 to become file2
• cp does not accept directories as arguments, except as
the last argument, unless you give it the option "-r",
i.e., cp -r, in which case it recursively copies the
directories. Note that cp makes copies of files, not just
their names.
Practice #1.1
• Explain in words what each of the following
commands does:
– $ rm hwk1.err hwk1.old main.o
– $ ln hwk1 /mysourcefiles/proj1
– $ cp -r main.c utils.c utils.h images /version2
THANK YOU!

You might also like