0% found this document useful (0 votes)
53 views23 pages

IL-Module 5

The document provides an introduction to common Linux administrative tasks such as managing users, groups and permissions, installing and removing packages, monitoring system activities, configuration files for booting, login, filesystems and system administration. It describes file locations for user, group, password and filesystem information.

Uploaded by

Kanak RT
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views23 pages

IL-Module 5

The document provides an introduction to common Linux administrative tasks such as managing users, groups and permissions, installing and removing packages, monitoring system activities, configuration files for booting, login, filesystems and system administration. It describes file locations for user, group, password and filesystem information.

Uploaded by

Kanak RT
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

Introduction to Linux 2020-2021

Module 5
Topics to be covered:
 Common administrative tasks
 Identifying administrative files configuration and log files
 Role of system administrator, managing user accounts-adding & deleting users,
changing permissions and ownerships, Creating and managing groups, modifying
group attributes, Temporary disabling of user’s accounts, creating and mounting file
system, checking and monitoring system performance
 File security & Permissions, becoming super user using su.
 Getting system information with uname, host name, disk partitions & sizes, users,
kernel
 Installing and removing packages with rpm command.

Types of Unix/Linux Users and Accounts


1. Root User Account: The main user account, automatically created during the
installation. It has the highest privilege in system. It can do any administrative work
and can access any service. This account is intended for system administration and
should not be used for routine activities.
2. Regular User Account: The normal user account. During the installation, one regular
user account is created automatically. After the installation, we can create as many
regular user accounts as we need. This account has limited privilege. This account is
intended for routine works. It can perform only the tasks for which it is allowed and
can access only those files and services for which it is authorized. As per requirement,
it can be disabled or deleted.
3. Service Account: Service accounts are created by OS during installation and are used
by services to run processes and execute functions. These accounts are privileged
accounts and not intended for routine work.
 All the information of users in a system are stored in /etc/passwd file. The encrypted
passwords for users are stored in /etc/shadow file.

Common Administrative Tasks


1. System Operations: Booting and shutdown
2. Managing Users: Adding and removing users, groups, permissions, ownership etc.
3. Performing Backups; Restoring files from backups that users have accidentally deleted.
4. File System Administration: Mounting and Unmounting file system

Jain School of CS and IT


Introduction to Linux 2020-2021

5. Monitoring System Activities: Checking disc use and log files, Trying to free up disc
space, ensuring different services such as email, web services, network services are
working correctly.
6. Troubleshooting: figuring out malfunctions of services/programs/devices, rebooting
after a crash, answering users’ question.
7. Monitoring System Security: Set up security features such as Firewall, implement
security audits, run sniffers/scripts to check system, network and file system is secure.
8. Adding and removing hardware devices, configuring them.
9. Installing new software, upgrading system or the kernel, configuring servers like web
server, file server, mail server, etc.
10. Writing scripts to automate as many of the above tasks as possible

Configuration Files
In Linux and UNIX, system services are configured using various configuration files.
There are dozens of such files and may slightly different in different Linux
distributions. Configuration files can be global files, and local files.
Global /system-wide config files
 Apply to all users
 Usually located in /etc directory tree
Local/ User-specific config files
 Applies to a specific user
 Stored in the user’s home directory, usually hidden (AKA dot files).
The configuration files can be used for tasks related to Booting, Login/logout, File
system management, System administration, Networking etc.

Booting config Files


 A runlevel is one of the modes that a Linux OS will run on. Each runlevel has a certain
number of services stopped or started, giving the user control over the behavior of the
machine. Conventionally, seven runlevels exist, numbered from zero to six.
Most Linux servers lack a graphical user interface and therefore start in runlevel 3.
Servers with a GUI and desktop Unix systems start runlevel 5. When a server is
issued a reboot command, it enters runlevel 6. To check your current runlevel
use runlevel command: $ runlevel
After the Linux kernel has booted, the init program reads the /etc/inittab file to
determine the behavior for each runlevel.

Jain School of CS and IT


Introduction to Linux 2020-2021

/etc/inittab; /etc/init.d - describes which processes are to be started at bootup


/etc/rcX.d : (X stands for any number from 0 to 6). These directories are “run-level”
specific directories. When a system starts up, it identifies the run-level to be initiated,
and then it calls all the startup scripts present in the specific directory for that run-level.
For example, the system usually starts up and the message “entering run-level 3” is
shown after the boot messages; this means that all the init scripts in the directory
/etc/rc.d/rc3.d/ will be called.

