0% found this document useful (0 votes)
5 views26 pages

Module 3 – System Access and File System

The document provides an overview of accessing Linux systems, including methods like SSH, RDP, and VNC, as well as instructions for downloading and installing PuTTY. It covers essential network commands, file system structure, navigation commands, and important Linux concepts such as file permissions and package management. Additionally, it explains the hierarchical nature of the Linux file system and the significance of components like inodes and superblocks.

Uploaded by

Gaurav Dubey
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)
5 views26 pages

Module 3 – System Access and File System

The document provides an overview of accessing Linux systems, including methods like SSH, RDP, and VNC, as well as instructions for downloading and installing PuTTY. It covers essential network commands, file system structure, navigation commands, and important Linux concepts such as file permissions and package management. Additionally, it explains the hierarchical nature of the Linux file system and the significance of components like inodes and superblocks.

Uploaded by

Gaurav Dubey
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/ 26

Module 3 – System Access and File System

 Accessing Linux system

To access a Linux system, you typically have a few options depending on your requirements:

1. Physical Access: If you have physical access to the system, you can interact with it
directly through a keyboard and monitor connected to the machine.

2. SSH (Secure Shell): If you're trying to access a remote Linux system, SSH is the most
common method. You'll need the IP address or domain name of the remote system, as well
as valid credentials (username and password or SSH keys). You can use a terminal
application on your local machine to connect via SSH, like so:

3. Remote Desktop Protocol (RDP): If the Linux system has a desktop environment
installed and RDP is configured, you can use an RDP client to access the desktop remotely.
However, this is less common for Linux systems compared to SSH.

4. Virtual Network Computing (VNC): Similar to RDP, VNC allows remote access to the
desktop environment of a Linux system. You need a VNC server running on the Linux
system and a VNC client on your local machine.

5. Serial Console Access: In some cases, especially with servers or embedded systems, you
may have access to the system via a serial console. This method is often used for
troubleshooting or initial setup.

6. Web-based Management Interfaces: Some Linux distributions come with web-based


management interfaces like Webmin or Cockpit, which allow you to manage the system
through a web browser.
 How to Download and install Putty

1. Download and run the latest version of the PuTTY installer (a .msi file). If you are
uncertain, you probably want the 64-bit version.

2. Click Next.

3. New Network Commands (ifconfig and ip)


4. Select Add shortcut to PuTTY on the Desktop and select will be installed on local
hard drive

5. Click Install

6. Click Finish.

7. On your desktop, double-click on the PuTTY icon to launch the program.


 New Network Commands (ifconfig and ip)
ifconfig in short “interface configuration” utility for system/network administration
in Unix/Linux operating systems to configure, manage, and query network interface
parameters via command-line interface or in a system configuration scripts.

The “ifconfig” command is used for displaying current network configuration information,
setting up an ip address, netmask, or broadcast address to a network interface, creating an
alias for the network interface, setting up hardware address, and enabling or disabling
network interfaces.

1. List Network Interfaces in Linux


The “ifconfig” command with no arguments will display all the active network interface
configuration details that includes their assigned IP addresses, netmasks, and other relevant
information.

$ ifconfig

2. Display Information on All Network Interfaces


The following ifconfig command with the -a argument will display information on all active
or inactive network interfaces on the server. It displays the results for eth0, lo, sit0, and tun0.

3. View Network Settings of Specific Interface


Using interface name (eth0) as an argument with the “ifconfig” command will display details
of the specific network interface.

4. How to Enable a Network Interface


The “up” or “ifup” flag with interface name (eth0) activates a network interface if it is not
inactive state and allows to send and receive information.

For example, “ifconfig eth0 up” or “ifup eth0” will activate the eth0 interface.

5. How to Disable a Network Interface


The “down” or “ifdown” flag with interface name (eth0) deactivates the specified network
interface. For example, the “ifconfig eth0 down” or “ifdown eth0” command deactivates
the eth0 interface if it is in an inactive state.

