Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
44 views71 pages

FSD Week 3 Session 1

By the end of the session, participants should have a solid understanding of basic Linux terminal commands and functionality. The document provides an overview of Linux and its history, introduces common terminal commands like ls, cd and mkdir. It also discusses installing Linux in a virtual machine and potential errors when setting up Ubuntu.

Uploaded by

vishal.pgd22028
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)
44 views71 pages

FSD Week 3 Session 1

By the end of the session, participants should have a solid understanding of basic Linux terminal commands and functionality. The document provides an overview of Linux and its history, introduces common terminal commands like ls, cd and mkdir. It also discusses installing Linux in a virtual machine and potential errors when setting up Ubuntu.

Uploaded by

vishal.pgd22028
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/ 71

Linux Essentials

The Terminal
By the end of the session:

By the end of the session, you should have clarity on the terminal-based
commands and have a solid understanding of the basic functioning and
commands in Linux (Ubuntu).
Poll Time

Q. Which of the following is not a popular operating system?

a. Windows

b. MacOS

c. Ubuntu

d. Azure
Poll Time

Q. Which of the following is not a popular operating system?

a. Windows

b. MacOS

c. Ubuntu

d. Azure
What is Linux?
Where does the Operating System Fit In?

User 1 User 2 User 3

System Application
Softwares Softwares
Software

Operating System

Hardware CPU RAM I/O


Need for Linux and Its History

1991 Linus Torvalds introduces the Linux Kernel

1992 Linux was re-licensed under the GNU GPL

1993 Slackware 1.0 was released, and the Debian distribution was established

1994 Release of version 1.0

1996 Release of version 2.0

1998 Release of version 1 of KDE Desktop version

1999 Release of version 2.2 and GNOME 1.0

2001 Release of version 2.4

2003 Release of version 2.6

2022 Release of version 6.0


What is Linux?

• Linux is an open-source operating system that is like Unix.


• It was first released on 17th September 1991 by Linus Torvalds.
• Offers a command-line interface as well as a Graphical User Interface (GUI).
• Linux powers servers, personal computers, embedded systems, smart TVs, and
other devices.
• Android is based on Linux.
• Linux is open-source, meaning its source code can be used, modified, and
distributed by anyone.
• Since it is free, it is extremely popular across all industries and sectors.
Pop Quiz

Q. What is the primary benefit of using open-source software?

a. It is always more reliable than proprietary software

b. It is always more secure than proprietary software

c. It is free to use and can be modified to meet specific needs

d. It is easier to use than proprietary software


Pop Quiz

Q. What is the primary benefit of using open-source software?

a. It is always more reliable than proprietary software

b. It is always more secure than proprietary software

c. It is free to use and can be modified to meet specific needs

d. It is easier to use than proprietary software


Why Should You Learn Linux?

• Linux powers most of the web infrastructure on the internet.


• A software developer will almost always cross paths with a Linux command-line-
based environment.
• Knowledge of Linux commands will help you work efficiently with development
and deployment.
• When working with remote servers, you have to work with Linux commands on a
terminal/console.
• It is easy to learn Linux by installing Ubuntu or similar distributions using a virtual
machine.
Ubuntu - Installation
Installation - Mac Users

If you're on a Mac, you do not need to install Ubuntu as MacOS is a *-nix-based OS. This
means that most (if not all) commands that work on Ubuntu will work natively on a macOS
terminal. Just open the terminal and get typing.
Installation - Windows Users

If you're on Windows, use VirtualBox to set up Ubuntu, as demonstrated in the


Week 3 > Introduction to Linux > Setting up Environment video on PRISM.

VirtualBox let’s you set up a virtual computer (a virtual machine) that co-exists
with your Windows environment and lets you configure it the way you want.
Once set up, you will have an Ubuntu machine running natively inside a
VirtualBox VM.
Installation - Windows Users

Pre-requisites:

• A Windows Computer with 8Gb RAM (preferred).

• ~ 20 - 30 GB of free hard disk space.