Login Shell Startup config Files


An interactive login shell is started after a successful login and the shell normally reads
the global /etc/profile and its local equivalent ~/.profile upon startup to configure the
shell environment.
.profile file is for Bourne shell (sh) or its compatible shells bash, ksh, ash etc.
Specific to bash, config files are: /etc/bash.bashrc and ~/.bashrc
The file ~/.bash_logout is read and executed when a user exits from an interactive login
shell.
These config files set environment variables, define aliases and functions, run scripts.

File System config Files


 /etc/fstab : Contains file system information; lists all file systems to be mounted, list of
disk drives and their partitions and their mount points.
 Your Linux system's file system table, aka fstab, is a configuration table designed to
ease the burden of mounting and unmounting file systems to a machine. It is a set of
rules used to control how different file systems are treated each time they are introduced
to a system. It is designed to configure a rule where specific file systems are detected,
then automatically mounted in the user's desired order every time the system boots.
 /etc/mtab: Currently mounted blocks information.

System Administration
 /etc/passwd : User authentication file contains the login data and is used during login
of a user.

Jain School of CS and IT


Introduction to Linux 2020-2021

1. Username- using which you login into Linux system.


2. Password- x means that the password is stored in the /etc/shadow file
3. UID- User ID of the user. If a user is root then the value of UID is 0. UIDs below 500
are reserved for system accounts. The normal user is assigned UID from 500 onwards.
4. GID- Each user is a member of a primary group and this field stores the group ID of
that group.
5. Full Name- Full name of the user, sometimes referred to as GECOS. It holds
information about the user such as first and last name, email address, phone number,
etc.
6. User Home Directory- absolute path of user's home directory. For a normal user, it is
/home/username.
7. Login shell- The shell that will be launched when user login. (defaults to /bin/bash).

 /etc/shadow : The shadow file contains user authentication information such as


encrypted password, password and account expiration date, last-time password
changed, etc.
1. Username- It is the name of a user that you will use to log in.
2. Encrypted password- This field holds an encrypted password of the user.
3. Password last changed- It specifies the number of days ( since the January 1, 1970),
the password was last changed.
4. Minimum password age- It specifies the minimum number of days that must pass
before the password can be changed.
5. Maximum password age- It specifies the maximum number of days for which the
password is valid.
6. Warning period- It specifies the number of days before password expiration that the
user is warned about the upcoming expiration.
7. Inactive period- The number of days after password expiration that account will be
disabled.

Jain School of CS and IT


Introduction to Linux 2020-2021

8. Account expiration- The date (represented as the number of days since the January 1,
1970) on which the account will expire and the user will no longer able to log in.
9. Reserved for future

 /etc/group : Configuration file for user groups. All the information related to groups
such as group name, group members, and group ID are stored in /etc/group file.
1. Group Name- This field stores a name of the group.
2. Group Password- This field specifies a password of the group and is generally left
blank. A value of x means password is stored in /etc/gshadow file for security reason.
A blank value means no password is assigned to this group.
3. Group ID(GID)- Every group is assigned a GID and this field is the place where GID
is stored.
4. Group Members- This field stores the usernames that belong to the group.

 /etc/motd : Message of the day shown after a user logs in. Used if an administrator
wants to convey some message to all the users of a Linux server.
 /etc/crontab : file specifies the system wide schedule of cron jobs that executes tasks
at specified intervals. These tasks are mostly used to automate system maintenance or
administration such as back up of data, updating the system with the latest security
patches, checking the disk space usage , sending emails, and so on.
 /etc/cron.d directories contain scripts to be run periodically.
 /etc/default: this is a special directory which holds the default configuration
information on some services, programs etc. For example, in /etc/default/useradd, you
can specify GROUP=500, so that your newly created users have 500 group id in default.

Jain School of CS and IT


Introduction to Linux 2020-2021

 /etc/hosts : The file contains list of hosts with their IP addresses and corresponding host
names that can be contacted using the network.
 /etc/hosts.allow: List of hosts allowed to access services on the Linux machine.
 /etc/host.deny : List of hosts denied to access services on the Linux machine.
 /etc/sysconfig/ : directory that contains the system's network configuration files