6. How to Assign an IP Address to Network Interface


To assign an IP address to a specific interface, use the following command with an interface
name (eth0) and ip address that you want to set. For example, “ifconfig eth0 172.16.25.125”
will set the IP address to interface eth0.

7. How to Assign a Netmask to Network Interface


Using the “ifconfig” command with the “netmask” argument and interface name as (eth0)
allows you to define a netmask to a given interface. For example, “ifconfig eth0 netmask
255.255.255.224” will set the network mask to a given interface eth0.
8. How to Assign a Broadcast to Network Interface
Using the “broadcast” argument with an interface name will set the broadcast address for the
given interface. For example, the “ifconfig eth0 broadcast 172.16.25.63” command sets the
broadcast address to an interface eth0.

9. How to Assign an IP, Netmask, and Broadcast to Network Interface


To assign an IP address, Netmask address, and Broadcast address all at once using the
“ifconfig” command with all arguments as given below.

10. How to Change MTU for a Network Interface


The “mtu” argument sets the maximum transmission unit to an interface. The MTU allows
you to set the limit size of packets that are transmitted on an interface. The MTU is able to
handle a maximum number of octets to an interface in one single transaction.

11. How to Enable Promiscuous Mode


What happens in normal mode, is when a packet is received by a network card, it verifies
that it belongs to itself. If not, it drops the packet normally, but in the promiscuous mode is
used to accept all the packets that flow through the network card.

12. How to Disable Promiscuous Mode|


To disable promiscuous mode, use the “-promisc” switch that drops back the network
interface to normal mode.

13. How to Add New Alias to Network Interface


The ifconfig utility allows you to configure additional network interfaces using
the alias feature. To add the alias network interface of eth0, use the following command.
Please note that the alias network address is in the same subnet mask. For example, if
your eth0 network ip address is 172.16.25.125, then the alias ip address must
be 172.16.25.127.

14. How to Remove Alias to Network Interface


If you no longer required an alias network interface or you incorrectly configured it, you can
remove it by using the following command.

15. How to Change the MAC address of Network Interface


To change the MAC (Media Access Control) address of an eth0 network interface, use the
following command with the argument “hw ether“. For example, see below.
 How to Connect to a Linux VM using Putty
1. Start PuTTy.
2. Fill in the host name or IP address of your VM from the Azure portal:

3. Before selecting Open, click Connection > SSH > Auth tab. Browse to and select your
PuTTY private key (.ppk file):

4. Click Open to connect to your VM.


 Important things to remember in Linux
In Linux, there are several important things to remember to ensure smooth and efficient
operation:

1. File System Hierarchy: Understand the directory structure (root directory "/", bin, etc.),
as it forms the basis of Linux organization.

2. File Permissions: Learn about the file permission system (read, write, execute) and how
to change them using commands like chmod.

3. Package Management: Familiarize yourself with the package manager of your


distribution (apt, yum, pacman, etc.) for installing, updating, and removing software.

4. Command Line Basics: Learn essential command line operations such as navigating
directories, creating, copying, moving, and deleting files and directories.

5. System Processes: Understand how to manage processes with commands like ps, top, kill,
and systemctl to monitor and control system resources.

6. User and Group Management: Learn how to add, remove, and modify users and groups
using commands like useradd, usermod, groupadd, and groupmod.

7. Networking: Familiarize yourself with networking commands like ifconfig, ip, ping, and
traceroute for configuring and troubleshooting network connections.

8. System Logs: Know where system logs are stored (/var/log/) and how to view them using
commands like tail, less, and grep to troubleshoot issues.

9. File System Maintenance: Regularly perform tasks like disk space monitoring, file
system checks and disk defragmentation (if applicable) to keep the system running smoothly.

10. Backup and Restor: Implement a backup strategy to protect against data loss, using
tools like rsync, tar, and backup utilities provided by your distribution.

11. Security Practices: Follow security best practices such as keeping the system up-to-date
with security patches, using firewalls, configuring sudo access carefully, and disabling
unnecessary services.

