0% found this document useful (0 votes)
11 views23 pages

Unix Mid Prep - Merged

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

Unix Mid Prep - Merged

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

Handling Ordinary Files – File attributes

> Some lines have been changed.: This line was modified in file2.txt compared to file1.txt.

4a5,6: This indicates that new lines have been added starting from line 5 in file2.txt.

a denotes the addition of lines.

5,6 denotes the range of lines added.

> New lines have been added. and > New lines have been added at the end.: These lines are
the additions in file2.txt.

`zip` command: PACKAGE & COMPRESS ( ARCHIEVE ) FILES

✓ The `zip` command is a commonly used utility for creating compressed archive files in
the ZIP format.
✓ It allows you to combine multiple files and directories into a single compressed
archive, making it easier to store and transfer large amounts of data.
Syntax:
zip [OPTIONS] ARCHIVE_NAME(.zip) FILE1 FILE2 ...

NOTE:
• Archiving refers to the process of collecting and storing data files or directories in a
compressed format or a single container file.
• The purpose of archiving is to reduce the size of the data and organize it for efficient
storage, backup, and transfer.
• When files or directories are archived, they are typically compressed to occupy less
disk space.
• Archiving software, such as ZIP, TAR, or RAR, is commonly used to create and
extract archives.
• Compressing refers to the process of reducing the size of files or directories by using
compression algorithms.

Dept. of CS
Handling Ordinary Files – File attributes

`zip` command with OPTIONS:


Ø -r or --recurse-paths: Recursively includes directories and their contents in the
archive.
Ø -j or --junk-paths: Stores files without including their directory paths.
Ø -u or --update: Updates an existing archive with new or modified files.
Ø -d or --delete: Deletes files or directories from an existing archive.
Ø -v or --verbose: Displays detailed output while creating the archive.

Examples:
1. Create a basic ZIP archive named sample.zip containing two files:
$ zip sample.zip.zip file1.txt file2.txt
2. Create a ZIP archive recursively including a directory and its contents:
$ zip -r sample.zip directory
3. Update an existing ZIP archive with new or modified files:
$ zip -u sample.zip newfile.txt
4. Delete files from an existing ZIP archive:
$ zip -d sample.zip file1.txt

Dept. of CS
Handling Ordinary Files – File attributes

`unzip` command: LIST, TEST, EXTRACT COMPRESSED FILES IN A ZIP ARCHIVE


✓ The `unzip` command is a utility used to extract files and directories from ZIP
archives.
✓ It allows you to decompress and restore the original files from a compressed ZIP
archive.
Syntax:
unzip [OPTIONS] ARCHIVE.zip

`unzip` command with OPTIONS:


Ø -l or --list: Lists the contents of the ZIP archive without extracting them.
Ø -d or --DIRECTORY: Specifies the destination directory where the files will be
extracted. If not provided, the files are extracted to the current working directory.
Ø -o or --overwrite: Overwrites existing files without prompting for confirmation.
Ø -x FILE or --exclude FILE: Excludes specific files from extraction.
Ø -P PASSWORD or --password PASSWORD: Provides a password to extract
encrypted ZIP archives.
Examples:
1. Extract all files from a ZIP archive:
$ unzip sample.zip
2. Extract files from a ZIP archive to a specific directory:
$ unzip archive.zip -d /path/to/destination
3. List the contents of a ZIP archive without extracting:
$ unzip -l archive.zip
4. Extract a password-protected ZIP archive:
$ unzip -P mypassword encrypted.zip

Dept. of CS
Handling Ordinary Files – File attributes

`od` command: DUMP FILES IN OCTAL OR OTHER FORMATS


✓ The `od` command is used to display the content of files in various formats (human
readable format).
✓ It can be used to view binary, octal, decimal, or hexadecimal representations of data.
✓ The od command is often used for debugging purposes or to examine the contents of
binary files.
✓ Many files containing non-printable characters (such as `\n`, `\r`, `\b`) and most UNIX
commands do not display them properly.
Syntax:
od [options] [FILES]..
Example:
$ od file1.txt
`od` command with OPTIONS:
Ø -a or --address-radix=<radix>: Specifies the address radix to use for displaying file
offsets. The supported radix values are o for octal (default), x for hexadecimal, d for
decimal, n for none, or t for "traditional" octal (leading zeros suppressed).
Ø -b or --format=byte: Displays the file content in binary format.
Ø -c or --format=char: Displays the file content as characters, showing both printable
and non-printable characters.
Dept. of CS

You might also like