0% found this document useful (0 votes)
7 views8 pages

Exp Linux

The document outlines laboratory experiments for a Linux Programming course, focusing on commands for compressing, decompressing, and managing file permissions. It details commands like gzip, gunzip, zip, tar, chmod, chown, and chgrp, along with their syntax and common options. Additionally, it includes practical scenarios for applying these commands to secure access control and manage file permissions effectively.
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)
7 views8 pages

Exp Linux

The document outlines laboratory experiments for a Linux Programming course, focusing on commands for compressing, decompressing, and managing file permissions. It details commands like gzip, gunzip, zip, tar, chmod, chown, and chgrp, along with their syntax and common options. Additionally, it includes practical scenarios for applying these commands to secure access control and manage file permissions effectively.
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/ 8

DEPARTMENT OF COMPUTER ENGINEERING

Subject: BLP (Linux Programming) Subject Code:312002


Semester:2nd Semester Course: Computer Engineering
Laboratory No: V118 Name of Subject Teacher: Mrs. Sneha Patange

Name : Vidya Subodh Kurhade Semester: 2nd


Roll No: 24203A0043 Year:
Department: CO Batch: 2

Experiment No: 6&7


Title of Experiment Execute Linux commands for compressing, decompressing, and archiving
files.
Change file and directory permissions.

Linux commands for compressing, decompressing, and archiving files.


gzip Command in Linux
The gzip command is used for compressing files in Linux. It reduces the size of files using Lempel-
Ziv coding (LZ77), making them more efficient for storage or transfer.
Syntax:
gzip [options] [filenames]
Common Options:
Option Description
-d Decompress a compressed file (gunzip is also used)
-k Keep the original file while compressing
-r Compress files recursively (used for directories)
-l Display compression details (original size, compressed size, ratio, etc.)
-v Show compression details during execution (verbose mode)
-t Test integrity of compressed files
-f Force compression even if the file already exists
Compression level (1-9), where -1 is fastest but less compression, and -9 is slowest but
-#
highest compression

The gunzip command in Linux is used to decompress files that have been compressed using the
gzip command. It restores the file to its original state before compression.

Syntax:
gunzip [OPTION] [archive name/file name]
DEPARTMENT OF COMPUTER ENGINEERING

Common Options:
-c : Writes the decompressed output to standard output (stdout) without deleting the original
compressed file.
-d : Explicitly decompresses the file (this is the default behavior).
-f : Forces decompression, even if a file with the same name exists.
-k : Keeps the original compressed file instead of deleting it.
-l : Lists information about the compressed file (e.g., size before/after compression).
-r : Recursively decompresses all .gz files in a directory.
-v : Displays the name and size of the decompressed file.

ZIP Command in Linux with Example


The zip command in Linux is used to compress files and directories into a .zip archive file.

Syntax:
zip [options] zipfile_name files_to_zip

Common Options:
Option Description
-r Compress directories recursively
-e Encrypt the zip file with a password
-v Show detailed output
-q Quiet mode (no output)
-d Delete files from the zip archive
-u Update existing zip archive

The tar command in Linux is used to create, extract, and manage archive files. It stands for "Tape
Archive" and is commonly used to group multiple files or directories into a single archive file.

Syntax:
tar [OPTIONS] [ARCHIVE-FILE] [FILES OR DIRECTORIES]

Common Options in tar Command:


Option Description
-c Create a new archive.
-x Extract an archive.
-v Verbose mode (shows progress).
-f Specifies the filename of the archive.
-z Compress the archive using gzip.
-j Compress the archive using bzip2.
-J Compress the archive using xz.
DEPARTMENT OF COMPUTER ENGINEERING

-r Append files to an existing archive.


-t List contents of an archive.

List Command (List Files and Directories)


Option Description

-l Long listing format (shows permissions, ownership, size, etc.)

-ld Show details of directories themselves, not their contents

chmod Command (Change File Permissions)

Option Description

u User (owner)

g Group

o Others (everyone else)


DEPARTMENT OF COMPUTER ENGINEERING

a All (user, group, others)

r Read permission

w Write permission

x Execute permission

+ Add permission

Here’s a table for adding permissions using chmod:


Command Description
chmod u+r filename Add read (r) permission for the user (owner)
chmod u+w filename Add write (w) permission for the user (owner)
chmod u+x filename Add execute (x) permission for the user (owner)
chmod g+r filename Add read (r) permission for the group
chmod g+w filename Add write (w) permission for the group
chmod g+x filename Add execute (x) permission for the group
chmod o+r filename Add read (r) permission for others
chmod o+w filename Add write (w) permission for others
chmod o+x filename Add execute (x) permission for others
chmod a+r filename Add read (r) permission for all (user, group, others)
chmod a+w filename Add write (w) permission for all
chmod a+x filename Add execute (x) permission for all
chmod u+rwx Grant full (read, write, execute) permission to the
DEPARTMENT OF COMPUTER ENGINEERING