• A processor that supports Intel VT-x or AMD-v hardware virtualization enabled


in the BIOS.
Installation - Windows Users

Alternative Solutions (If you do not want to use Ubuntu on VirtualBox):

• Use the Windows Subsystem for Linux- https://docs.microsoft.com/en-


us/windows/wsl/about

• Setup a free Google Cloud Platform (GCP) account and use a Virtual Machine
Poll Time

Q. Which animal features on the logo of Linux?

a. Octopus

b. Penguin

c. Cat

d. Dolphin
Poll Time

Q. Which animal features on the logo of Linux?

a. Octopus

b. Penguin

c. Cat

d. Dolphin
Debugging Errors

Let’s discuss the common roadblocks that may come across when installing Ubuntu.
Pop Quiz

Q. Does VirtualBox affect the existing files on a Windows machine?

a. Yes

b. No
Pop Quiz

Q. Does VirtualBox affect the existing files on a Windows machine?

a. Yes

b. No
Installation - Windows Users

Commonly faced errors and solutions:

• Error: Failed to open a session for the virtual machine Ubuntu.


• Solution video: https://bit.ly/sessionfail01

• Error: VirtualBox failed to open the session for the virtual machine,
E_FAIL (0x80004005).
• Solution video: https://bit.ly/sessionfail02
Introduction to Linux
Commands
Shell and Command Line

The command line is a text-based interface using which you give “commands” to your
system to perform certain activities. In the early 70s, the only way one could interact with
a computer was the command line or “Shell”.
Writing Commands in Linux

To execute a command in the Linux command prompt, type the command


and the related arguments on the shell.

For example :

ls command to see a list of all the files and folders in the current directory.

ls with an option, hyphen l (or dash l). The hyphen l option stands for long
listing, which gives more information.

ls -l abc

The command Related arguments


Command
itself
options
Pop Quiz

Q. Which command can be used to find additional information about


the file listing in the "ls" command?

a. -d

b. -a

c. -l

d. -f
Pop Quiz

Q. Which command can be used to find additional information about


the file listing in the "ls" command?

a. -d

b. -a

c. -l

d. -f
Writing Commands in Linux

A command can have multiple options.


ls – a is user to show all files.
ls -a –l abc
Name of the Related arguments
command Command
options
Multiple commands can be written in a single line.
ps command is used to find all the processes instead of using the show processes or list processes
command.

ps -ax | grep "bash"

Name of the command Pipe to stitch two commands


File and Directories in Linux

• Files are collections of information representing text data, photos,


documents, source code, databases, and other things.
• Linux files are stored in a single-rooted, hierarchical file system.
• Files are stored in different directories (folders) that can be nested inside
other directories.
• Irrespective of what type of files are stored, users can create, delete, modify
or compress files from the command line.

Types of Files:
Internally the files are segregated into two major kinds:
1. Text files
2. Binary files
Pop Quiz

Q. Which of the following operations can be performed on a file from


the terminal?

a. Create

b. Rename

c. Delete

d. All the above


Pop Quiz

Q. Which of the following operations can be performed on a file from


the terminal?

a. Create

b. Rename

c. Delete

d. All the above


Basic Linux Commands

Commands​ Description​

date​ Current date, day of the week, time zone, etc.​


cal Shows the calendar​

clear​ Clears the screen​

bc Launches a calculator​

pwd Shows the name of the current working directory


cd​ Helps to change directory​

..​ Used with cd, takes to the parent directory​

mkdir Make a new directory​


Navigate Between Directories Using “cd"

Irrespective of where you start, you can navigate through various directories. To navigate
through the directory:

1. List down the directories within your current directory by typing ls.
2. Move to any of these directories by typing cd. This command stands for change directory.
Pop Quiz

Q. Which command would take you to the home directory from


anywhere in the system?

a. cd

b. cd home

c. cd /HOME

d. cd ../home
Pop Quiz

Q. Which command would take you to the home directory from


anywhere in the system?

a. cd

b. cd home

c. cd /HOME

