0% found this document useful (0 votes)
29 views

Assignment 3 Pulkit SSL

This document contains Pulkit Dehariya's answers to questions about file categories, directory related commands, manipulating paths using cd, and file related commands. It provides detailed explanations of common file formats like JPEG, PNG, GIF, PDF, and MP4. It also explains commands for working with directories and files, such as ls, cd, mkdir, rmdir, pwd, cat, cp, mv, rm, comm, cmp, diff, tar, and umask with examples and syntax. Key topics covered include categories of files, absolute and relative paths, and commands for listing, creating, deleting, moving, and compressing files and directories.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

Assignment 3 Pulkit SSL

This document contains Pulkit Dehariya's answers to questions about file categories, directory related commands, manipulating paths using cd, and file related commands. It provides detailed explanations of common file formats like JPEG, PNG, GIF, PDF, and MP4. It also explains commands for working with directories and files, such as ls, cd, mkdir, rmdir, pwd, cat, cp, mv, rm, comm, cmp, diff, tar, and umask with examples and syntax. Key topics covered include categories of files, absolute and relative paths, and commands for listing, creating, deleting, moving, and compressing files and directories.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 29

Assignment 3

NAME – Pulkit Dehariya


ENROLLMENT NO. -0801IT221103

Q.1- What are Categories of files? Explain in detail?


Ans.- A file category refers to the way files are organised based on their type or
format. It helps in easily identifying and managing different types of files, such
as documents, images, videos and audio files. By categorizing files, it becomes
simpler to locate and work with specific types of files.
Some file categories are:
1. JPEG
2. PNG
3. GIF
4. PDF
5. SVG
6. MP4
01. JPEG (Joint Photographic Experts Group)
JPEG is the most common format used by digital cameras and images living on
the World Wide Web. This file format is based on lossy compression, meaning
that it keeps information that is visible to the viewer and gets rid of data that the
human eye can’t perceive. The popularity of the JPEG file stems from the fact
that it is lightweight, while still being good enough quality for digital use. Due to
its size, it will not only load faster, but it can be uploaded to any platform
regardless of size limitations. This format can also be viewed on any device
without the need to download a special image viewer. However, it’s important to
be aware that every time you save a file as a JPEG, hence compressing it over
and over again, it causes the image to lose quality and possibly become pixelated
or grainy.

Advantages: lightweight file, viewable on almost any program.


Disadvantages: loses quality when saved multiple times.
Best places to use it: images for web design, social networks, and photo
portfolios.

02. PNG (Portable Network Graphics)


PNG is a high-quality file format used for images. This file type is based on the
lossless compression, which means that it supports high-quality images for
online use while retaining the original image colours and sharpness. Unlike
JPEG files, PNGs also support images with transparent backgrounds. So, if you
want to have an image without a background, like a logo or product, you can
save it as a PNG file and use it with different backgrounds. However, this file is
not as lightweight as a JPEG. Therefore, it’s not recommended to upload
hundreds of large PNG’s to your website or portfolio as it will take up a lot of
storage and ultimately increase the loading time of your site. And nobody has
time for that.

Advantages: high-quality files, supports transparent backgrounds.


Disadvantages: heavyweight file (slows down loading time and takes up lots of
storage).
Best places to use it: logos, websites photos, social networks (profile pictures,
posts, and cover photos).

03. GIF (Graphics Interchange Format)


You’ve probably heard of this file type based on its most popular feature that’s
taken the Internet by storm: animation! The GIF file is a form of bitmap images,
meaning the graphic is composed of many tiny parts called pixels, just like the
JPEG and PNG file formats. This file type is based on LZW (Lempel-Ziv-
Welch), a special form of the lossless data compression algorithm. A GIF is most
suitable for storing graphics with a few colors, such as simple diagrams, shapes,
and logos, rather than gradients. For example, your business’ icons that contain
three colors or less look great in this file format – plus, the small file size will be
suitable to use anywhere. However, a beautiful sunset picture would not only be
too heavy of a file size but also will look distorted because of the color
limitations. One benefit of this file type is that it supports a transparent
background, like a PNG file.
Advantages: supports transparency and basic animation.
Disadvantages: displays gradient colors poorly.
Best places to use it: short animations for social channels, like Facebook and
Twitter.