12. Shell Scripting: Learn shell scripting (bash, sh) to automate tasks and improve
efficiency in managing the system.

13. Documentation: Document configurations, changes, and troubleshooting steps to


facilitate future maintenance and collaboration.

Remember, Linux is a powerful and versatile operating system, and mastering these basics
will provide a strong foundation for efficient usage and administration.
 Introduction to File System

What is a File System?


In computing, a file system is a method and data structure used by operating systems to
store, retrieve, and organize files on a storage device like a hard drive or SSD. It provides a
logical way to access and manage data stored on the storage medium.

Key Components of a File System:

1. Directories (Folders): Directories are like containers for files and other directories. They
help in organizing and structuring the file system hierarchy. In Linux, directories are
represented by paths such as "/home/user/Documents", where "/" represents the root
directory.

2. Files: Files are the basic units of data storage in a file system. They can contain text,
programs, images, videos, or any other type of data. In Linux, files can have various
permissions (read, write, execute) and attributes associated with them.

3. Inodes: Inodes are data structures used by the file system to store metadata about files and
directories, such as file permissions, ownership, timestamps, and pointers to the actual data
blocks on the disk.

4. Superblock: The superblock is a critical data structure at the beginning of a file system
that contains metadata about the entire file system, including its size, status, and other
essential information.

5. Data Blocks: Data blocks are the actual units of storage on the disk where file contents
are stored. These blocks are linked together through pointers in the inode to form the
complete file.

Common File Systems in Linux:

1. Ext4: The Extended File System 4 (ext4) is the default file system for most Linux
distributions. It provides improvements over its predecessor, ext3, including larger file sizes,
faster file system checks, and better performance.

2. XFS: XFS is a high-performance journaling file system known for its scalability and
reliability. It's commonly used in enterprise environments and for large-scale storage
systems.

3. Btrfs: Btrfs (B-tree file system) is a modern file system that supports features like
snapshotting, checksums, and built-in RAID support. It's designed to be more flexible and
scalable than traditional file systems.

4. ZFS: While not as commonly used on Linux as on other operating systems like FreeBSD,
ZFS (Zettabyte File System) is a robust and feature-rich file system known for its data
integrity, volume management, and snapshot capabilities.
File System Hierarchy in Linux:

Linux follows a hierarchical file system structure with a root directory ("/") at the top. Here
are some key directories commonly found in the Linux file system:

- /bin: Essential user binaries (commands) used by all users.


- /boot: Boot loader files and Linux kernel.
- /dev: Device files representing hardware devices.
- /etc: System configuration files.
- /home: Home directories for regular users.
- /lib and /lib64: Shared libraries used by programs.
- /proc: Virtual file system providing information about system processes.
- /sys: Virtual file system providing information about the kernel and hardware.
- /tmp: Temporary files.
- /usr: User programs and data.
- /var: Variable files such as logs, spool files, and temporary files.
 File System Structure Description
File System provide efficient access to the disk by allowing data to be stored, located and
retrieved in a convenient way. A file System must be able to store the file, locate the file and
retrieve the file.

Most of the Operating Systems use layering approach for every task including file systems.
Every layer of the file system is responsible for some activities.

The image shown below, elaborates how the file system is divided in different layers, and
also the functionality of each layer.

o When an application program asks for a file, the first request is directed to the logical
file system. The logical file system contains the Meta data of the file and directory
structure. If the application program doesn't have the required permissions of the file
then this layer will throw an error. Logical file systems also verify the path to the file.
o Generally, files are divided into various logical blocks. Files are to be stored in the
hard disk and to be retrieved from the hard disk. Hard disk is divided into various
tracks and sectors. Therefore, in order to store and retrieve the files, the logical blocks
need to be mapped to physical blocks. This mapping is done by File organization
module. It is also responsible for free space management.
o Once File organization module decided which physical block the application program
needs, it passes this information to basic file system. The basic file system is
responsible for issuing the commands to I/O control in order to fetch those blocks.
o I/O controls contain the codes by using which it can access hard disk. These codes are
known as device drivers. I/O controls are also responsible for handling interrupts.
 File system navigation commands
Here are some common file system navigation commands:

1. cd (Change Directory): This command is used to change the current working directory.
You can use it to navigate to different directories in the file system. For example:

cd directory_name

2. ls (List): This command is used to list the contents of a directory. When used without
arguments, it lists the files and directories in the current directory. For example:

ls

3. pwd (Print Working Directory): This command displays the path of the current working
directory. For example:

pwd

4. mkdir (Make Directory): This command is used to create a new directory. For example:

mkdir new_directory

5. rmdir (Remove Directory): This command is used to remove a directory. Note that the
directory must be empty for this command to work. For example:

rmdir directory_to_remove

6. rm (Remove): This command is used to remove files or directories. Use with caution as it
permanently deletes files and directories. For example:

rm file_to_remove

7. cp (Copy): This command is used to copy files or directories. For example:

cp source_file destination_file

8. mv (Move): This command is used to move files or directories. It can also be used to
rename files or directories. For example:

mv old_file new_file

9. touch: This command is used to create an empty file or update the timestamp of an
existing file. For example:

touch filename
 File System Paths
In Linux, file system paths are structured hierarchically, starting from the root directory `/`.
Here are some key points about file system paths in Linux:

1. Root Directory: Denoted by `/`, it's the top-level directory in the file system hierarchy.
All other directories and files are located under it.

2. Absolute Paths: These paths start from the root directory.

For example:
- `/home/username/Documents/file.txt`
- `/var/log/syslog`
- `/usr/bin/bash`

3. Relative Paths: These paths specify the location of a file or directory relative to the
current working directory.

For example:
- If you are currently in `/home/username/`, to refer to the `Documents` directory, you can
simply use `Documents`.
- To refer to a file `example.txt` in the current directory, you can use `./example.txt`.
- To refer to a directory one level up from the current directory, you can use `../`.

4. Special Directories:

- `.` (dot): Represents the current directory.


- `..` (dot dot): Represents the parent directory.
- `/` (slash): Represents the root directory.
- `~` (tilde): Represents the home directory of the current user.

5. Path Separators: In Linux, paths are separated by forward slashes `/`.

6. Case Sensitivity: File and directory names in Linux are case-sensitive. For example,
`Documents` and `documents` are considered two different directories.

7. Absolute Path Resolution: Linux resolves absolute paths starting from the root directory
`/`. Each directory in the path specifies the next level in the hierarchy until the final file or
directory is reached.
 Directory listing overview
In Linux, the `ls` command is used to list directory contents. It's a fundamental command
for navigating the file system and inspecting files and directories. Here's an overview of
its usage and some common options:

1. Basic Usage: The basic syntax of the `ls` command is:

ls [options] [file(s) or directory]

2. List Contents of Current Directory: Running `ls` without any arguments lists the
contents of the current directory.

ls

3. List Specific Directory: You can specify the directory whose contents you want to list.

ls /path/to/directory

4. List Hidden Files: By default, `ls` does not list files and directories whose names start
with a dot (hidden files). To include them, use the `-a` or `--all` option.

ls -a

5. List with Long Format: The `-l` option displays detailed information about files and
directories in long format, including permissions, ownership, size, and modification time.

ls -l

6. List All Files with Human-readable File Sizes: The `-lh` option combines the `-l` and `-
h` options to display file sizes in a human-readable format (e.g., KB, MB, GB).

ls -lh

7. Sort by Modification Time: The `-t` option sorts files and directories by modification
time, with the most recently modified first.

ls -lt

8. Sort by Size: The `-S` option sorts files by size, with the largest files first.

ls -lS

9. List Subdirectories Recursively: The `-R` option lists the contents of directories
recursively.

ls -R

10. List with Colorized Output: Many Linux distributions alias `ls` to `ls --color=auto` by
default, which colorizes the output to distinguish between file types and permissions.
 Creating Files and Directories