filename owner
chmod a+rx filename Allow all users to read and execute the file
- Remove permission

Here’s a table for removing permissions using chmod:


Command Description
chmod u-r filename Remove read (r) permission for the user (owner)
chmod u-w filename Remove write (w) permission for the user (owner)
chmod u-x filename Remove execute (x) permission for the user (owner)
chmod g-r filename Remove read (r) permission for the group
chmod g-w filename Remove write (w) permission for the group
chmod g-x filename Remove execute (x) permission for the group
chmod o-r filename Remove read (r) permission for others
chmod o-w filename Remove write (w) permission for others
chmod o-x filename Remove execute (x) permission for others
chmod a-r filename Remove read (r) permission for all (user, group,
others)
chmod a-w filename Remove write (w) permission for all
chmod a-x filename Remove execute (x) permission for all
chmod u-rwx Remove all (read, write, execute) permissions for the
filename owner
chmod a-rx filename Remove read and execute permissions for all
= Set exact permissions

chmod o=rw file.txt


### Numeric mode (e.g., chmod 600 file sets owner RW, no permissions for
group/others)

chown Command (Change File Owner)


Option Description

user:group Change owner and group (e.g., chown john:developers file.txt)

--recursive (-R) Apply changes recursively to all files in a directory

chmod -R 755 directory1

chgrp Command (Change Group Ownership)


Option Description

groupname Change the group of a file (e.g., chgrp developers file.txt)


DEPARTMENT OF COMPUTER ENGINEERING

-R Change group recursively for all files in a directory

Questions:
1 Secure Access Control for HR Documents

Scenario: You are the system administrator of an HR department managing confidential


employee data. The file salary_records.csv must be accessible only to the HR head and
should not be read, written, or executed by anyone else.
🔸 Task:
 Use the appropriate command to restrict access so that only the HR head (file
owner) can read and write the file.
 Verify the changes by listing the file permissions.

chmod 600 salary_records.csv

🔹 Explanation:
 6 → Owner can read (r) and write (w) (rw-).
 0 → Group has no permissions (---).
 0 → Others have no permissions (---).

ls -l salary_records.csv

2 Managing Project Files for a Software Development Team


Scenario: The dev_team is working on a project, and all files in /home/projects/app/ must
be assigned to the developers group so that all team members can access them.
🔸 Task:
 Change the group ownership of all files in /home/projects/app/ to developers.
 Ensure that future files created in this directory automatically inherit the
developers group.

To assign all files in /home/projects/app/ to the developers group, use:


chown :developers /home/projects/app/*
🔹 Explanation:
 chown → Changes ownership.
 :developers → Changes only the group to developers.
 /home/projects/app/* → Applies changes to all files in the directory.

To automatically assign the developers group to newly created files, set the SGID (Set
Group ID) bit on the directory:
bash
DEPARTMENT OF COMPUTER ENGINEERING

CopyEdit
chmod g+s /home/projects/app/
🔹 Explanation:
 g+s → Enables SGID, ensuring that all new files created in /home/projects/app/
inherit the developers group.

ask 3: Verify the Changes


Check the group ownership and permissions:
ls -l /home/projects/app/

-rw-r--r-- 1 user developers 1234 Feb 8 11:00 file1.py


-rw-r--r-- 1 user developers 5678 Feb 8 11:05 file2.js

3 Securing Web Server Logs


Scenario: A web server generates logs in /var/log/webserver/, but these logs should only
be accessed by the system administrators and not by regular users.
🔸 Task:
 Modify the permissions of /var/log/webserver/ so that only system administrators
can access them.
 List and verify the new permissions.

hange the group ownership to admin (or sysadmin if applicable)

chown :admin /var/log/webserver/

Explanation:

admin → Changes only the group ownership to admin.


/var/log/webserver/ → Affects the directory and its files.

chmod 750 /var/log/webserver/

xplanation:
 7 (Owner) → Full permissions (Read, Write, Execute).
 5 (Group) → Read & Execute (Admins can access but not modify).
 0 (Others) → No access for regular users.

ls -ld /var/log/webserver/
DEPARTMENT OF COMPUTER ENGINEERING

4 File Listing and Disk Space Optimization in a Media Company


Scenario: A media company is running out of disk space. The IT team needs to identify
large files in the /media/ directory to archive or delete them.
🔸 Task:
 List all files in /media/ sorted by size (largest first).
 Save the list to large_files_report.txt for review.

Conclusion:

Marks Obtained Dated signature of


Teacher
Process Related(10) Product Related(15) Total Marks(25)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy