Assignment 3 Pulkit SSL
Assignment 3 Pulkit SSL
Q.2- What are directories Related Command? Explain with Examples &
Syntax?
cd documents/project
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]...
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 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.
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.
- 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 ```
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 ```