In Linux, you can create files and directories using various commands, such as `touch`,
`mkdir`, and `echo`. Here's how you can use these commands to create files and directories:

1. Creating Files:

a. Using `touch`: The `touch` command is primarily used to update the timestamps of
files, but it can also be used to create new empty files.

touch filename.txt

b. Using `echo`: You can use `echo` along with redirection to create a new file with
content.

echo "Hello, world!" > filename.txt

c. Using text editors: Text editors like `nano`, `vim`, or `emacs` allow you to create and
edit files interactively.

nano filename.txt

2. Creating Directories:

a. Using `mkdir`: The `mkdir` command is used to create directories.

mkdir directory_name

b. Creating nested directories: You can create directories with parent directories if they
don't exist using the `-p` option.

mkdir -p parent_directory/child_directory

3. Creating Multiple Files/Directories:

a. Using brace expansion: Brace expansion allows you to quickly create multiple files or
directories with similar names.

touch file{1..5}.txt

This command will create files named `file1.txt`, `file2.txt`, ..., `file5.txt`.

b. Using loops: You can also use loops in shell scripting to create multiple files or
directories

for i in {1..5}; do touch file$i.txt; done

This command will create files named `file1.txt`, `file2.txt`, ..., `file5.txt`.
 Types of File in Linux

1 — Regular File

starting with ‘-‘. text, data, or executable files.

2 — Directory

Starting with ‘d’. Folder, Directory.

3 — Link

Starting with ‘l’. A shortcut that points to the location of the actual file

4 — Special File

Starting with ‘c’. Mechanism used for input and output, such as files in /dev

5 — Block Disk

Any kinds of dis, it will be read as block disk.

6 — Pipe & Socket & Link

Pipe: A pipe is a form of interprocess communication (IPC) in Unix-like OS.

It allows data to flow between two processes, enabling them to communicate

Socket: another form of IPC used for communication between processes over a network

Link: A special type of file that acts as a pointer to another file or directory.
 Finding Files and Directories (find, locate)
Finding files and directories on a Unix/Linux system can be done using various commands,
primarily `find` and `locate`.

`find` Command:

`find` searches for files in a directory hierarchy based on various criteria like name, type,
size, etc.

Syntax:

find [path...] [expression]

Examples:

1. To find all files with a specific name in the current directory:

find . -name "filename"

2. To find all directories with a specific name in the current directory:

find . -type d -name "dirname"

3. To find files modified within the last 7 days:

find . -mtime -7

4. To find files larger than 10MB:

find . -size +10M

`locate` Command:

`locate` searches a pre-built database of files and directories for the specified pattern.

Syntax:

locate [pattern]

Examples:

1. To find all files containing "example" in their name:

locate example

2. To find the location of the executable file `python`:

locate bin/python
Comparison:

- `find` searches the file system in real-time, so it's more flexible but can be slower,
especially on large file systems.

- `locate` searches a pre-built database, so it's faster but may not have the most up-to-date
information.
 Difference between find and locate command

The find Linux command is a staple on all Linux distros and always included by default. It
searches for files based on a large number of parameters, allowing you to perform a very
granular search. You can find files based on their name, size, owner, modified date, and
other options.

find searches for files in real time, meaning that it will crawl the specified directory for your
search query when you execute it. On large file systems with deep subdirectories, these
searches can take some time, especially on a slow computer or old style hard drive disk. A
solid state drive and shallower directory depth will yield faster results.

find proves useful in a multitude of situations, and can even execute commands on the files
that it returns in its search results. It also accepts regex syntax and can pipe to xargs to do
some slick and fast file manipulation across tons of directories scattered on your file system.

The locate command is not as well known as find and is often not included as a default
command on Linux distros, although it can easily be installed via package manager. It can’t
perform as granular of a search, as it simply matches files based on their name, although it
does accept complicated syntax such as regex.