04. PDF (Portable Document Format)


This file format is used for online documents and printing purposes. It was
created by Adobe with the goal of displaying files in the same format, no matter
what device they are viewed on or what software they are opened with. Thanks
to the reliability of PDFs you can create long documents and share them with
others without risking a loss to your original design – text is not larger, images
are not smaller, etc. PDF files can contain many different elements: text, photos,
vector images, videos, audio files and even interactive elements like forms and
buttons. It’s possible to create this file using many different kinds of software,
from Adobe Photoshop, Illustrator, Indesign, and Acrobat to Microsoft Word,
Google Docs and more. But to be able to view a PDF, you need to have a PDF
reader installed on your device.

Advantages: keeps all formatting regardless of what device it is displayed on.


Disadvantages: you need a PDF Reader installed on the device to view it. Best
places to use it: online forms, documents and printing services.

05. SVG (Scalable Vector Graphics)


SVG is a format commonly used to save and display vectors. Vector what?
Vector art graphics are digital illustrations that are based on geometric shapes.
They are created using a vector illustration software, like Illustrator. Apart from
the clean and professional look they embody, their biggest advantage is that they
maintain the highest quality even when resized. For example, if your business
logo is a vector – and it should be – you can resize it to fit something as big as a
billboard sign or as small as your business cards without risking a loss in quality.
Today, we can view SVG images on all web browsers. It’s also a good format for
printing purposes. So when you’re creating logos, icons and illustrations, make
sure you save them as an SVG file. Also, if you’re working with designers on
visual assets for your business, ask them to send it to you as an SVG file version,
as well as other relevant formats (like PNG, JPEG, etc.).

Advantages: resizable without losing quality.


Disadvantages: social media platforms do not support this file type.
Best places to use it: Graphics on your web design, illustrated assets for your
business (logo, icons, diagrams illustrations, etc.).

06. MP4 (Moving Picture Experts Group)


MP4 is a multimedia container format, which is just a fancy term for most of the
videos we consume on the Internet. This file can contain video, audio, and
subtitles. Thanks to its compression format, the end result will be a very
lightweight file that can be easily uploaded to your website or favorite social
media channel. MP4s can also be played on all major media players and
streamed over the Internet, so you won’t need any sophisticated program to view
it. In summary, this is the best choice for creating or saving video files to your
website, social media and more.

Advantages: lightweight file, playable on all major media players and


streamable online.
Disadvantages: we searched high and low, but it seems that this file type has no
flaws.
Best places to use it: videos on your website and social media videos
(Facebook, Youtube, Vimeo, etc.).

Q.2- What are directories Related Command? Explain with Examples &
Syntax?

Ans- 1. The "ls" command:


- Syntax: ls
- Example: If you type "ls" in the terminal, it will display a list of files and
directories in the current directory.
2. The "cd" command:
- Syntax: cd [directory]
- Example: To navigate to the "Documents" directory, you can type
"cd Documents" in the terminal.

3. The "mkdir" command:


- Syntax: mkdir [directory_name]
- Example: To create a new directory named "Photos", you can
use the command "mkdir Photos".
4. The "rmdir" command:
- Syntax: rmdir [directory_name]
- Example: To remove an empty directory named "Photos", you can
use the command "rmdir Photos".
5. The "pwd" command:
- Syntax: pwd
- Example: If you want to know the path of the current directory, you
can use the command "pwd".

Q.3- Explain Manipulating Absolute paths and Relative paths using cd


command?
Ans. 1 Absolute Paths:
 An absolute path specifies the complete location of a directory or file from the root
directory of the file system. It starts with a forward slash (/) on Unix-based systems
(like Linux) or a drive letter (e.g., C:) on Windows.
 You can use the cd command with an absolute path to directly navigate to a specific
directory, regardless of your current location in the file system. For example:
 cd /home/user/documents