System Administrator’s Login


 Login as root:
This is a special account UNIX/Linux system provides; created during installation for
the exclusive use of the system administrator. It has a password and its prompt is #.
Once, login as root, the system administrator is placed in the / (root) directory instead
of a subdirectory like other user.
It is a privileged account and has enormous power to do anything in the system.
The root user also has a different environment of his won. For example his .profile and
PATH differ from others. His PATH is /bin: /usr/bin: /etc
 Login as super user using su:
Preferably, the system administrator has his own login directory for performing all
routine works instead of using the / (root) directory. He can acquire the super user status
from any user directory by invoking su command without logging as root.
The su (substitute user) allows you to run commands with the privileges of another
user, by default the root user.
 Syntax: su user
 Example (as root user): $ su
 Example (as acojha): $ su acojha
It will ask for the password of the user and on successful login creates a sub-shell under
the current shell to execute commands. You can logout of the sub-shell by typing exit
command.
 The sudo command
The sudo command allows you to execute a command by default, as the super user (or
as another user). It prompts you for your personal password and confirms your request
to execute a command by checking a security policy file, /etc/sudoers, which the
system administrator configures.
Using the sudoers file, system administrators can give certain users or groups access to
some or all commands without those users having to know the root password.

Jain School of CS and IT


Introduction to Linux 2020-2021

 Sudo vs Su
On some Linux distributions like Ubuntu, the root user account is disabled by default
for security reasons. This means that no password is set for root and you cannot
use su to switch to root.
You can set the root password with following command: $ sudo passwd root
First, the command will prompt for your own password to confirm that you have sudo
privileges.
After you've entered your password, the passwd command will prompts you to enter a
new password for the root account (Twice).
Now you can log in to the root user using the su command and entering the root
password when prompted.

Adding a New User Account


As a system administrator, you have the responsibility to manage the system’s users
and groups by creating and removing users and assign them to different groups etc.
 To add/create a new user, you may use the command ‘useradd’ or ‘adduser’. The
command useradd is native binary compiled with the system. But, adduser is a script
which uses useradd in back-end. The adduser is more user friendly than its back-
end useradd. There's no difference in features provided. Administrators should usually
use adduser instead.
 Once a new user created, it’s entry automatically added to the ‘/etc/passwd’ file.
 The useradd command creates a user in locked state and to unlock that user account,
you need to set a password for that account with ‘passwd’ command.
 Syntax: useradd username
 Example: $ sudo useradd raju
$ sudo passwd raju
 The adduser command takes password and other information and creates a user,
unlocks the account for immediate use.
 Syntax: adduser username
 Example: $ sudo adduser raju
Delete a user

To delete a new user, you may use the command ‘userdel’ or ‘deluser’. The command
userdel is native binary compiled with the system. But, deluser is a script which
uses userdel in back-end. Administrators usually use deluser instead.

Jain School of CS and IT


Introduction to Linux 2020-2021

The command modifies the system account files, /etc/passwd , /etc/shadow , and
removes the entries of the user.
 Syntax: userdel raju
Example: $ sudo userdel raju
 Syntax: deluser raju
Example: $ sudo deluser raju

Changing Password
 Change Your User Password
To change your own user’s account password, run the passwd command without any
arguments. You will be prompted to enter your current password. If the password is
correct, the command will ask you to enter and confirm the new password.
 Example: $ passwd
 Change Another User’s Password
To change the password of another user account, run the passwd command, followed
by the username. Only the root user and users with sudo access can change the
password of another user account.
 Syntax: $ sudo passwd username
Example: $ sudo passwd raju
 Options:
-d deletes the password of the user (makes it empty): $ sudo passwd -d raju
-e immediately expires an accounts password, and forces the user to change the
password at the next login $ sudo passwd -e raju

Creating a new User Group & Deleting Group


In Linux, groups are used to organize and administer user accounts. The primary
purpose of groups is to define a set of privileges such as reading, writing, or
executing permission for a given resource that can be shared among the users within
the group.
 Creating a Group: The groupadd command is used to create a group. The command
adds an entry for the new group to the /etc/group and /etc/gshadow files. Once the
group is created, you can start adding users to the group.
Syntax: groupadd [OPTIONS] GROUPNAME
 Example: $ sudo groupadd faculty
 Assigning a specific group id using –g option
 Example: $ sudo groupadd -g 1002 faculty