locate creates a database of files on your system, along with their locations, and then
searches that database for a match, rather than actually scanning your hard drive for
matching files in real time. This allows locate to produce very fast results, so it can
effectively search the entire file system for a matching file in just a few seconds.

Since locate uses a database, and this database is not updated all the time, the command can’t
find files that were recently created. The user can run updatedb to manually update
the locate database, or wait about a day for the database to be updated automatically in the
background.

Pros and Cons


In most situations, it will be pretty clear whether the locate or find command will be a
superior choice. Take a look at the table of pros and cons below to get some quick
information about which tool is better across certain categories.
Category find locate

Fast for shallow directory


Lightning fast at searching
Speed structures, but can be slow for
the entire hard drive
deeper ones

Accepts many parameters like


Only searches based on the
Granularity name, size, owner, modified
file name
time, etc.

Dead simple syntax, just


More complicated syntax and
Simplicity specify the name or part of
requires more arguments
the name of the file

Best suited for granular Best suited for quickly


Purpose searches that require multiple finding a file or directory
parameters based on the name

Can delete files, execute


Extended Simply returns the location
commands on files, pipe
Use of a file or directory
to xargs, etc.

Installed by default on Linux, Usually needs to be installed


Availability
nothing to download via system package manager

Searches any specified Must log the file in its


Usability directory and subdirectories in database in order to search
real time for it

 How to Changing Password


Linux system administrators frequently have to handle user accounts and the passwords that
are associated with them. As an administrator or someone with the right permissions, you
might occasionally need to modify the password for another user. Through Linux's command
line, this is simple to complete.
Step - 1: Open the Terminal

To begin, open a terminal on your Linux system. The terminal is a command line interface
that allows you to interact with the operating system using text-based commands. You can
usually find the terminal application in the applications menu or by using the keyboard
shortcut Ctrl + Alt + T.

Step - 2: Switch to the Root User

To change another user's password, you'll need administrative privileges. In Linux, the root
user has the highest level of administrative access. To switch to the root user, type the
following command and press Enter:

$ sudo su

You will be prompted to enter the password for the current user account. Enter your
password and press Enter.

Step - 3: Run the 'passwd' Command

Once you are logged in as the root user, type the following command and press Enter:

$ passwd username

Replace "username" with the actual username of the user whose password you want to
change.

Step - 4: Enter the New Password

After running the passwd command, you'll be prompted to enter a new password for the
specified user. Type the new password and press Enter. It's important to choose a strong
password that meets the system's requirements.

Step - 5: Confirm the New Password

After entering the new password, you'll be asked to re-enter it for confirmation. Type the
new password again and press Enter. Make sure both entries match exactly to avoid any
mistakes.

Step - 6: Password Changed Successfully

If the new password meets the system's requirements, you will see a success message
indicating that the user's password has been changed. Congratulations! You have
successfully changed another user's password in Linux.

Step - 7: Exit the Root User


After you have finished changing the user's password, it's good practice to exit the root user
and return to your regular user account. To do this, type the following command and press
Enter:

exit

 Wildcard
In Linux, wildcards are characters that represent patterns of filenames or text strings. They're
used in commands such as `ls`, `cp`, `mv`, and `rm` to specify groups of files or directories
that match certain criteria. Here are some common wildcards:

1. `*` (Asterisk): Represents zero or more characters.


- Example: `*.txt` matches all files with the `.txt` extension.

- Example: `file*.txt` matches all files that start with "file" and end with ".txt".

2. `?` (Question Mark): Represents a single character.

- Example: `file?.txt` matches files like `file1.txt`, `fileA.txt`, but not `file12.txt`.

3. `[ ]` (Square Brackets): Matches any one character enclosed within the brackets.

- Example: `file[123].txt` matches `file1.txt`, `file2.txt`, or `file3.txt`.

- Example: `file[a-z].txt` matches `filea.txt`, `fileb.txt`, ..., `filez.txt`.

4. `{ }` (Curly Braces): Matches any one of the comma-separated patterns inside the braces.