This command changes the current working directory to the "documents" directory,
regardless of where you were before.
2 Relative Paths:
A relative path specifies the location of a directory or file in relation to your current
working directory.
You can use the cd command with a relative path to move to a directory that is relative to
your current position in the file system. Common symbols for relative path navigation
include:
. (dot): Represents the current directory.
.. (dot-dot): Represents the parent directory.
Directory and file names: You can specify the name of a directory or file relative to your
current location.
For example, consider the following directory structure:
/home/user
├── documents
│ ├── project
│ └── work
└── pictures
f your current working directory is /home/user, you can use relative paths with cd as
follows:
To navigate to the "pictures" directory, you can use
cd pictures
To navigate to the "project" directory from "documents," you can use:

cd documents/project

To navigate up one level to the parent directory, you can use:

cd ..

To remain in the current directory (useful for referencing files or


subdirectories), you can use:
cd

Q.4 Define File related Commands – cat, cp, mv, rm, comm, cmp, diff, tar,
umask, wc with examples & Syntax?
Ans. 1 cat (Concatenate):
cat is used to display the content of one or more files.
Syntax: cat [OPTION]... [FILE]...
Example: To display the contents of a file named "file.txt," use:
cat file.txt
2 cp (Copy):
cp is used to copy files or directories from one location to another.
Syntax: cp [OPTION]... SOURCE DEST
Example: To copy a file from one directory to another, use:
cp source-file.txt destination-directory/
3 mv (Move or Rename):
mv is used to move files or directories from one location to another or rename them.
Syntax: mv [OPTION]... SOURCE DEST
Example: To rename a file, use:
mv old-file.txt new-file.txt
4 rm (Remove):
rm is used to remove or delete files or directories.
Syntax: rm [OPTION]... FILE...
Example: To delete a file named "unwanted.txt," use:
rm unwanted.txt
5 comm (Compare Two Sorted Files Line by Line):
comm is used to compare two sorted files line by line.
Syntax: comm [OPTION]... FILE1 FILE2
Example: To compare two sorted files, use:
comm file1.txt file2.txt
6 cmp (Compare Two Files):
cmp is used to compare two files and determine if they are identical.
Syntax: cmp [OPTION]... FILE1 FILE2
Example: To compare two files, use:
cmp file1.txt file2.txt
7 diff (Compare Two Files Line by Line):
diff is used to compare two files line by line and display the differences.
Syntax: diff [OPTION]... FILE1 FILE2
Example: To see the differences between two files, use:
diff file1.txt file2.txt
8 tar (Tape Archive):
tar is used to create and manipulate archive files.
Syntax (creating an archive): tar [OPTION]... [FILE]...

Syntax (extracting an archive): tar [OPTION]... -xvf ARCHIVE_FILE

Example (creating an archive): To create an archive of files, use:


tar -cvf archive.tar file1.txt file2.txt
Example (extracting an archive): To extract files from an archive, use:
tar -xvf archive.tar
9 umask (User Mask):
umask is used to set the file permission mask for newly created files and directories.
Syntax: umask [OPTION]... [MASK]
Example: To set a umask value of 022, use:
10 wc (Word Count):
wc is used to count the number of lines, words, and characters in a file.
Syntax: wc [OPTION]... [FILE]...
Example: To count the lines, words, and characters in a file, use:
wc file.txt

Q.5 Listing seven attributes of a file: ls and its options define in details?
Ans. 1 File Name:
The name of the file or directory.
Displayed by default when you use the ls command without any options.
ls
2 File Type:
Indicates whether an entry is a regular file, directory, symbolic link, etc.
To view the file type, you can use the -F option.
ls -F
The file type is indicated by special characters at the end of the file name, such as "/" for
directories or "@" for symbolic links.
3 Permissions:
Describes who can read, write, and execute the file or directory.
Use the -l option to display a long listing, which includes permission information.
ls -l
The permission string appears at the beginning of each line and looks like "drwxr-xr-x," where
"d" indicates a directory, and the remaining characters represent read, write, and execute
permissions for the owner, group, and others.
4 Owner:

The user who owns the file or directory.


Shown in the long listing format with the -l option.
ls -l
The owner's username appears in the third column of the long listing.
5 Group:
The group associated with the file or directory.
Also displayed in the long listing format using the -l option.
ls -l
The group name is found in the fourth column of the long listing.
6 Size:
Represents the size of the file in bytes.
To see file sizes in a human-readable format (e.g., KB, MB, GB), use the -h option with -l.
bash
Copy code
ls -lh
The size is displayed in the fifth column of the long listing.
7 Timestamps:
Include three timestamps: modification time, access time, and change time.
The long listing format with -l shows these timestamps.
bash
Copy code
ls -l

Q.6 What is file permissions ? Explain Absolute and Relative permissions of


file with examples?
Ans. Absolute Permissions (Numeric Representation):
Absolute permissions are represented using numeric values (octal notation) and are assigned
using a three-digit code.
Each digit corresponds to a class of users (owner, group, others) and specifies the permissions
as a sum of values:
4 for read (r)
2 for write (w)
1 for execute (x)
The three-digit code combines the permissions for each class. For example:
644 means read and write (6) for the owner and read (4) for the group and others.
755 means read, write, and execute (7) for the owner and read and execute (5) for the group
and others.
Example: To set the absolute permissions of a file named "example.txt" to 644, use the chmod
command:
chmod 644 example.txt
Relative Permissions (Symbolic Representation):
Relative permissions are represented using symbolic characters and provide a more flexible
and human-readable way to modify permissions.
The symbolic representation consists of the following components:
u for the owner
g for the group
o for others
a for all (a combination of u, g, and o)
+ to add permissions
- to remove permissions
= to set permissions explicitly
r for read
w for write
x for execute
Example: To add read and write permissions for the owner on "example.txt," you can use the
chmod command with symbolic notation:
chmod u+rw example.txt
Example: To remove execute permission for the group and others on "script.sh," you can use
the chmod command with symbolic notation:
chmod go-x script.sh
Example: To set permissions to 755 for a script, allowing the owner to read, write, and
execute, while the group and others can only read and execute:
chmod 755 script.sh

Q.7 Explain the manipulation of file permission using chmod command?


Ans. The chmod command in Unix-like operating systems (including Linux) is used to
change or manipulate file permissions. It allows you to modify the access rights of files and
directories, specifying which users (owner, group, others) can read, write, or execute a file.
Here's an explanation of how to manipulate file permissions using the chmod command:
Syntax:
chmod [OPTIONS] PERMISSIONS FILE
PERMISSIONS can be specified in either absolute (numeric) or symbolic notation.
FILE is the name of the file or directory whose permissions you want to change.
Common chmod Options:
-c (changes): Display the changes made.
-v (verbose): Display the changes verbosely.
-f (silent): Suppress most error messages.
Absolute (Numeric) Notation:
In absolute notation, you use a three-digit code (octal notation) to represent the permissions
for the owner, group, and others. Each digit corresponds to the sum of values for read (4),
write (2), and execute (1). Here are some examples:
4 represents read permission.
2 represents write permission.
1 represents execute permission.
Examples:
To give read and write permission to the owner and read-only permission to the group and
others:
chmod 644 file.txt
To give full permissions (read, write, and execute) to the owner, and read-only permissions to
the group and others:
chmod 755 script.sh
Symbolic Notation:
In symbolic notation, you use letters and symbols to specify changes to the file permissions.
The notation includes the following components:
u for the owner.
g for the group.
o for others.
a for all (a combination of u, g, and o).
+ to add permissions.
- to remove permissions.
= to set permissions explicitly.
r for read.
w for write.
x for execute.
Examples:
To add write permissions for the owner and group, you can use:
chmod u+rw,g+rw file.txt
To remove execute permissions for the owner, group, and others, you can use:
chmod a-x file.sh
To set read-only permissions for the owner and group, you can use:
chmod u=r,g=r file.txt

Q.8 Define the file ownership using chown command ?