Jain School of CS and IT


Introduction to Linux 2020-2021

 Adding a user to the group


Syntax: useradd -g groupname useranme
Example: $ sudo useradd -g faculty raju
 Deleting a Group: To groupdel command delete a group from the system. The
command removes the group entry from the /etc/group and /etc/gshadow files. But you
can not remove the primary group of any existing user.
 Syntax: groupdel groupname
 Example: $ sudo groupdel faculty
 To check which groups the user belongs
Example: $ groups user

Modify Group
 The groupmod command is used to modify an existing group in Linux. The /etc/group
file is modified by the command.
Syntax: groupmod [option] group
 To change the name of the group from group_old to group_new, use the -n option
Example: $ sudo groupmod -n group_new group_old
 To change the group id, use -g option. The following command changes the GID of
‘teaching’ group to 1002.
Example: $ sudo groupmod -g 1002 teaching

Modify User Account


The command ‘usermod’ is used to modify any attributes of an existing user account.
The command modifies the account files to reflect the changes.
 Syntax: usermod [options] USER
 To add user to supplementary group(s) using -a and -G options. If you want to add the
user to multiple groups at once, specify the groups after the -G option separated
with , (commas) with no intervening whitespace.
 Example: sudo usermod -a -G iotlab raju
 To change a user’s primary group using the -g option.
 Example: sudo usermod -g mactlab raju
 To change the user information (full name, address etc called GECOS comment) using
the -c option
 Example: sudo usermod -c “Rajkumar Gowad” raju
 To change the login name of the user using -l option

Jain School of CS and IT


Introduction to Linux 2020-2021

 Example: sudo usermod -l rajkumar raju


 To change the default login shell use -s option. You can find out what shells are
available on your system by displaying the /etc/shells file’s content.
 Example: $ sudo usermod -s /etc/bin/sh rajkumar
 To change the uid of the user use -u option
 Example: $ sudo usermod -u 1005 rajkumar
 To change the default home directory use -d and -m options combined. These options
change the directory and move the contents of the current directory to the new location.
If the new directory does not exist, it is created.
 Example: sudo usermod -d /usr/rajkumar -m rajkumar

Disabling / Locking the User Account


 To set expiry date of password, use -e option. Specify the date in YYYY-MM-DD
format. Once the password expires, it forces the user to change the password in order
to login. An empty expiry date will disable the expiration.
 Example: $ sudo usermod -e “2021-01-26” rajkumar
 Example: $ sudo usermod -e “” rajkumar
 Use the chage -l command to list the user’s password aging information
Example: sudo chage -l rajkumar
 To lock the user account, use -L option. The command will insert an exclamation
point (!) mark in front of the encrypted password, effectively disabling the password.
When the password field in the /etc/shadow file contains an exclamation point, the user
will not be able to login to the system using password authentication.
 Example: $ sudo usermod -L rajkumar
 To unlock a user, use the -U option
 Example: sudo usermod -U rajkumar

File Permission and Mask


 By default, Linux permissions for new directories are set to 777 allowing read, write,
and execute permissions to user, group, and other users. Conversely, file permissions
default to 666 allowing read and write access to user, group, and others.
 The System Administrator often change the Linux default permissions by using the
umask command to reduce the originally requested permissions.
 You can use the umask command without specifying any arguments to determine what
your current default permissions are.

Jain School of CS and IT


Introduction to Linux 2020-2021

 The value displayed by umask must be subtracted from the defaults of 777
(directories) and 666 (files) to determine your current defaults.
Remember that the umask specifies which permissions should not be granted
automatically to newly created files or directories.
Use the -S option to display the umask symbolically, in a form that shows which are
the permissions that are allowed.

 To display current umask values in octal numbers:


Example: $ umask
 To display current umask values symbolically:
Example: $ umask –S
 To set umask values in octal numbers:
Example: $ umask 0077
In this case, the mask makes the files more private and disallows all group or other
access to newly created files
 To set umask values symbolically:
Example: $ umask u=rwx,g=,o=
 On Linux systems, where users do not have private groups, the umask normally defaults
to 0022, which removes group and other write permission from new files. Where users
have a private group, the umask normally defaults to 0002 which removes the write
permission for other users.
 The umask can be set system-wide ( in file /etc/profile or /etc/bash.bashrc) or user-
