Ch2.FilesInUNIX 21
Ch2.FilesInUNIX 21
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.
• **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!