Ans. The chown command in Unix-like operating systems (including Linux) is used to
change the ownership of files and directories. Ownership of a file or directory is a crucial
aspect of file permissions and access control in the system. With chown, you can change the
user and group ownership of a file or directory, provided you have the necessary permissions
to do so.
Syntax:
chown [OPTIONS] USER[:GROUP] FILE...
USER is the new owner's username.
GROUP (optional) is the new group's name.
FILE... is the file or directory whose ownership you want to change. You can specify multiple
files or directories.
Common chown Options:
-R or --recursive: Change ownership recursively for directories and their contents.
--reference=REFERENCE_FILE: Set ownership to match that of the reference file.
Examples:
1 Change the owner of a file:

chown newowner file.txt


2 Change the owner and group of a file:
chown newowner:newgroup file.txt
3 Change ownership recursively for a directory and its contents:
chown -R newowner:newgroup directory/
4 Change the owner of a file to match the owner of a reference file:
chown --reference=reference_file target_file
-

The absence of a leading forward slash indicates that you are referring to a
directory relative to your current location.
Remember, the current directory is the directory you are currently located in. It
serves as a reference point for navigating to other directories.

Q.4- Define File related Commands – cat, cp, mv, rm, comm, cmp, diff, tar,
umask, wc with examples & Syntax?

Ans- 1. cat:
- The "cat" command is used to display the contents of a file.
- Syntax: cat [options] [file]
- Example: "cat file.txt" will display the contents of the file named
"file.txt".
2. cp:
- The "cp" command is used to copy files or directories.
- Syntax: cp [options] source destination
- Example: "cp file.txt newfile.txt" will create a copy of "file.txt" named
"newfile.txt".
3. mv:
- The "mv" command is used to move or rename files or directories.
- Syntax: mv [options] source destination
- Example: "mv file.txt folder/" will move the file "file.txt" to the
"folder" directory.
4. rm:
- The "rm" command is used to remove/delete files and directories.
- Syntax: rm [options] file/directory
- Example: "rm file.txt" will delete the file named "file.txt".
5. comm:
-

- The "comm" command is used to compare two sorted files line by line.
- Syntax: comm [options] file1 file2
Example: "comm file1.txt file2.txt" will compare the contents of "file1.txt"
and "file2.txt".

6. cmp:
- The "cmp" command is used to compare two files byte by byte.
- Syntax: cmp [options] file1 file2
- Example: "cmp file1.txt file2.txt" will compare the contents of
"file1.txt" and "file2.txt".
7. diff:
- The "diff" command is used to compare two files line by line and
display the differences.
- Syntax: diff [options] file1 file2
- Example: "diff file1.txt file2.txt" will show the differences between
"file1.txt" and "file2.txt".
8. tar:
- The "tar" command is used to create, view, or extract files from a tar
archive file.
- Syntax: tar [options] [archive-file] [files/directories]
- Example: "tar -cvf archive.tar file1.txt file2.txt" will create a tar
archive named
"archive.tar" containing "file1.txt" and "file2

Q.5- Listing seven attributes of a file: ls and its options define in details?
Ans- 1. -l (long format):
- This option displays detailed information about files and directories,
including permissions, owner, size, and modification time.
- Example: "ls -l" will display files and directories in long format.
-

2. -a (all files):
- This option shows all files, including hidden files that start with a dot
(.)
- Example: "ls -a" will display all files, including hidden files.
3. -h (human-readable):
This option displays file sizes in a human-readable format, such as "10K" or
"2G".
- Example: "ls -h" will display file sizes in a human-readable format.
4. -t (sort by time):
- This option sorts files and directories by modification time, with the
most recently modified ones first.
- Example: "ls -t" will display files and directories sorted by
modification time.
5. -r (reverse order):
- This option reverses the order of the file and directory listing.
- Example: "ls -r" will display files and directories in reverse order.
6. -S (sort by size):
- This option sorts files and directories by size, with the largest ones
first.
- Example: "ls -S" will display files and directories sorted by size.
7. -i (inode number):
- This option displays the inode number of each file and directory.
- Example: "ls -i" will display the inode number of files and directories.