specific ( in file ~/.profile or ~/.bashrc)

Change File owner and group


 File permissions can be changed using the chmod command and ownership using
the chown command.
The root user can change the ownership of a file or directory using
the chown command.
Syntax: chown [OPTIONS] USER[:GROUP] FILE(s)
Example: To change the ownership of file ‘testfile’ to user ‘raju’.
$ sudo chown raju testfile

Jain School of CS and IT


Introduction to Linux 2020-2021

Example: To change the ownership as well as the group of a file


$ sudo chown raju:teaching testfile
Example: To change the ownership of a link, use –h option
$ sudo chown -h raju link_name
Example: To change the ownership of all files and directories under the given directory,
use –R option
$ sudo chown -R raju dir1

Change Group
 In Linux, each file is associated with an owner and a group. The chgrp command
changes the group ownership of given files.
 Regular user can change the group of the file only if he owns the file and only to a
group of which he is a member. Administrative user can change the group ownership
of all files.
Syntax: chgrp [OPTIONS] GROUP FILE(s)
Example: To change the group of file ‘testfile’ to group ‘faculty’.
$ sudo chgrp faculty testfile
Example: To change the group of a link, use –h option
$ sudo chgrp -h faculty link_name
Example: To change the group of all files and directories under the given directory, use
–R option
$ sudo chgrp -R faculty dir1

The locate command


 The locate command search for files and directories by their names in the file system.
It is frequently used by administrators and users to search files.
If locate is not installed, you can easily install it using the package manager of your
Linux distribution.
 Example: $ sudo apt install mlocate
 Using locate command:
 Example: $ locate .bashrc
 Example: $ locate *.sh
By default, locate performs case-sensitive searches. The -i (--ignore-case) option
tells locate to ignore the case and run a case-insensitive search.
 Example: $ locate -i readme.dat

Jain School of CS and IT


Introduction to Linux 2020-2021

To display the count of all matching entries, use the -c (--count) option.
 Example: $ locate -c .bashrc

File Systems in Linux


 Linux supports a large number of file systems. Each of these file system types uses its
own metadata and structures to store and manage the user data on a partition of a hard
drive or a logical volume. A Linux Distribution provides the choice of partitioning disk
with different file formats:
ext2, ext3 , ext4, jfs, ReiserFS, xfs, Btrfs, minix, msdos, ntfs, fat, vfat
 ext2, ext3, ext4: progressive version of Extended Filesystem (ext). ext4 supports larger
files and file system sizes.
 jfs: The Journaled File System was developed by IBM for AIX UNIX, and is an
alternative to ext4 currently.
 ReiserFS: was introduced as an alternative to ext3 with improved performance and
advanced features.
 xfs: a high speed JFS which aimed at parallel I/O processing.
 vfat: MS-DOS file system useful when sharing files between Windows and Linux
 Btrfs: B-Tree File System is relatively new file system focus on fault tolerance, large
storage configuration.
 ext4 is the preferred and most widely used Linux file System. In certain Special
case xfs and ReiserFS are used. Btrfs is still used in experimental environment.
 To check the supported file system types installed, use: $ ls /sbin/mkfs* command.

Creating a File System


 The command to build a Linux file system on a device, or hard disk partition, is mkfs.
 Syntax: $ sudo mkfs [options] [-t type] device
The mkfs command is actually a front end for the different file system builder utilities
such as mkfs.ext2 and mkfs.ext4. These utilities are executable directly from the
command line.
 If not specified, the default file system type, ext2, is created.
 Example: $ sudo mkfs /dev/sdb1
$ sudo mke2fs /dev/sdb1
$ sudo mkfs.ext2 /dev/sdb1
 All the above three commands are same
 To create a specific type of file system ( say an ext3), use (-t option) any of the following
commands:

Jain School of CS and IT


Introduction to Linux 2020-2021

 Example: $ sudo mkfs -t ext3 /dev/sdb1


$ sudo mke2fs -t ext3 /dev/sdb1
$ sudo mkfs.ext3 /dev/sdb1

File System Mounting and Unmounting


 File systems on different partitions and removable devices, must be attached to the root
