Unit I

Download as pdf or txt
Download as pdf or txt
You are on page 1of 21

Linux Notes Unit I

1. What is operating System?


• An operating system is a program that manages computer hardware and
software for the user.
• It is designed to perform repetitive hardware tasks, such as managing
files,running programs and receiving commands from the user.
• It also manages software applications.
• It controls the loading and execution of all programs.
• File management , program management, and user interaction are
traditional features common to all operating system
• MS_DOS,Windows,Unix,Linux,Android.
2. What is Linux ?
• Linux is operating system
• It is a multiuser multitasking operating system.
• As it is multitasking system, you can ask the system to perform several
tasks at the samr time.
• As it is multiuser system, several users can log in to the system at the
same time, each interact with the system through his or her own
terminal.

3. What are the different points which make GUI more user friendly
compare to command line interface?
GUI CLI
It stands for Graphical User Interface It stands for Command Line
Interface.
A type of user interface that allows An interface for the user to issues
users to interact through graphical commands in the form of successive
icons and visual indicators. line of text or command lines to
perform the tasks.
Every user can easily handle. A user should have good knowledge
of commands.
Requirment of memory is more as it Requirement of memory is less.
contains many graphical components.
It is more flexible. It is less flexible.
It is slow It is fast.
There are many options to change the There are no options to change the
appearance. appearance.
4. Define different terminology used in Linux?
Following are the different terminology used in Linux:
1. Command: It enables you to give instruction to the operating system.
2. Shell : Shell is a command interpreter for checking syntax on command
prompt , passes to kernel for execution and throws exception if problem
in syntax.
3. Sservice: There are various services provided by Linux which can be
either be an background process or foreground process. You need to
start and stop services as and when needed.
Linux Notes Unit I
4. Desktop Environment: It is a GUI provided at the top of your
operating system. The command desktop environments in Linux are
GNOME and KDE.
5. Pacakages:Packages contain a program or part of a program that is
needed to r un any software on Linux. Packages can be installed using
terminal or a package.
6. Terminal: It is primary way, a interface , to interact with files and
programs. Terminal are used for executing commands, running scripts
and installing.
7. Root: Linux has user specific roles. A root account has full access to
the system, that is access to every command and file in the system. The
root user is also called super user.
8. Sudo: In Linux, sudo is used for executing commands as superuser
when you are logged in as any user.Sudo makes sure that core files are
accessed or changed by a user .
9. Repositories
Repositories are like the storage of a computer, served at online sources.
They contain packages and source code that we can download and use
in our system via software manager or package manager, and terminal.
10. Package Manager
Package Manager is a tool that provides you with a graphical interface
to help you find new packages, then install, update, and even configure
them.Two of the major package management system for Linux: dpkg
and rpm. The dpkg was originally for Debian systems but is now
employed by Ubuntu. RPM was created for Red Hat Linux distribution
but now is used by Fedora and others
11. Kernel
‘Kernels’ is the heart of Linux. kernel manages your system’s hardware,
along with all the programs on your computer. The base Linux kernel is
open-source, and it provides the core for a lot of distributions, some of
which modify that code to better suit their particular goals.
12. Distribution:
A distribution of Linux is a bundled variation of Linux. There are a
number of major distributions such as Ubuntu, Fedora, Debian

5. Explain in brief hard link and soft link with suitable example.
1. Hard Links
• Each hard linked file is assigned the same Inode value as the original,
therefore they reference the same physical file location. Hard links more
flexible and remain linked even if the original or linked files are moved
throughout the file system, although hard links are unable to cross
different file systems.
• Links have actual file contents
• Removing any link, just reduces the link count, but doesn’t affect other
links.
• We cannot create a hard link for a directory to avoid recursive loops.
Linux Notes Unit I
• If original file is removed then the link will still show the content of the
file.
• Command to create a hard link is:
• $ ln [original filename] [link name]
2. Soft Links
• A soft link is similar to the file shortcut feature which is used in Windows
Operating systems. Each soft linked file contains a separate Inode value
that points to the original file. As similar to hard links, any changes to the
data in either file is reflected in the other. Soft links can be linked across
different file systems, although if the original file is deleted or moved, the
soft linked file will not work correctly (called hanging link).
• Soft Link contains the path for original file and not the contents.
• Removing soft link doesn’t affect anything but removing original file, the
link becomes “dangling” link which points to nonexistent file.
• A soft link can link to a directory.
• Link across filesystems: If you want to link files across the filesystems,
you can only use symbolic links/soft links.
• Command to create a Soft link is:
$ ln -s [original filename] [link name]
6. What is the architecture of linux? Explain.
Linux Architecture

The Linux system works basically on 4 layers. First view the diagram below,
which is showing the architecture of a Linux System.

• Hardware − Hardware consists of all physical devices attached to the System.


