Linux Unit2
Linux Unit2
2024/04/08 1
Linux
2.Basic of Linux
• Linux Commands:
1. ls (List): List files and directories in the current directory.
Example: ls –l (Long format listing), ls –a (List hidden files),
ls /path/to/directory (List files in a specific directory)
2
Linux
• Linux Commands:
3
Linux
• Linux Commands:
4
Linux
• Linux Commands:
5
Linux
Shell
Shells are command-line interfaces (CLIs) or command interpreters in Linux and Unix-like
operating systems. They provide users with a way to interact with the system by entering
commands and scripts. Each shell has its own features and syntax.
Three popular shells in Linux:
1. Cch (C Shell):
• History: Csh was developed by Bill Joy at the University of California, Berkeley, in the late 1970s.
It was designed to resemble the C programming language syntax.
• Features:
• C-like syntax: Csh uses a syntax similar to the C programming language, which may be more
familiar to programmers with a C background.
• History substitution: Csh provides the ability to recall and reuse previous commands using
history substitution.
• Scripting capabilities: While not as popular as Bash for scripting, Csh can be used for writing
shell scripts.
• Use Cases: Csh is less commonly used today as a default interactive shell but may still be found
on some systems. It's mostly used by those who are already familiar with it or for maintaining
legacy scripts. 6
Linux
Shell
2. Ksh (Korn Shell):
• History: Ksh was developed by David Korn at AT&T Bell Laboratories in the early 1980s.
It was designed as an improved version of the original Unix shell (sh).
• Features:
• Rich scripting: Ksh is known for its powerful scripting capabilities, making it a popular
choice for writing complex shell scripts.
• Command-line editing: Ksh offers advanced command-line editing features, including
vi and emacs modes.
• Job control: Ksh provides extensive job control features for managing and
manipulating background and foreground processes.
• Use Cases: Ksh is often used by system administrators and script developers due to its
scripting capabilities and extended features.
7
Linux
Shell
3. Bash (Bourne-Again Shell):
•History: Bash, as the name suggests, is an evolution of the Bourne Shell (sh), which was the
original Unix shell. It was created by Brian Fox for the GNU Project in 1989.
•Features:
•Wide adoption: Bash is the default shell on most Linux distributions and macOS, making
it one of the most widely used shells.
•Scripting: Bash is highly regarded for its scripting capabilities and is the go-to choice for
writing shell scripts.
•Command-line editing: Bash provides intuitive command-line editing with features like
history recall, tab completion, and more.
•Extensibility: Users can customize their Bash environment with aliases, functions, and
configuration files like .bashrc.
•Use Cases: Bash is the most commonly used shell for interactive sessions, scripting, and
automation tasks on Linux and Unix systems. It is versatile and well-documented, making it
a great choice for users of all levels.
8
Linux
Shell
Differences
9
Linux
10
Linux
Text Editors
Text editors are essential tools for creating and editing text files in a variety of environments, including
the command line. Here are detailed explanations of three popular text editors: Vim, Pico, and Nano.
2. Pico:
•Description: Pico is a simple and user-friendly text editor that is part of the
Pine email client suite. It's designed for basic text editing tasks and is
characterized by its straightforward and minimalistic interface.
•How to Use:
•To open a file with Pico: pico filename
•Navigation: Use arrow keys to move around the text.
•Editing: Simply start typing to add or modify text.
•Saving and quitting:
•Press Ctrl + O to save changes.
•Press Ctrl + X to exit Pico.
•Use Cases:
•Pico is an excellent choice for beginners or those who prefer a
straightforward and intuitive text editor.
•It's suitable for quick edits, composing emails, or making simple changes
to text files.
12
Linux
3. Nano:
•Description: Nano is a user-friendly and easy-to-use text editor known for its
simplicity and accessibility. It provides a simple interface for basic text editing
tasks without the complexity of more advanced editors like Vim.
•How to Use:
•To open a file with Nano: nano filename
•Navigation: Use arrow keys to move the cursor.
•Editing: Start typing to add or modify text.
•Saving and quitting:
•Press Ctrl + O to save changes.
•Press Ctrl + X to exit Nano.
•Use Cases:
•Nano is suitable for users who want a straightforward text editor without
the need to learn extensive commands.
•It's useful for quick text edits, viewing files, or performing simple text-
related tasks.
13
Linux
• Linux file system has a hierarchal file structure as it contains a root directory and its
subdirectories. All other directories can be accessed from the root directory. A partition
usually has only one file system, but it may have more than one file system.
• A file system is designed in a way so that it can manage and provide space for non-volatile
storage data. All file systems required a namespace that is a naming and organizational
methodology. The namespace defines the naming process, length of the file name, or a
subset of characters that can be used for the file name. It also defines the logical structure
of files on a memory segment, such as the use of directories for organizing the specific files.
Once a namespace is described, a Metadata description must be defined for that particular
file.
14
Linux
15
Linux
•/boot: Contains boot loader files, including the Linux kernel and related boot files.
•/etc: Stores configuration files for the system and various programs.
•/home: User home directories, where individual users store their files and personal settings.
•/root: The home directory for the root (administrative) user.
•/opt: Contains third-party applications, usually not managed by the system's package manager.
•/dev: Houses device files that represent system hardware (e.g., disks, terminals).
•/var: Stores variable files such as logs, spools, and caches that change dynamically during system
operations.
•/bin: Essential user binaries like basic command-line utilities (e.g., ls, cat).
•/sbin: System binaries, mainly for system administration tasks, usually requiring root privileges.
•/usr: Contains user applications and utilities, along with their libraries and documentation.
•/proc: Virtual filesystem providing process and kernel information.
•/mnt: Used to temporarily mount filesystems, such as removable media or network filesystems.
•/sys: Virtual filesystem that represents kernel objects, providing access to kernel settings and system
hardware information.
•/media: Directory for mounting removable media like CDs, USB drives, and external devices.
•/run: Contains runtime data used during the system’s operation (e.g., system services).
•/tmp: Temporary files, which are deleted either periodically or upon reboot.
•/lost+found: Directory used by the fsck utility to recover files that may become corrupted or lost
during a crash.
•/lib: Contains essential shared libraries needed by the binaries in /bin and /sbin.
•/srv: Service data directory where files related to specific services (like web or FTP servers) are stored.
16
Linux
Permission
Linux file permissions are essential for controlling access to files and directories, ensuring
the security and integrity of the system. Users and administrators must understand how to
set, view, and modify permissions to manage file access effectively. Linux file permissions
are a crucial aspect of the operating system's security model. They determine who can
access, modify, and execute files and directories on a Linux system. File permissions are
primarily defined for three categories: the owner of the file, the group associated with the
file, and others (everyone else).
17
Linux
1.Owner (User): The user who owns the file or directory. This user has the most control over
the file, including the ability to change its permissions.
2.Group: Files and directories can be associated with a specific group. All users belonging to
that group share the group's permissions for that file.
3.Others (World): Everyone else who is not the owner or a member of the group falls into this
category.
File Permissions:
Linux file permissions are represented using a combination of letters and symbols:
r: Read permission (can view the file's contents or list directory contents).
w: Write permission (can modify or delete the file or create new files in a directory).
x: Execute permission (can run a program or script if it is marked as executable).
These permissions are assigned to each category (owner, group, others) for each file or
directory.
18
Linux
• Permission Settings:
File permission settings are often displayed in the following format:
-rw-r--r—
19
Linux
Numeric Representation:
File permissions can also be represented numerically using octal (base-8) values:
644 represents -rw-r--r-- (Owner can read and write, group and others can only read).
755 represents -rwxr-xr-x (Owner can read, write, and execute; group and others can read and
execute).
20
Linux
You can change file permissions using the chmod command. For example, to give the owner write permission
on a file, you can use:
21
Linux
File Ownership:
Linux also assigns an owner and group to each file and directory. You can view ownership using the ls -l
command. To change ownership, use the chown command, and to change group ownership, use chgrp.
Execute x 1
22
Linux
Example Permissions:
If you don't use the "d" and only have the -rwxr-xr-x 7 5 5
permission string like rwxr-x--- it would be
interpreted as permissions for a regular file,
not a directory. In other words, it would drwxr-x--- 7 5 0
indicate that the file has the following
permissions:
23
Linux
Example Permissions:
The owner can read, write, and execute. Members of the group can read and execute. Others
(world) have no permissions (cannot read, write, or execute).
Including the "d" is essential to convey that these permissions are meant for a directory. This
distinction is crucial because directories and regular files serve different purposes and have
different operations associated with them. For example:
Reading a directory (r permission for a directory) allows you to list its contents.
Writing to a directory (w permission for a directory) permits you to create, delete, or rename files
and subdirectories within it.
Executing a directory (x permission for a directory) is required to change into (cd) that directory
or access its contents.
For regular files, the same "rwx" permissions control reading, writing, and executing the file
itself. 24