file system in order to be accessed. To attach a partition or device, a mount point must
be created. A mount point is simply a directory created with the mkdir command. After
a directory, or mount point, is created, attach the partition by using the mount command.
 Syntax: sudo mount [options] device_file mount_point
 When used without any argument, the mount command will display all currently
attached file systems:
 Example: $ mount
 If a file system is of type ext4 or xfs, the command will auto-detect the file system
type.
 Example: $ sudo mount /dev/sdb1 ~/diskB
 If a file system is not recognized, use the -t option to specify the file system type:
 Example: $ sudo mount -t vboxsf /dev/sdb1 ~/diskB
 To detach a mounted file system , use umount command:
 Example: $ sudo umount mount_point
OR
$ sudo umount device_file

Other File System Commands


 Create a disk Partition
• Syntax: fdisk [option] device
 Example: $ sudo fdisk /dev/sdb
 To check partitions and list partition tables
 Example: $ sudo fdisk -l
 Checking File system integrity
 Example: $sudo fsck
 Display mounted file system information such as mount point, filesystem size, used
space free space etc.
 Example (disk free space): $ df

Jain School of CS and IT


Introduction to Linux 2020-2021

 Example (disk usage): $ du


 Example (list block device): $ lsblk
 Example (find mounted file system): $ findmnt
 Example (memory usage): $ free
 Example (view the full path of an executable file): $ which cat

Mounting a Shared Folder in VirtualBox VM


 Step-1: Install VirtualBox Guest Additions:
 VirtualBox Guest Additions are a collection of device drivers and system applications
designed to achieve closer integration between the host and guest operating systems.
 From the Virtual Machine menu bar, select Devices => click on Insert Guest
Additions CD image.
 Once the installation complete, Reboot the Virtual machine
 Or you can use command-line installation: $ sudo apt-get install virtualbox-guest-utils
 Step-2: Creating a shared folder
 Create a folder on the Host computer that you would like to share (for example,
linuxfiles) in your hard disk.
 From the Virtual Machine menu bar, select Devices => Shared Folders...
 Choose the 'Add' button.
 Select the folder to be shared (i.e. linuxfiles)
 Select the ‘Auto Mount’ and 'Make permanent' options
 Step-3: Mount the shared folder to a directory in your home directory
 $ sudo mount -t vboxsf linuxfiles ~/host

Creating and Mounting a File system


 Step 1: Adding the Virtual Drive
 Using Virtual Box Manager wizard, create and add a virtual hard disk to your virtual
machine. The new hard drive will be assigned to the device file say, /dev/sdb.
 Step 2: Creating Linux Partitions
 $ sudo fdisk /dev/sdb
A primary partition say /dev/sdb1 will be created
 Step 3: Creating a File System
 $ sudo mkfs.ext4 /dev/sdb1

Jain School of CS and IT


Introduction to Linux 2020-2021

 Step 4: Mounting a File system


Create a mount point and the mount the file system to the mount point
 $ mkdir ~/diskB
 $ sudo mount /dev/sdb1 ~/diskB
Note: Follow the instructions given in the associated document

Process Management
A process in Linux is nothing but a program in execution. It’s a running instance of a
program. Any command that you execute starts a process. Every process is given a
unique process identification number (PID) by the kernel to identify and manage it.
There are two types of processes: foreground process and background process.
A foreground process is any command or program a user runs directly, interacts with
it, and waits for it to complete. Background processes run independently of a user.
Programs and commands run as foreground processes by default.
A process undergoes several states during its execution. There are several commands
to manage the states of a process particularly, the running state.
For example: ps, top, kill, nice, renice etc.

The ps (process status) command


It displays a snapshot of the current processes. The default output of ps command is a
simple list of the processes running in the system. The output generated is not in real-
time. It shows process ID (PID), terminal type (TTY), total time the process has been
running (TIME), and the command that launches the process (CMD)
 Example: $ ps
To display a full list including parent process id (PPID), and start time of the process,
use -f
 Example: $ ps -f
To display every process, use -e option.
 Example $ ps -e
To display more information like CPU, and memory usage about the running processes
use -u option.
 Example: $ ps -u

The top command


It display process statistics continuously until stopped. Top command displays a list of
processes that are running in real-time along with their memory and CPU usage. Top
displays a list of processes, with the ones using the most CPU at the top.

Jain School of CS and IT


Introduction to Linux 2020-2021

 Example: $ top