For example: Hard disk drive, RAM, Motherboard, CPU etc.
Linux Notes Unit I
• Kernel − Kernel is the core component for any (Linux) operating system which
directly interacts with the hardware.
• Shell − Shell is the interface which takes input from Users and sends
instructions to the Kernel, Also takes the output from Kernel and send the result
back to output shell.
• Applications − These are the utility programms which runs on Shell. This can
be any application like Your web browser, media player, text editor etc.

7. Explain Linux features.


 Multiuser capability: Multiple users can access the same system
resources like memory, hard disk, etc. But they have to use different
terminals to operate.
 Multitasking: More than one function can be performed simultaneously
by dividing the CPU time intelligently.
 Portability: Portability doesn't mean it is smaller in file size or can be
carried in pen drives or memory cards. It means that it support different
types of hardware.
 Security: It provides security in three ways namely authenticating (by
assigning password and login ID), authorization (by assigning
permission to read, write and execute) and encryption (converts file into
an unreadable format).
 Live CD/USB: Almost all Linux distros provide live CD/USB so that
users can run/try it without installing it.
 Graphical User Interface (X Window system): Linux is command
line based OS but it can be converted to GUI based by installing
packages.
 Support's customized keyboard: As it is used worldwide, hence
supports different languages keyboards.
 Application support: It has its own software repository from where
users can download and install many applications.
 File System: Provides hierarchical file system in which files and
directories are arranged.
 Open Source: Linux code is freely available to all and is a community
based development project.
Linux Notes Unit I
8. Difference between Linux and Unix
Linux Notes Unit I
9. What are Commands?
• A command is an instruction given to our computer by us to do
whatever we want. In Mac OS, and Linux it is called terminal, whereas,
in windows it is called command prompt. Commands are always case
sensitive.
• Commands are executed by typing in at the command line followed by
pressing enter key.

10. Command:
1. Pwd
Linux pwd (print working directory) command displays your location currently
you are working on. It will give the whole path starting from the root ending to
the directory.

Syntax:
pwd

2. cd
Linux cd command is used to change the current working directory ( i.e., in
which the current user is working). The "cd" stands for 'change directory.' It is
one of the most frequently used commands in the Linux terminal.

Syntax:
cd <dirname>

1) Change from the current directory to a new directory


We can change our directory from the current working directory to a specified
directory. To display the current working directory, execute the command as
follows:

pwd

To change our current working directory, execute the command as follows:

cd < current directory> <specified directory>


Linux Notes Unit I

2) Change directory using an absolute path


To change the directory by using an absolute path, we have to mention the
whole path starting from the root. Consider the below example:

3) Change directory using a relative path


We can change our directory by using a relative path; a relative path is a
location that is relative to the current directory.

4) Change to the home directory


To change the directory to home directory from the current working directory,
execute the command as follows:

cd ~

5) Change to the root directory


To navigate directory to entire system's root directory from current working
directory, execute the command as follows:

cd /

3. Ls command
The ls is the list command in Linux. It will show the full list or content of your
directory. Just type ls and press the enter key. The whole content will be shown.

Syntax:

ls
Linux Notes Unit I

a. ls -a command
It will give you the whole list of a directory including the hidden files also.
In Linux, hidden files start with a dot (.) and can't be seen in the regular
directory.
Syntax:
ls -a

b. ls -l command
The ls command will only display the files. But if you want your files to be
displayed in a long list format, then you can use ls -l command.

Syntax:

ls -l

Columns above indicate specific things:


Column 1 indicates information regarding file permission.
Column 2 indicates the number of links to the file.
Column 3 & 4 indicates the owner and group information.
Column 5 indicayes size of the file in bytes.
Column 6 shows th date and time on which the file was recently modified.
Column 7 shows the file or directory name.

c. ls ~
Linux ls ~ command shows the contents of the home directory.
Linux Notes Unit I
Syntax:
ls ~

d. List Files with Human Readable Format


shows sizes in a human-readable format.
Syntax:
ls -lh

e. List Files in Reverse Order in Linux


The following command with the ls -r option display files and directories
in reverse order.
Syntax:
ls -r

f. Display Inode number of File or Directory


We can see some numbers printed before the file/directory name.

4. mkdir
The mkdir stands for 'make directory'. With the help of mkdir command, you
can create a new directory wherever you want in your system. Just type "mkdir
<dir name> , in place of <dir name> type the name of new directory, you want
to create and then press enter.

Syntax:
Linux Notes Unit I
mkdir <dirname>

To make multiple directories


Syntax:
mkdir <dirname1> <dirname2> <dirname3> ...

5. rmdir
This command is used to delete a directory. But will not be able to delete a
directory including a sub-directory. It means, a directory has to be empty to be
deleted.

Syntax:
rmdir <dirname>

rmdir -p
This command will delete a directory including its sub-directories all at once. In
below picture, all sub-directories have been deleted with 'rmdir -p' command.

6. File command
Linux Notes Unit I
file command is used to determine the file type. It does not care about the
extension used for file. It simply uses file command and tell us the file type. It
has several options.