d. cd ../home
Basic Commands
Basic File Operations and Commands in Linux

Create a file:

Some of the command-based editors are vi or vim editor and nano editor.

To create a file, type:

touch Hogwarts.txt

This will create a text file. You can open the file using vim by running

vi Hogwarts.txt
Basic File Operations and Commands in Linux

Create a directory:
The command used to make a new directory in Linux is mkdir.

For example:
mkdir my-website : This command will create a new directory named "my-website."

Some commonly used options with this command are:

• The –p command can create many directories by specifying a path.

• The mkdir -p x/y will create directory x if it doesn't exist. Then it will create directory y inside
directory x.

• The -m mode option is used to create directories with specific permissions (read, write, or
execute).
Basic File Operations and Commands in Linux

Copy files and directories :

The cp command is used to copy one or multiple files/folders from a source to a


destination.

Syntax: cp [option] [source] [destination]

Here are different variants of cp command:

Copy a file to another location:

cp path/to/source_file.ext path/to/target_file.ext

Copy a file into another directory, keeping the filename:

cp path/to/source_file.ext path/to/target_parent_directory
Poll Time

Q. Which of the following is not a built-in text editor on a Linux


machine?

a. vscode

b. vi

c. vim

d. nano
Poll Time

Q. Which of the following is not a built-in text editor on a Linux


machine?

a. vscode

b. vi

c. vim

d. nano
Basic File Operations and Commands in Linux

Copy files and directories :

Recursively copy a directory's contents to another location (if the destination


exists, the directory is copied inside it):

cp -R path/to/source_directory path/to/target_directory

Verbose mode -v

cp -i : Interactive mode (i) will ask the user to overwrite before copying the file by
prompt.

Example:

$ cp -i a.txt b.txt
cp: overwrite 'b.txt'? y
Basic File Operations and Commands in Linux

Move or rename a file:

The mv command is used to move any file from a source directory to a


destination directory. It can also be used to rename a file or folder.

Syntax : mv [option] [source] [destination]

Example:

mv sample.txt dir1
mv oldname.txt newname.txt

Some commonly used options with this command are:

mv –f : forcefully move
mv -i : interactive mode
mv –n : prevent overriding of an existing folder
Basic File Operations and Commands in Linux

Remove a file or a directory:

The rm command is used to remove any file from a source directory.

Syntax : rm [option] file

Example:

rm sample.txt
rm dir1

Some commonly used options with this command are:

rm –f : forcefully delete
rm -i : interactive mode
rm -r : recursive deletion deletes all the files as well as directories from the parent directory
Pop Quiz

Q. Can the "mv" command be used to rename a file or folder?

a. Yes

b. No
Pop Quiz

Q. Can the "mv" command be used to rename a file or folder?

a. Yes

b. No
User Management Commands
User Management Commands

Linux is a multi-user operating system; several people may be logged in and


actively working on a given machine at the same time.

To create users "useradd" command is used.


Syntax: useradd [options] username

Example :
sudo useradd jane

This command will create a user jane so that she has a home directory and can
log in.

Some commonly used options with this command are:

-d : option along with the location of the new home directory, creates a user in
the new home directory.
-u : create users with custom user ID.
-g : create users with specific group ID.
User Management Commands

To create the user Jane with a home directory and login, use the command:

sudo useradd -m jane

When this command is executed, it will ask for a password to create the user.
Once done, the command creates the user and the user's home directory to
match the username.

To update the password for user jane, type:

sudo passwd jane


Poll Time

Q. Which of the following flags can be used to create users with a


custom user ID?

a. -d

b. -g

c. -i

d. -u
Poll Time

Q. Which of the following flags can be used to create users with a


custom user ID?

a. -d

b. -g

c. -i

d. -u
Creating a Group

• To create the group "training" use the command:


sudo groupadd training

• Now you want to add a new user, Jane, to the group training. For this,
type:
sudo usermod -a -G training jane

• The -a option tells usermod that you are appending, and the -
G option tells usermod that you are appending to the group name that
follows the option.

• To ensure user "jane" is part of the training group, type:


sudo usermod -g training jane
Change Users

• The command su is used to switch users the terminal way.

Example:
su jane

• Root is the superuser. It is more like the administrator with super privileges.
Only root can create users and groups. sudo is a command that provides any
user with superuser's privileges.

Example:
sudo su root
Pop Quiz

Q. Which of the following grants root user access for any command?

a. super

b. root

c. sudo

d. boss
Pop Quiz

Q. Which of the following grants root user access for any command?

a. super

b. root

c. sudo

d. boss
File Permissions
Permissions

There are three different permissions you can have in Linux:

Read
1. Read: Allows someone to Write
read the content of a file or a Execute
directory.
Read
2. Write: Allows someone to Write
write to the content of a file. Execute

3. Execute: Allows someone to Read


execute the program. Write
Execute
Permissions

To find the permissions on a file, type the command ls -l.

From the right. r-- are the permissions for others. It means only read permissions
for this file & no write or execute permissions.

The next set is for a group, read and write for group members, but no execution
permission, which makes sense as this is not really an executable file.

Finally, the first set of permissions for the user John himself, John also has read and
write permissions.
Permissions

• To change the permission of a file: command chmod is used.

• Use this command to set permissions (read, write, execute) on a


file/directory for the owner, the group and others.

Syntax:
chmod permissions filename

Example:
• chmod o+w filename.txt to add write permissions for others.
• chmod -w filename.txt to remove write permissions for everyone.
• chmod g+w filename.txt to add write permissions for group.
• chmod o-r filename.txt to remove read permissions for others.
• chmod +x filename.txt to add execute permissions for all.
Pop Quiz

Q. Which of the following commands is used for a "read" permission?

a. chmod +w filename.txt

b. chmod +r filename.txt

c. chmod +o filename.txt

d. chmod +g filename.txt
Pop Quiz

Q. Which of the following commands is used for a "read" permission?

a. chmod +w filename.txt

b. chmod +r filename.txt

c. chmod +o filename.txt

d. chmod +g filename.txt
Activity

Part 1

1) Create a folder called 'hogwarts' on the desktop.


2) Add four sub-folders inside this folder called 'gryffindor', 'hufflepuff',
'ravenclaw', 'slytherin'.
3) Add four files inside the folder 'gryffindor' called 'harry.txt', 'hermoine.txt',
'ron.txt', 'draco.txt'.
4) Move the file 'draco.txt' to 'slytherin' folder.
5) Open the file 'harry.txt' in vim editor and add the following text: "The boy
who lived“.
6) [Optional] Add some content in other files. Should be fun if you are a
potterhead like us.
7) Change permissions on the 'hufflepuff' folder to 'rwx------' ie. Only the
owner has permission to read, write and execute.
Activity

Part 2

1) Create a user with the name 'sherlock'. Remember to use '–m' so sherlock
has its own home directory.
2) Set a password for 'sherlock'. Log in as 'sherlock' and Create a file named
watson.txt inside the home directory for 'sherlock'
3) Change permission on 'watson.txt' to 'rw-rw----’ which means only the owner
and group can read and write the file.
4) Type 'exit' to exit the session as 'sherlock'. Verify that you can open the file
'watson.txt' using vim.
Summary

• Linux along with its distributions (distros) is a leader in the OS industry and powers the
computing infrastructure on servers across the world.

• You can create directories using mkdir.

• You can change the directory using cd.

• You can copy and move files/folders using cp and mv command.

• You can create files using touch.

• sudo is a superpower that grants a user with administrative privileges.

• Linux provides parallel computing with multiple users sharing the computing power.

• You can create another user using 'useradd' and groups using 'groupadd’.

• You can change permissions using 'chmod' command.


Session
Feedback
Next Session:
Working with Linux​

Thank You

Copyright © Knowledgehut Upgrad., All rights reserved


Confidential Information, intended for approved distribution list of Knowledgehut Upgrad

You might also like