Linux Lab
Linux Lab
Introduction:
LINUX is an open-source operating system used extensively worldwide. It is free and its source code
is available for everyone under GNU (General Public License).
Linux as an Operating System provides a wide range of features that can be used by a wide range of
systems such as servers and computers.
Android OS is also based on the Linux kernel that extends its usage for building embedded systems
and automation systems.
Linux is open-source. This means that modification of code, analysis of codes, redistribution of codes,
or selling copies of the enhanced codes can be done by anyone in the world provided they come under
the same license where the license also costs no charge.
Linux operating system is released under the GNU (General Public License) and is now one of the
largest open-source projects worldwide.
2. Extremely Flexible
Linux has incorporated itself into embedded products like watches, digital equipment and
supercomputing servers.
There are no prerequisites for installing an entire Linux suit. It allows a user to install only the
components that are required by the user.
3. Lightweight Infrastructure
Linux consumes lesser storage space, and its installation requires around 4GB to 8GB of disk space.
Memory footprint or the amount of memory (RAM) used by the software while running is also less
and it is compatible with all kinds of file formats like text files, audio files, video files, graphic formats,
etc.
5. End-to-end encryption
Linux allows end-to-end encryption while accessing data thus storing public keys in the server. All
data is password protected and provides authentication to users. It also allows many security features
and provides file permissions, a secure shell, etc.
Hence, Linux uses Command-line interface to carry out the execution of tasks which is comparatively
more efficient to execute and takes lesser time. It also takes lesser space in the memory,
8. Customized keyboard
Linux is available in all languages which makes it acceptable worldwide. That is why language can be
changed from the keyboard according to the requirements and preferences.
1) Ubuntu
It came into existence in 2004 by Canonical and quickly became popular. Canonical wants Ubuntu to
be used as easy graphical Linux desktop without the use of command line. It is the most well known
Linux distribution. Ubuntu is a next version of Debian and easy to use for newbies. It comes with a
lots of pre-installed apps and easy to use repositories libraries.
Earlier, Ubuntu uses GNOME2 desktop environment but now it has developed its own unity desktop
environment. It releases every six months and currently working to expand to run on tablets and
smartphones.
2) Linux Mint
Mint is based on Ubuntu and uses its repository software so some packages are common in both.
Earlier it was an alternative of Ubuntu because media codecs and proprietary software are included in
mint but was absent in Ubuntu. But now it has its own popularity and it uses cinnamon and mate
desktop instead of Ubuntu's unity desktop environment.
Abhishek Kumar Singh 0187CS221016 3
3) Debian
Debian has its existence since 1993 and releases its versions much slowly then Ubuntu and mint.
This makes it one of the most stable Linux distributor.
Ubuntu is based on Debian and was founded to improve the core bits of Debian more quickly and
make it more user friendly. Every release name of Debian is based on the name of the movie Toy
Story.
Red hat uses trademark law to prevent their software from being redistributed. CentOS is a community
project that uses red hat enterprise Linux code but removes all its trademark and make it freely
available. In other words, it is a free version of RHEL and provide a stable platform for a long time.
5) Fedora
It is a project that mainly focuses on free software and provides latest version of software. It doesn't
make its own desktop environment but used 'upstream' software. By default it has GNOME3 desktop
environment. It is less stable but provides the latest stuff.
1. mkdir : This command is used to create a directory in current file system or directory.
Syntax :
[ ]# mkdir <directory name>
Eg.
[ ]#mkdir sistec
2. ls : List , this command is used to show all directories and files in current file system or
directory
Syntax :
[ ]# ls
Sistec f1 f2 f3 dos.c cs
3. ls -l : Long List , this command is used to show all directories and files in current file
system or directory with certain information.
Syntax :
[ ]# ls -l
drwxr-xr-x 2 root root 4096 Aug 18 15:05 cs
-rwxr-xr-x 1 root root 96 Aug 18 15:06 f1
-rwxr-xr-x 2 root root 40 Aug 18 15:20 f2
4. cd : Change Directory
(A) [ ] $ cd This command is used to change dir to home directory
Eg.
[sistec@localhost cs ]$ cd
[sistec@localhost ~ ]$
Eg.
india
mp up
[ ]$mkdir -p india/mp/gwl
[ ]$mkdir -p india/mp/bpl
[ ]$mkdir -p india/up/agra
[ ]$mkdir -p india/up/gorakhpur
Syntax :
Describe the following File management commands with syntax and examples
1. cat >
2. cat
3. more
4. less
5. cat >>
6. cp
7. mv
8. rm
1. cat > : This command is used to create a file in current file system or directory.
Syntax :
[ ]#cat > <file name>
Eg.
[ ]#cat > f1
1234567
Abcdefg ------ press crtl + d twice to save file (if cursor is on content line)
[ ]#cat > f2
1234567
Abcdefg
press crtl + d once to save file (if cursor is on new line)
Syntax :
[ ]#more <file name>
Eg.
[ ]#more f1
12345678
Abcdefg
Syntax :
[ ]#less <file name>
Eg.
Abhishek Kumar Singh 0187CS221016 7
[ ]#less f1
12345678
Abcdefg
(A) Redirect one file to another by > .This will overwrite the contents of one file to
another
Syntax :
[ ]#cat fille1 > file2
Eg.
[ ]#cat file1
12345678
[ ]#cat file2
Abcdefg
Then
[ ]# cat file1 > file2
[ ]#cat file1
12345678
[ ]#cat file2
12345678
(B) Redirect one file to another by >> .This will append the contents of one file to
another
Syntax :
[ ]#cat fille1 >> file2
Eg.
[ ]#cat file1
12345678
[ ]#cat file2
Abcdefg
Then
[ ]# cat file1 >> file2
[ ]#cat file1
12345678
[ ]#cat file2
Abcdefg
12345678
6. cp : This command is used to copy files. Copy may be file to file or file to directory .
Syntax :
copy content of one file to another file
[ ]#cp <file name1> <file name2>
Eg.
[ ]#cp f1 f2
Syntax :
Rename file
[ ]#mv <old file name> <new file name>
Eg.
[ ]#mv f1 f5
[ ]#ls
F5
Syntax :
[ ]#rm <file name>
Eg.
[ ]#rm f1
In this example, you see two different listings. The first field of the ls -l output is a group of metadata
that includes the permissions on each file.
File type: -
Permission settings: rw-r--r--
Extended attributes: dot (.)
User owner: root
Group owner: root
File permissions control the ability of user and group accounts to view, modify, access, and execute
the contents of the files and directories.
Symbolic notation :
Type the initial letter for each class, followed by the equal sign (=) and the first letter of the read (r),
write (w) and/or execute (x) privileges.
Numeric Notation
Another way to specify permission is by using the octal/numeric format. This option is faster, as it
requires less typing, although it is not as straightforward as the previous method.
Instead of letters, the octal format represents privileges with numbers:
r(ead) has the value of 4
w(rite) has the value of 2
(e)x(ecute) has the value of 1
no permission has the value of 0
The privileges are summed up and depicted by one number. Therefore, the possibilities are:
7 – for read, write, and execute permission
6 – for read and write privileges
5 – for read and execute privileges
4 – for read privileges
As you have to define permission for each category (user, group, owner), the command will include
three (3) numbers (each representing the summation of privileges).
For instance, let’s look at the test.txt file that we symbolically configured with the chmod u=rw,g=r,o=r
test.txt command.
The same permission settings can be defined using the octal format with the command:
chmod 644 test.txt
Syntax :
[ ]# useradd <username>
Eg.
[ ]# useradd sistec
Syntax :
[ ]# passwd <username>
eg.
[ ]# passwd sistec
Change password for user sistec.
New UNIX Password :
Retype UNIX Password :
Passwd : all authentication token update successfully.
3. useradd –u : This command is used to add a new user with specified User ID.
Syntax :
eg.
[ ]# cat /etc/passwd
Syntax :
eg.
6. useradd -u –g : This command is used to add a new user with specified User ID and
Group.
Syntax :
eg.
7. useradd –c : This command is used to add a new user with user comment.
Syntax :
Describe the following user management commands with syntax and examples
1. passwd
2. usermod -l
3. cat /etc/passwd
4. usermod –u
5. usermod –g
6. usermod –u –g
7. usermod -c
8. userdel
9. userdel -r
Syntax :
Eg.
Syntax :
[ ]# passwd <username>
eg.
[ ]# passwd sps
Change password for user sistec.
New UNIX Password :
Retype UNIX Password :
Passwd : all authentication token update successfully.
Syntax :
eg.
Syntax :
eg.
Syntax :
eg.
6. usermod –c : This command is used to add a new user with user comment.
Syntax :
eg.
7. userdel : This command is used to delete a user name without its home directory.
Syntax :
[ ]# userdel <username>
eg.
[ ]# userdel IT
8. userdel -r : This command is used to delete a user name with home directory.
Syntax :
[ ]# userdel -r <username>
eg.
[ ]# userdel -r sps
There are 2 categories of groups in the Linux operating system i.e. Primary and Secondary groups.
The Primary Group is a group that is automatically generated while creating a user with a unique user
ID simultaneously a group with ID same as the user ID is created and the user gets added to the group
and becomes the first and only member of the group. This group is called the primary group. The
secondary group is a group that can be created separately with the help of commands and we can then
add users to it by changing the group ID of users.
groupadd group_name
Example:
groupadd Group1
2. Command to Set the Password for the Group: Below command is used to set the password of
the group. After executing the command we have to enter the new password which we want to assign
to the group. The password has to be given twice for confirmation purposes.
gpasswd group_name
Example:
gpasswd Group1
Command to Display the Group Password File: The below command gives us the password file as
output. The file is present in a form such that no information about the file is open for the viewers.
Instead of this try: “cat /etc/group” to get more information about the groups.
3. Command to Add a User to an Existing Group: Below command is used to add a user to an
existing group. The users which may be present in any primary or secondary group will exit the other
groups and will become the part of this group.
4. Command to Add User to Group Without Removing From Existing Groups: This command is
used to add a user to a new group while preventing him from getting removed from his existing groups.
usermod -aG *group_name *username
Example:
usermod -aG group1 amit
6. Command to Delete a User From a Group: Below command is used to delete a user from a group.
The user is then removed from the group though it is still a valid user in the system but it is no more a
part of the group. The user remains part of the groups which it was in and if it was part of no other
group then it will be part of its primary group.
7. Command to Delete a Group: Below Command is used to delete the group. The users present in
the group will not be deleted. They will remain as they were, but now they will no more be part of this
group as the group will be deleted.
groupdel *group_name
Example:
groupdel Group1
The Linux File Hierarchy Structure or the Filesystem Hierarchy Standard (FHS) defines the directory
structure and directory contents in Unix-like operating systems. It is maintained by the Linux
Foundation.
In the FHS, all files and directories appear under the root directory /, even if they are stored on different
physical or virtual devices.
Some of these directories only exist on a particular system if certain subsystems, such as the X Window
System, are installed.
Most of these directories exist in all UNIX operating systems and are generally used in much the same
way; however, the descriptions here are those used specifically for the FHS and are not considered
authoritative for platforms other than Linux.
1. / (Root): Primary hierarchy root and root directory of the entire file system hierarchy.
Every single file and directory starts from the root directory
The only root user has the right to write under this directory
/root is the root user’s home directory, which is not the same as /
6. /home : Users’ home directories, containing saved files, personal settings, etc.
Home directories for all users to store their personal files.
example: /home/kishlay, /home/kv
mnt-linux-directory
12. /srv : Site-specific data served by this system, such as data and scripts for web servers, data
offered by FTP servers, and repositories for version control systems.
srv stands for service.
Contains server specific services related data.
Example, /srv/cvs contains CVS related data.
13. /tmp : Temporary files. Often not preserved between system reboots, and may be severely size
restricted.
Directory that contains temporary files created by system and users.
Files under this directory are deleted when system is rebooted.
14. /usr : Secondary hierarchy for read-only user data; contains the majority of (multi-)user utilities
and applications.
Contains binaries, libraries, documentation, and source-code for second level programs.
/usr/bin contains binary files for user programs. If you can’t find a user binary under /bin,
look under /usr/bin. For example: at, awk, cc, less, scp
/usr/sbin contains binary files for system administrators. If you can’t find a system binary
under /sbin, look under /usr/sbin. For example: atd, cron, sshd, useradd, userdel
/usr/lib contains libraries for /usr/bin and /usr/sbin
/usr/local contains users programs that you install from source. For example, when you install
apache from source, it goes under /usr/local/apache2
/usr/src holds the Linux kernel sources, header-files and documentation.
OR
echo -e "Hello\nHi"
OR
#!/bin/bash
clear
echo -n "Enter 1st number: "
read first_number
echo -n "Enter 2nd number: "
read second_number
sum=$(($first_number + $second_number))
echo "Sum of $first_number and $second_number: "$sum
Output:
Enter 1st number:10
Enter 2nd number:20
Sum of 10 and 20 :30