Q.6- What is file permissions ? Explain Absolute and Relative permissions


of file with examples?
-

Ans- File permissions determine the level of access and actions that can be
performed on a file. There are two types of file permissions: absolute and
relative. 1. Absolute Permissions:
- Absolute permissions are represented by a series of numbers (0-7)
or letters (r, w, x).
- The numbers represent different levels of permission: 0 = no
permission, 1 = execute, 2 = write, 3 = write and execute, 4 = read, 5 =
read and execute, 6 = read and write, 7 = read, write, and execute.
- Example: "chmod 755 file.txt" sets absolute permissions on
"file.txt" as read, write, and execute for the owner, and read and execute
for the group and others.
2. Relative Permissions:
Relative permissions use symbols (+, -, =) to modify existing permissions.
- The plus sign (+) adds a permission, the minus sign (-) removes a
permission, and the equals sign (=) sets permissions explicitly.
- Example: "chmod +x file.txt" adds execute permission to "file.txt"
for the owner, group, and others.

Q.7- Explain the manipulation of file permission using chmod command?


Ans- The basic syntax of the `chmod` command is:
```chmod [options] mode file/directory```
Here, "mode" represents the permissions you want to set, and "file/directory" is
the target file or directory you want to modify.
1. Absolute Permissions:
Absolute permissions are represented by a three-digit number. Each digit
corresponds to a specific user or group: the owner, the group, and others. The
digits can range from 0 to 7, with each number representing a different level of
permission.
- 0: No permission
- 1: Execute permission
-

- 2: Write permission
- 3: Write and execute permission
- 4: Read permission
- 5: Read and execute permission
- 6: Read and write permission
- 7: Read, write, and execute permission
To set absolute permissions using `chmod`, you can use the numeric
representation. For example, to give the owner read, write, and execute
permissions, the group read and execute permissions, and others read-only
permissions, you would use the command:
``` chmod 751 file.txt ```
2. Symbolic Permissions:
Symbolic permissions use symbols to modify existing permissions. The
symbols used are:
- `+`: Adds the specified permission
- `-`: Removes the specified permission
- `=`: Sets the specified permission explicitly
To modify permissions using symbolic notation, you need to specify the user
or group you want to modify, followed by the symbol and the permission you
want to add or remove. For example, to add execute permission for the owner,
you can use the command:
``` chmod u+x file.txt ```
Here, `u` represents the owner, and `+x` adds the execute permission.
You can also use multiple symbols together. For example, to add read and
write permissions for the owner, and remove write permission for the group,
you can use:
``` chmod u+rw,g-w file.txt ```

Q.8- Define the file ownership using chown command ?


Ans- The basic syntax of the `chown` command is:
```chown [options] owner[:group] file/directory```
Here, "owner" represents the new owner of the file or directory, and "group"
represents the new group ownership. If the group ownership is not specified, it
will remain unchanged.
1. Changing Owner:
To change the owner of a file or directory using `chown`, you need to specify
the new owner's username or user ID. For example, to change the owner of a
file named "file.txt" to a user named "newowner", you would use the command:
``` chown newowner file.txt ```
You can also use the user ID instead of the username. To change the owner
using the user ID, you would use the command:
``` chown 1000 file.txt ```
2. Changing Group Ownership:
To change the group ownership of a file or directory using `chown`, you need
to specify the new group's name or group ID. For example, to change the group
ownership of a file named "file.txt" to a group named "newgroup", you would
use the command:
``` chown :newgroup file.txt ```
You can also use the group ID instead of the group name. To change the group
ownership using the group ID, you would use the command:
``` chown :1000 file.txt ```

If you want to change both the owner and group ownership of a file or
directory, you can specify both the owner and group separated by a colon. For
example, to change the owner to "newowner" and the group to "newgroup", you
would use the command:
``` chown newowner:newgroup file.txt ```
You can also use the user ID and group ID instead of the names. To change
both the owner and group ownership using the IDs, you would use the
command:
``` chown 1000:1000 file.txt ```

You might also like