Syntax:
file <filename>

7. touch
touch command is a way to create empty files (there are some other mehtods
also). You can update the modification and access time of each file with the
help of touch command.

Syntax:
touch <filename>

touch -a command
touch command with option 'a' is used to change the access time of a file. By
default, it will take the current time of your system.

Syntax:
touch -a <filename>
Linux Notes Unit I

touch -m command
The touch '-m' option will help you to change only the modification time of a
file.
Syntax:
touch -m <filename>

touch -r
This command will update time with reference to the other mentioned
command.
Syntax:
touch -r demo.txt Demo.txt
Linux Notes Unit I

touch -t command
with this command, you can change the access time of a file by determining a
specified time to it.

It will modify the time by specified time instead of default time.


Syntax:
touch -t YYYYMMDDhhmm.ss
Linux Notes Unit I

8. rm
The 'rm' means remove. This command is used to remove a file. The command
line doesn't have a recycle bin or trash unlike other GUI's to recover the files.
Hence, be very much careful while using this command. Once you have deleted
a file, it is removed permanently.

Syntax:
rm <filename>

rm *extension
This command can be used to remove all the files ending with same extensions
like .pdf, .txt, .odt, .png, etc.

Syntax:
rm *<extension>
Linux Notes Unit I

rm -r
With rm '-r' option, you can delete a directory having sub directories inside it.
So you don't need to delete sub-directories manually.

Syntax:
rm -r <dirname>

rm -i
The option 'i' stands for 'interactivity'. Before deleting a file it will ask you
whether you want to delete it or not. To delete a file use command:
Linux Notes Unit I
Syntax:
rm -i

9. cp command
'cp' means copy. 'cp' command is used to copy a file or a directory.
To copy a file into the same directory syntax will be,
Syntax:
cp <existing file name> <new file name>

cp -r
Option 'r' with the copy command can be used to copy a directory including all
its content from a source directory to the destination directory.

Syntax:
cp -r <sourceDirectory> <destinationDirectory>
Linux Notes Unit I
10. mv command
Linux mv command is used to move existing file or directory from one location
to another. It is also used to rename a file or directory.
Rename a Directory
Directories can be renamed in the same way as the files. In this case also inode
number will remain the same.

mv -i
If you want to copy a file using 'mv' option and if that file already exists then it
will silently over write the existing file.But if you'll use 'i' option then it will
first ask for your permission to over write it.

11. Linux File Contents Command


There are many commands which help to look at the contents of a file.

a. head command
The 'head' command displays the starting content of a file. By default, it
displays starting 10 lines of any file.
Linux Notes Unit I
Syntax:
head <file name>

Linux head -n
The 'head -n' option displays specified number of lines.
Syntax:
head -n <file name>

b. tail command
Linux tail command is used to display the last ten lines of one or more files. Its
main purpose is to read the error message. By default, it displays the last ten
lines of a file.

Syntax:
tail <file name>

c. Cat Command
The 'cat' command is the most universal and powerful tool. It is considered to
be one of the most frequently used commands. It can be used to display the
content of a file, copy content from one file to another, concatenate the contents
of multiple files, display the line number, display $ at the end of the line, etc.

The 'cat' command can be used to display the content of a file.


Syntax:
cat <fileName>
Linux Notes Unit I

cat command (to create a file)


The 'cat' command can be used to create a new file with greater than sign (>).

Syntax:
cat > <file name>

To Append the Content of A File


The 'cat' command with double greater than sign (>>) append (add something
in the last of a file) something in your already existing file.

Syntax:
cat >> (file name)

Linux cat command (to concatenate files)


The 'cat' command can be used to concatenate the contents of multiple files in a
single new file.

Syntax:
cat <filename1> <filename2>.... > <newFilename>
Linux Notes Unit I

cat -n command (to display line numbers)


The 'cat -n' option displays line numbers in front of each line in a file.

Syntax:
cat -n <fileName>

cat -e command (to display $)


The 'cat-e' option displays a '$' sign at the end of every line.

Syntax:
cat -e <fileName>

d. tac command

The 'tac' command is the reverse of the 'cat' command. It is also known as 'cat'
backward. It will display the file content in reverse order. It prints the last line
first, then second last and so on. Such way, it prints the first line at last.

Syntax:

tac <file name>


Linux Notes Unit I

e. more command

As 'cat' command displays the file content. Same way 'more' command also
displays the content of a file. Only difference is that, in case of larger files, 'cat'
command output will scroll off your screen while 'more' command displays
output one screenful at a time.
Following keys are used in 'more' command to scroll the page:
Enter key: To scroll down page line by line.
Space bar: To go to next page.
b key: To go to the backward page.
/ key: Lets you search the string.

Syntax:

more <file name>

f. less command

The 'less' command is same as 'more' command but include some more features.It
automatically adjust with the width and height of the teminal window, while
'more' command cuts the content as the width of the terminal window get shorter.

Syntax:

less <file name>

You might also like