- Example: `file{1,2,3}.txt` matches `file1.txt`, `file2.txt`, or `file3.txt`.

- Example: `file{.txt,.doc}` matches `file.txt` or `file.doc`.

5. `$` (Dollar Sign): In regular expressions, it represents the end of a line.

6. `^` (Caret): In regular expressions, it represents the start of a line.

Soft and Hard links in Unix/Linux

1. Soft Links

 A soft link is similar to the file shortcut feature which is used in Windows Operating
systems. Each soft linked file contains a separate Inode value that points to the original
file. As similar to hard links, any changes to the data in either file is reflected in the
other. Soft links can be linked across different file systems, although if the original file is
deleted or moved, the soft linked file will not work correctly (called hanging link).
 ls -l command shows all links with first column value l? and the link points to original
file.
 Soft Link contains the path for original file and not the contents.
 Removing soft link doesn’t affect anything but removing original file, the link becomes
“dangling” link which points to nonexistent file.
 A soft link can link to a directory.
 The size of the soft link is equal to the length of the path of the original file we gave. E.g
if we link a file like ln -s /tmp/hello.txt /tmp/link.txt then the size of the file will be
14bytes which is equal to the length of the “/tmp/hello.txt”.
 If we change the name of the original file then all the soft links for that file become
dangling i.e. they are worthless now.
 Link across file systems: If you want to link files across the file systems, you can only
use symlinks/soft links.

Command to create a Soft link is:


$ ln -s [original filename] [link name]

2. Hard Links

 Each hard linked file is assigned the same Inode value as the original, therefore they
reference the same physical file location. Hard links more flexible and remain linked
even if the original or linked files are moved throughout the file system, although hard
links are unable to cross different file systems.
 ls -l command shows all the links with the link column shows number of links.
 Links have actual file contents
 Removing any link, just reduces the link count, but doesn’t affect other links.
 Even if we change the filename of the original file then also the hard links properly work.
 We cannot create a hard link for a directory to avoid recursive loops.
 If original file is removed then the link will still show the content of the file.
 The size of any of the hard link file is same as the original file and if we change the
content in any of the hard links then size of all hard link files are updated.
 The disadvantage of hard links is that it cannot be created for files on different file
systems and it cannot be created for special files or directories.

Command to create a hard link is:


$ ln [original filename] [link name]

 How to open image file through GUI


Opening an image file through a GUI on Linux can be achieved using various toolkits and
programming languages. One popular choice is using Python with Tkinter as the GUI toolkit,
as I showed in the previous example. Here's how you can do it on Linux:
1. Install Tkinter: On most Linux distributions, Tkinter should be pre-installed. If not, you
can install it using your package manager. For example, on Ubuntu or Debian-based
systems, you can install it with:

bash

sudo apt-get install python3-tk

2. Write the Python script: Use a text editor to create a Python script with the following
code, which is similar to the previous example:

python

import tkinter as tk

from tkinter import filedialog

from PIL import Image, ImageTk

def open_image():

file_path = filedialog.askopenfilename(filetypes=[("Image files",


"*.jpg;*.jpeg;*.png;*.gif")])

if file_path:

image = Image.open(file_path)

image.thumbnail((300, 300)) # Resize image to fit within a 300x300 box

photo = ImageTk.PhotoImage(image)

label.config(image=photo)

label.image = photo

# Create the main window

root = tk.Tk()

root.title("Image Viewer")

# Create a label to display the image

label = tk.Label(root)

label.pack()

# Create a button to open the image


open_button = tk.Button(root, text="Open Image", command=open_image)

open_button.pack()

# Run the Tkinter event loop

root.mainloop()

3. Make the script executable (optional): You can make the Python script executable by
adding a shebang line at the beginning of the file and setting the execute permission:

bash

chmod +x your_script.py

4. Run the script: Simply run the script from the terminal:

bash

python3 your_script.py

This will launch the Tkinter window with a button to open an image file. When you click the
button, a file dialog will appear where you can select an image file to open and display in the
window.

You might also like