UNIX - Module 1 (Chapter1 2 3)
UNIX - Module 1 (Chapter1 2 3)
22CSE351
Module-I
Introduction
By:
Dr. Saumya Y M., CSE, SJEC
Textbook and Reference Books
History of Unix
In 1969 Kenneth Thompson and Dennis Ritchie developed the UNIX operating system
at Bell Labs.
Unix is the first operating system designed to run on computers of all sizes, making open
systems possible.
UNIX became the foundation for the Internet.
5
History of Unix
"Until UNIX came on the scene, operating systems were designed with a particular
machine in mind. They were written in a low-level language (like assembler, which
uses human unreadable code).
The systems were fast, but were restricted to the hardware they were designed for.
Programs designed for one system would not run on the other. This was the status
when Ken Thompson and Dennis Ritchie, of AT&T fame, authored the UNIX
system.
6
History of Unix
"The origins of Unix date back to the mid-1960s when the Massachusetts Institute of
Technology (MIT), Bell Labs, and General Electric were developing Multics, a
time- sharing operating system for the GE-645 mainframe computer.
Multics featured several innovations, but also presented severe problems: size and
complexity, individual researchers at Bell Labs started withdrawing from the project.
The last to leave were Ken Thompson, Dennis Ritchie, Douglas McIlroy, and Joe Ossanna,
The new operating system was a single-tasking system, which was initially without
organizational backing, and also without a name.
6
History of Unix
In 1970, the group coined the name Unics for Uniplexed Information and
Computing Service ("eunuchs"),
Later Brian Kernighan takes credit for the idea, but adds that "no one can remember" the
origin of the final spelling Unix. Dennis Ritchie, Doug McIlroy, and Peter G. Neumann
also credit Kernighan.
The operating system was originally written in assembly language, but in 1973, Version 4
Unix was rewritten in C.
Version 4 Unix, however, still had many PDP-11 dependent codes, and was not suitable for
porting.
7
History of Unix
1978 the first port to another platform was made to for the Interdata 8/32O.
"Bell Labs produced several versions of Unix that are collectively referred to as "Research
Unix".
In 1975, the first source license for UNIX was sold to Donald B. Gillies at the University of
Illinois at Urbana–Champaign Department of Computer Science.
UIUC graduate student Greg Chesson, who had worked on the UNIX kernel at Bell Labs,
was instrumental in negotiating the terms of the license.
During the late 1970s and early 1980s, the influence of Unix in academic circles led to
large- scale adoption of Unix (BSDO and System V) by commercial startups including
DYNIX, HP-UX, SunOS/Solaris, AIX, and Xenix.
8
History of Unix
In the late 1980s, AT&T Unix System Laboratories and Sun Microsystems developed
System V Release 4 (SVR4), which was subsequently adopted by many commercial
Unix vendors.
In the 1990s, Unix and Unix-like systems grew in popularity and became the operating
system of choice for over 90% of the world's top 500 fastest supercomputers, as BSD and
Linux distributions were developed through collaboration by a worldwide network of
programmers.
In 2000, Apple released Darwin, also a Unix system, which became the core of the Mac
2020 Unix OS’s are widely used in modern servers, workstations, and mobile devices.
9
Meanwhile Microsoft was making it big with windows – GUI
–Windows 3.1/95/98 – for desktops
–Windows NT/2000 – for servers.
•So UNIX needed windows type interface for survival and introduced X windows @ MIT.
•Finally UNIX turned commercial.
–Richard Stallman – Started Free software foundation GNU
–Linus Torvalds – Linux OS
•Many Linux tools are written and supplied free by GNU(GNU's Not Unix”).
• It all began in 1991 when Linus Torvalds, a Finnish computer science student, started a
personal project to create a free operating system kernel. He was inspired by MINIX, a
UNIX- like operating system
• Today, Linux is one of the most widely used operating systems in the world, powering
everything from smartphones (like Android) to supercomputers.
• Linux’s open-source nature has allowed it to evolve rapidly, with contributions from
thousands of developers globally. It’s known for its stability , security, and flexibility,
making it a popular choice for a wide range of applications
Here are some key milestones in the history of Linux:
• 1991: Linus Torvalds released the first version of the Linux kernel. It was initially a
small project, but it quickly gained attention from developers around the world.
• 1992: Linux was re-licensed under the GNU General Public License (GPL), which
allowed anyone to use, modify, and distribute the software freely.
• 1994: The first stable version of the Linux kernel, version 1.0, was released.
Linux
•Origin: Created by Linus Torvalds in 1991 as a free and open-source alternative to UNIX.
•Features: Highly customizable, supports a wide range of hardware, and has a large
community of developers.
•Distributions: Includes popular distributions like Ubuntu, Fedora, and CentOS
BSD (Berkeley Software Distribution)
•Origin: Emerged from UNIX in the late 1970s at the University of California, Berkeley.
•Features: Known for its performance, security, and networking capabilities.
•Variants: Includes FreeBSD, OpenBSD, and NetBSD, each with its own focus and strengths
Solaris
•Origin: Developed by Sun Microsystems in 1992, now maintained by Oracle.
•Features: Known for its scalability, advanced features, and the ZFS file system.
•Use Cases: Often used in enterprise environments for its robustness and support for
large-scale applications
Outline
• Introduction of UNIX
• Introduction to OS
• Architecture
• Experience the Unix environment
• Basic commands
Introduction to OS
Operating System (OS)
• It is a software that manages the computers hardware and provides a
convenient and safe environment for running programs.
• It is loaded into memory when a computer is booted and remains active as long
as the machine is up.
OS Architecture
• Unix is an Operating System which is the base of all Operating Systems like Ubuntu,
Solaris, POSIX, etc. It was developed in the 1970s by Ken Thompson, Dennis Ritchie, and
others in the AT&T Laboratories. Originally it was written in assembler, later rewritten in
C.
• Users communicate with the kernel(part of OS) through a program known as the shell.
• A shell is a program that acts as the interface between the user and the UNIX system,
UNIX
1. Division of labor
Architecture
•Kernel: communicates directly with hardware
•Shell: command interpreter, translates commands into action
–Sh: BourneShell
–Csh: Cshell
–Ksh: Kornshell
2. The file and Process
• File: Array of bytes and can contain virtually anything.
• Process: name given to a file when it is executed as a program.
3. System calls
•Kernel, shell, applications---C
•All UNIX flavors use the same system calls---POSIX(Portable Operating
System Interface)
•Examples: Open, write
Kernel file LINUX: /boot/vmlinuz
• User program uses the services of the kernel to access the hardware using the system calls
• Kernel Manages system memory, schedules process, decides priorities and performs
other tasks which you don’t even bother. The kernel has to do lot of work even when if no
user program is running.
•Types:
• Sh (Bourne Shell) ($): One of the earliest UNIX shells, known for its simplicity
and scripting capabilities.
• Developed by Steve Bourne at AT&T Labs
•Because it is oldest and primitive it is not used in most systems today
•An enhanced version of Bourne Shell called Bash (Bourne again shell) is
used in Linux.
• Csh (C Shell) (%):
•Developed by Bill Joy in Berkeley
•Compatible version of C shell is tcsh used in Linux.
•Introduced features like command history and scripting syntax similar to the C
programming language. Received a name from the fact that its commands look like
C statements
• Ksh (Korn Shell): Combines features of both Bourne and C shells, offering enhanced
scripting capabilities and performance. Developed by David Korn at AT&T Labs
• It is the newest and most powerful
• It is compatible with Bourne shell
• The default system prompt for the bourne, bash and korn shells is dollar ($).
The file and process
Two simple entities support the UNIX system – the file and process.
File: Definition: A file is an array of bytes that can contain virtually anything, such as
text, images, or executable code.
• Unix provides a vast array of text manipulation tools that can edit these files without
using an editor.
Process
• Unix provides tools that allow us to control processes, move them between foreground
and background.
The System Calls
•System calls are the interface between user applications and the kernel. They allow
programs to request services from the operating system. Examples: Common system calls
include open, write, read, and close.
CreateProcess() Fork()
Process Control ExitProcess() Exit()
WaitForSingleObject() Wait()
Open()
CreateFile()
Read()
File manipulation ReadFile()
Write()
WriteFile()
Close()
SetConsoleMode() Ioctl()
Device Management ReadConsole() Read()
WriteConsole() Write()
GetCurrentProcessID() Getpid()
Information Maintenance SetTimer() alarm()
Sleep() Sleep()
CreatePipe() Pipe()
Communication CreateFileMapping() Shmget()
MapViewOfFile() Mmap()
SetFileSecurity() Chmod()
Protection InitializeSecurityDescriptor() Umask()
SetSecurityDescriptorgroup() Chown()
Regular expression : They allow you to define patterns to match specific sequences of
characters within text files or streams.
Example: [a-zA-Z]\d{2}
• Programming facility
–Unix shell is a programming language . –It has control structures, loops and variables
and are used in shell scripts-programs that can invoke the UNIX commands.
1. Man Pages: Man pages (short for manual pages) are the primary source of
documentation in Unix. They provide detailed information about commands, system calls,
library functions, and more. To access a man page, use the man command followed by the
name of the command or topic. For example: man ls.
This command will display the manual page for the ls command
2. Info Pages: Info pages are another form of documentation, often more detailed than man
pages. They are accessed using the info command. For example: info ls
This command will display the info page for the ls command
3. Help command: Many Unix commands have a built-in help option that provides a brief
overview of their usage. For example:
ls --help
This command will display a summary of the ls command’s options and usage.
Types of Unix Operating Systems
• Unix gives the user the flexibility to modify the Unix code according to their
requirements. Thus it is easy to port the Unix code on different types of hardware.
• The freely available source code of this operating system and its portability feature
lead to various Unix like operating systems.
• Some of the popular Unix like operating systems are Solaris, Darwin, AIX, HP-UX,
FreeBSD, NetBSD, Xenix, IRIX, Tru64, macOS, etc…
The UNIX Environment
Unix is originally designed as a multiuser environment, many users were installing Unix on
their personal computers.
This trend made up with the availability of Linux, a free Unix system
Time-Sharing
•Environment
Time-sharing allows multiple users to
share the computing resources of a
single machine simultaneously.
2. The Shell
The shell acts as an interface between the user and the kernel. It interprets user
commands and executes them. It also provides programming capabilities through
scripting.
- Interpreter: Translates user commands into actions performed by the kernel.
- Programming Capability: Allows users to write shell scripts to automate tasks.
3. Utilities
UNIX comes with a variety of utility programs that perform specific tasks. These include:
- Text Editors: Programs like `vi` and `nano` for editing text files.
- Search Programs: Tools like `grep` for searching text using patterns.
- Sort Programs: Utilities like `sort` for arranging text data.
4. Applications
Applications are user-level programs that perform specific tasks. These can range from
simple command-line tools to complex software suites. It is not a part of standard Unix but
is written by system administrators, professional programmers, or users to extend the
capability to the system
POSIX and the Single UNIX Specification
Dennis Ritchie's decision to rewrite UNIX in C didn’t quite make UNIX very
portable.
X/Open Portability Guide (XPG): Developed by X/Open (now The Open Group), this
guide aimed to create a more unified standard for UNIX systems.
• ls -l /home/user
Wrong option given- the shell locates the command but command finds the wrong option.
Ex: $ls –z
The error message is generated by the command and not the shell.
3. Exceptions
• who
• ls
• pwd etc….
Meaning of Internal and external
commands
Meaning of Internal and external
commands
• Internal commands are commands that are already loaded in the
system. They can be executed any time and are independent.
Example: cd, source, XCOPY, CHKDSK, LABEL, TREE etc
• External commands are loaded when the user requests for them.
Example: ls, cat etc
Internal and External Commands
Internal Commands
• These commands are built into the shell itself.
• They are executed directly by the shell without needing an external executable file.
• Generally faster because the shell doesn’t need to search for the command in the file
system.
External Commands
• These commands are not built into the shell. They exist as separate executable files in
the file system.
• The shell locates these commands in directories specified by the PATH variable and
then executes them.
• Slightly slower compared to internal commands because the shell needs to find and
execute the corresponding file.
• If a command has entry in built-in set and has external file also, in such situation
internal command takes precedence.
The type command: knowing the type of a command and locating it.
The type command in Linux is used to determine how a given command will be
interpreted by the shell.
Common Outputs:
•alias: If the command is an alias (a shortcut to another command).
•builtin: If the command is a built-in function of the shell itself.
•file: If the command is an executable file.
•function: If the command is a shell function.
•keyword: If the command is a reserved word in the shell.
Options
-t: Print a single word indicating the type of command.
-P: Search the PATH for an executable file even if the command is not a file.
type -a cd
Output might be:
cd is a shell builtin
Understanding of some basic commands
[echo, printf, ls, who, date, passwd, cal, Combining
commands.]
echo: Display message
Display diagnostic messages on the terminal, or issue prompts for taking user
input
Echo behavior differs across the shells, and most of these differences are related to
the way the echo interprets the escape sequence
Hello, World!user@SJEC:$
To use these escape sequences, you need to use the -e option with the echo command.
Escape Sequence Description
\a Alert (bell). Produces an audible or visible alert, depending on the system.
\b Backspace. Moves the cursor one position to the left.
\c Suppress further output. Echo will not output anything else that follows.
\e Escape character.
\f Form feed. Moves the cursor to the start of the next page.
\n New line. Moves the cursor to the next line.
\r Carriage return. Moves the cursor to the beginning of the line.
\t Horizontal tab. Adds a tab space.
\v Vertical tab. Moves the cursor down to the next vertical tab stop.
\\ Backslash. Prints a backslash character.
\' Single quote. Prints a single quote character.
\" Double quote. Prints a double quote character.
Enable interpretation of backslash escapes:
echo -e “Hello,\nWorld!”
Hello,
World!
Using variables:
name="Alice"
echo "Hello, $name!“
Like echo printf exists as an external command but only the Bash shell has printf built-in.
printf does not automatically insert a newline unless the \n is used explicitly
printf also uses formatted strings in the same way the C language function
$ printf "My current shell is %s\n" $SHELL
My current shell is /bin/bash
printf allows for detailed formatting, including specifying width, precision, and alignment,
making it suitable for more complex output needs. echo is straightforward and does not
support advanced formatting.
echo is generally more portable across different Unix-like systems. printf can behave
differently on various systems, especially with different versions of the shell
Escape Sequences
Format Strings
\a Bell
%s string
\b Backspace
%30s printed in space 30 characters wide
\c No newline
%d decimal integer \f Formfeed
%6d printed in space 6 characters wide \n Newline
num=10
$ printf "My current shell is %x\n" $num
My current shell is a
printf
• Similar to echo
• Differ in newline
ls: listing files in current directory
The ls command in UNIX is used to list files and directories within the file system
1. Basic Listing
Command:
$ ls
$ ls /home/user
Description: Lists files and directories in the /home/user directory
The files are arranged alphabetically with uppercase having precedence over lower.
Common Options:
-l: Long listing format. Displays detailed information about each file, including
permissions, number of links, owner, group, size, and timestamp.
-a: Lists all files, including hidden files (those starting with a dot).
-h: Human-readable format. Makes file sizes easier to read (e.g., 1K, 234M, 2G).
Description: Lists all files, including hidden files (those starting with a dot).
Example Output:
.bashrc .profile [Link] directory
Human-Readable Sizes
•Command:
ls -lh
•Description: Shows file sizes in a human-readable format (e.g., KB, MB).
•Example Output:
drwxr-xr-x 2 user group 4.0K Aug 12 20:00 directory
-rw-r--r-- 1 user group 1.2K Aug 12 20:00 [Link]
Combine Options
Command:
ls -alh
Description: Combines multiple options to list all files (including hidden ones) in long
format with human-readable sizes.
Example Output:
drwxr-xr-x 5 user group 4.0K Aug 12 20:00 .
drwxr-xr-x 3 user group 4.0K Aug 12 20:00 ..
-rw-r--r-- 1 user group 1.2K Aug 12 20:00 .bashrc
drwxr-xr-x 2 user group 4.0K Aug 12 20:00 directory
-rw-r--r-- 1 user group 1.2K Aug 12 20:00 [Link]
Consider the following directory structure:
ls -R /home/user
Output:
/home/user:
dir1 [Link] [Link]
/home/user/dir1:
dir2 [Link]
/home/user/dir1/dir2:
[Link]
The ls -x command in Linux lists directory contents in columns, sorted horizontally.
This means that the files and directories are displayed in rows across the terminal window,
rather than in a single column or sorted vertically.
The ls -F command in Linux is used to append a character to each file name indicating the
file type. This makes it easier to distinguish between different types of files and directories
at a glance.
/ for directories
* for executable files
@ for symbolic links
| for FIFOs (named pipes)
= for sockets
#!/bin/bash
# This script displays the current user, date and time, and the contents of the current
directory
• ls
• LS
• ls chap*
• ls –l
• ls –l chap*
ls options
$ who
user1 tty7 2024-08-12 09:00
user2 pts/0 2024-08-12 09:05
$who –H
NAME LINE TIME COMMENT
user1 tty7 2024-08-12 09:00
user2 pts/0 2024-08-12 09:05
$who –uH
date
•If a users account is not set with the password or if it is already known to others then to
$passwd
• cal command is used to see the calendar of any specific month or a complete year.
• cal can be used without arguments in which it displays the current month
• $ cal
$ cal 01 2024
Display the entire current year:
cal -y
This command shows the calendar for the entire current year.
The ps command in UNIX and Linux is used to display information about the currently
running processes.
The cat command is a versatile tool used for various file-related operations
Basic Usage
Display File Contents: To display the contents of a file, use:
cat [Link]
Concatenate Multiple Files: Combine and display the contents of multiple files:
cat [Link] [Link]
Copy Contents to Another File: Copy the contents of one file to another:
cat [Link] > [Link]
Contents of [Link] will be copied to the contents of [Link]. The original content of
[Link] will be replaced by [Link] contents
1 line 1 contents
2 line 2 contents
Suppress Repeated Empty Lines: Remove repeated empty lines in the output:
cat -s [Link]
It provides information about the number of lines, words, and characters in a file.
To count words:
wc -w [Link] ===🡺 6 [Link]
To count bytes:
wc -c [Link] ===🡺 26 [Link]
Flexibility of command usage
1) Combining commands
You can run multiple commands in a single line by separating them with a semicolon (;).
This allows you to execute several commands sequentially. Here’s an example:
For instance, if you want to list the contents of a directory, create a new directory, and then
navigate into it, you can do:
Shell understands that the command on each side of it needs to be processed separately
; is a metacharacter.
Flexibility of command usage
2) Command line can overflow or be split into multiple lines
Command line can be entered even if the width may exceed the terminal width.
UNIX lets us type a command at anytime , the system will interpret it.
When a long program is run, the prompt is not shown till completed but still can accept
commands and interpret.
The command is passed to shell for interpretation after previous program has completed.
Sun Aug 18 [Link] IST 2024
August 2024
$sleep 10 Su Mo Tu We Th Fr Sa
1 2 3
date; cal
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
man : Browsing the manual pages online
Man-Online Help facility command
Man displays the documentation called man documentation of every command in the
system.
Ex: $man wc
In UNIX/Linux, the man command uses a pager to display the manual pages one
screenful at a time. By default, the pager used is typically less, but it can also be
configured to use other pagers like more.
more: One of the oldest pagers, more allows you to scroll down through a text
file one screen at a time. It has basic navigation features but cannot scroll
backward.
less: An advanced pager that allows both forward and backward navigation
through text files. It includes additional features like search and is often the
default pager on many systems
For example, if you run:
ls -l | more
You can only move forward through the list of files. If you accidentally skip a screen, you
cannot go back to it.
In contrast, less allows both forward and backward navigation, even when used with
pipes, making it more versatile for viewing long outputs.
ls -l | less
Navigation and Search
Navigating and searching within a man page in Linux can be very efficient once you know
the right commands.
Navigation
Spacebar: Move forward one page.
b: Move backward one page.
Enter: Move forward one line.
Up/Down Arrow Keys: Move up or down one line.
PgUp/PgDn: Move up or down one page.
Home/End: Move to the beginning or end of the man page.
Navigation and Search
Searching
/: Start a forward search. Type the search term and press Enter. Use n to go to the next
occurrence and N to go to the previous occurrence.
?: Start a backward search. Type the search term and press Enter. Use n to go to the next
occurrence and N to go to the previous occurrence.
Exiting
q: Quit the man page viewer.
Understanding the man documentation
Understanding a man page in Linux can be very helpful for getting detailed information
about commands and their usage.
Every command does not have all sections, but the first three(NAME, SYNOPSIS and
DESCRIPTION) are generally seen in all man pages.
Structure of a man Page
NAME: The name of the command or function, followed by a brief description.
DESCRIPTION: Provides a detailed explanation of the command, its options, and its behavior.
OPTIONS: Lists and explains the command-line options available for the command.
NAME:
ls - list directory contents
SYNOPSIS:
ls [OPTION]... [FILE]...
DESCRIPTION:
List information about the FILEs (the current directory by default).
OPTIONS:
-a, --all do not ignore entries starting with .
-l use a long listing format
Navigating a man Page
/: Start a forward search. Type the search term and press Enter.
These numbers can be of help when writing shell scripts in order to determine the actual cause
of termination of a command
man man
This will show you the manual page for the man command, explaining how to use it
and its various options.
In UNIX/Linux, the man command uses a pager to display the manual pages one
screenful at a time. By default, the pager used is typically less, but it can also be
configured to use other pagers like more.
You can change the default pager by setting the PAGER environment variable.
For example, to use more instead of less, you can run:
export PAGER=more
The man –k, apropos and whatis command
The man -k command in UNIX/Linux is used to search the manual page descriptions for
keywords. It’s a helpful way to find commands related to a specific topic or function when
you don’t know the exact command name.
man -k list
This will return a list of commands and their short descriptions that include the keyword
“list.”
-k: This option stands for “keyword” and searches the short descriptions and names of
manual pages for the specified keyword.
Output: The output will include the command names and their brief descriptions, helping
you identify which command might be useful for your needs.
The man –k, apropos and whatis command
apropos command helps to find out the files and commands associated with a given
keyword.
apropos list
This will return all commands and their descriptions that include the keyword “list”.
The man –k, apropos and whatis command
This can be particularly useful when you need a quick summary of what a command
does without reading through the entire manual page
whatis ls
This will return a short description of the ls command.
Special Characters
• The tty command of terminal basically prints the file name of the terminal connected to
standard input. tty is short of teletype, but popularly known as a terminal it allows you to
interact with the system by passing on the data (you input) to the system, and displaying
the output produced by the system
Knowing your terminal
To find out which terminal you’re currently using in a Linux environment, you can use the
tty command. This command prints the file name of the terminal connected to the standard
input.
$ tty
/dev/tty3
stty -Displaying its characteristics and setting characteristics
The stty command in Linux is used to change and print terminal line settings.
Display all settings:
stty -a
This prints all current settings in a human-readable form.
Speed 38400 baud: Sets the terminal speed to 38400 baud. It means that the terminal
communicates at a rate of 38400 bits per second.
rows 26; columns 110: Configures the terminal to have 26 rows and 110 columns.
kill = ^U: Sets the kill character to Ctrl+U (deletes the current line).
Disable echo:
stty -echo
This turns off the echo, so characters typed are not displayed on the screen.
Enable echo:
stty echo
This turns the echo back on.
Displaying its characteristics and setting characteristics
Backspace should erase characters:
$ stty –echoe
This command ensures that the backspace key erases characters.
Enter password through a shell script:
$ stty –echo
This command disables the echo, so when you type your password, it won’t be displayed
on the screen.
Changing the interrupt key:
$ stty intr \^c
This sets the interrupt key to Ctrl+C.
Basic Usage
To start bc, simply type bc in your terminal:
bc
This opens an interactive prompt where you can type arithmetic operations.
Common Options
-l: Load the standard math library, enabling advanced mathematical functions(sine (s),
cosine (c), exponential (e), natural logarithm (l) etc) .
-q: Quiet mode, which suppresses the welcome message.
$bc
12+5 echo "12 + 5" | bc
17 17
11*3
33 echo "x=10; x*2" | bc
[Ctrl-d] 20
$
$bc
12+5; 11*3
17
33
[Ctrl-d]
$
In bc, the ibase and obase variables are used to set the input and output number bases,
respectively. This allows you to convert numbers between different bases.
obase=2
8
1000
12
1100
script command
The script command is used to record your terminal session, capturing all the input and output
displayed on the terminal.
This can be particularly useful for debugging, creating tutorials, or keeping a log of your
activities.
script
This will start a new session and save the output to a file named typescript by default.
exit
Here are some useful options for the script command:
-a, --append: Append the output to the file instead of overwriting it.
Changes the text color to red (1 is the color code for red).
Bold Text:
tput bold
Here are some common options you can use with uname:
It has the highest level of access and permissions, allowing it to perform any action on the
system, including modifying system files, installing software, and managing user accounts.
Login: root
Password :*******[Enter]
#_
On modern systems most administrative commands are resident in /sbin and /usr/sbin and
in Older systems most administrative commands are resident in /etc
root: The System Administrators Login
roots path list is also different from one used by other users.
Many standard scripts supplied with UNIX systems for system administrator work rely
on the Bourne Shell for execution.
Becoming thesuper user: su command.
The su (substitute user) command in UNIX/Linux allows you to switch to another
user’s account, typically the root user, within your current login session.
This is useful for performing administrative tasks that require elevated privileges.
Basic Usage
To switch to the root user, simply type:
su
You will be prompted to enter the root password. Once authenticated, you will have
root privileges.
Becoming a super user
• On UNIX this special user is known as superuser or root(not to be confused with the
root directory).
• Superuser can override file security and do almost anything he/she wants on the system
(she cannot see your password, since it is encrypted, but she can change it).
/home/Juliet
# prompt indicates that Juliet now has power of
Administrator can recreate the users environment without taking the login-password root
– su –henry
Su runs a separate sub-shell, so this mode is terminated by hitting [Ctrl-d] or using exit
Becoming a super user
Common Options
Login Shell: To start a login shell with the environment similar to a real login, use:
su -
Run Command: To run a specific command as the root user without starting an interactive
shell, use:
su -c 'command'
Example
To switch to the root user and run the ls command:
su -c 'ls'
The administrator's privileges
As a system administrator in UNIX/Linux, you have a wide range of powerful privileges. Here
are some key ones:
Change any user’s password: You can change any user’s password without knowing the
existing one using the passwd command. For example:
sudo passwd username
Set the system clock: You can set the system clock using the date command. For example:
sudo date MMDDhhmm[[CC]YY][.ss]
Address all users concurrently: You can send a message to all logged-in users using the wall
command. For example:
sudo wall "System maintenance will start in 10 minutes."
The administrator's privileges
Limit the maximum size of files: You can limit the maximum size of files that users are
permitted to create using the ulimit command. For example:
ulimit -f size
Control access to scheduling services: You can control users’ access to scheduling
services like at and cron by editing the /etc/[Link], /etc/[Link], /etc/[Link], and
/etc/[Link] files.
Control access to networking services: You can control users’ access to many
networking services like FTP, SSH, etc., by configuring the respective service’s
configuration files, such as /etc/ssh/sshd_config for SSH.
The/etc/passwd and/etc/shadowfiles
/etc/passwd is the key file in any Linux Unix system.
• The password file is a human-readable file that contains information about users on
the system including their encrypted passwords
• Some systems don’t have encrypted passwords in this file if /etc/shadow file is generated.
• cat /etc/passwd
/etc/passwd and /etc/shadow
• Username: Its user name being used by the user to login
• Password: Its password in an encrypted [Link] see x instead of encrypted password
since /etc/shadow file is generated on the system. The encrypted password is found in
/etc/shadow file in such case.
• UID: Its user id. Its unique number assigned to every account on the system.
• GID: Its group id. Its unique number of groups of which account is member of.
• Comment: This field is introduced to have some descriptions against the account. This is
purely for humans to identify/understand what related account is or to whom it belongs
to
• Home directory: Its a directory where normally user lands into when he/she login.
• Login shell: This is a shell that will be spawn when the user successfully logs in.
root:x:0:0:root:/root:/bin/bash
root:$6$h./k6HFM$EmRq6TQl80Lq7BF5k0v9A8MvCZx5PddhczyUViwtfj.FWkl6xsE0Tt
YJ
Commands to add, modify and delete users.
To add a new user in Linux, you can use the adduser command
This will create a new user named john and prompt you to set a password and provide
other details
Commands to add, modify and delete users.
The userdel command in Linux is used to delete a user account and its associated files.
Here’s a quick guide on how to use it:
Basic Syntax
sudo userdel username
Use the -a (append) option to add the user to a new group without removing them from
other groups.