You can use the up/down arrow keys to navigate up and down through the list. To quit
the display press q key. To kill a process, highlight the process with the up/down arrow
keys and press k key.

The kill command


Kill is used to send a signal to a process. However, it can be used to kill a process, given
its process id.
The most commonly used signal is "terminate" (SIGTERM) or "kill" (SIGKILL).
The default signal is 15, which is SIGTERM. Which means if you just use the kill
command without any number, it sends the SIGTERM signal.
 The syntax for killing a process is: $ kill [pid]
 Alternatively you can also use : $ kill -9 [pid]
This command will send a ‘SIGKILL’ signal to the process. This should be used in case
the process ignores a normal kill request.
However, to list the signals used in Linux, use command: $ kill -L

The nice and renice commands


In Linux, you can prioritize between processes. The priority value for a process is called
the ‘Niceness’ value. Niceness value can range from –20 to 19. A value of -20 is very
high priority, while a value of 19 is very low priority. A value of 0 is the default
priority, which means normal priority.
To start a process and give it a nice value other than the default one, use:
 $ nice -n [value] [process name]
To change nice value of a process that is already running use:
 $ renice [value] -p PID
If you’re making a process run at a higher priority, you’ll require root permissions.

Jain School of CS and IT


Creating and Mounting a File system
Step 1: Adding the Virtual Drive
Open Oracle VM Virtual Box Manager, select the Virtual Box for which you want to
add the new disk and click on Settings.

Click on Storage, select hard drive

Click on Add a hard disk.

Click on Create New Disk and follow the instructions to create a virtual hard disk.
Click OK when the wizard completes to close the settings.

Now, start your virtual machine, logon to Ubuntu and open terminal window.
On the shell prompt, give either of the following commands to see the new hard disk:
/dev/sdb

$ sudo ls /dev/sd*

$ sudo fdisk -l

As we can see from the above output, the new hard drive has been assigned to the
device file /dev/sdb. Currently the drive has no partitions shown (because we have
yet to create any)

Step 2: Creating Linux Partitions


Give the following command:

$ sudo fdisk /dev/sdb

Enter m to see the command options; then enter p to print partition table.
As we can see from the above fdisk output, the disk currently has no partitions
because it is a previously unused disk. The next step is to create a new partition on
the disk, a task which is performed by entering n (for new partition) and p (for
primary partition).

We can create only one partition which will be named partition 1, so enter 1 for
partition number, press enter key to accept default sector. Then enter w (to write
and exit) save the partition and exit from the utility.

Now, type $ sudo ls /dev/sd* command to check the new partition created (i.e.
/dev/sdb1)

You can also use list block device command to check the partition:

$ lsblk

Step 3: Creating a File System


We have just installed a new disk and configured a Linux partition on the disk.

The next step is to create a Linux file system on the partition so that the operating
system can use it to store files and data. The easiest way to create a file system on a
partition is to use the mkfs.ext4 utility which takes as argument the partition device:

$ sudo mkfs.ext4 /dev/sdb1

You can also use mkfs command with –t option:

$ sudo mkfs -t ext4 /dev/sdb1


Step 4: Mounting a File system
Create a mount point (for example, a directory named diskB in the home directory)

 $ mkdir ~/diskB

Mount the new file system to the mount point

 $ sudo mount /dev/sdb1 ~/diskB

Now, check the file system is mounted to the home directory:

 $ mount –t ext4

Now, the new hard drive is attached with a new file system mounted to a mount point under
your home directory. But the file system is owned by root and you as a regular user can’t use
it. Give following command to check the ownership:

$ ls –la diskB

See the current directory (.) dot is owned by root. So, change the ownership to the regular
user (in this case acojha):

$ sudo chown acojha:acojha diskB/.

Now, you can create file in this directory ~/diskB without sudo command.
Persist the mount
File system mounted manually above will be unmounted when the virtual machine
shutdown.

To ensure that the drive is remounted automatically after a reboot, it must be added
to the /etc/fstab file.

Now modify /etc/fstab file using vi editor to append:

It is also highly recommended that the UUID (Universally Unique Identifier) be used
in /etc/fstab to refer to the drive rather than just the device name (such
as, /dev/sdb1).

To find the UUID of the new drive, use the blkid utility:

$ sudo blkid

You might also like