0% found this document useful (0 votes)
47 views

Rishabh Linux File

The document discusses Linux commands for file operations, user management, and editing files. It provides examples of commands like ls, cd, touch, cp, mv, rm, cat, less, whoami and who. It also discusses the vi text editor and creating and navigating directories and files in Linux.

Uploaded by

rish212004
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views

Rishabh Linux File

The document discusses Linux commands for file operations, user management, and editing files. It provides examples of commands like ls, cd, touch, cp, mv, rm, cat, less, whoami and who. It also discusses the vi text editor and creating and navigating directories and files in Linux.

Uploaded by

rish212004
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

Linux Assignment

Submitted by: Rishabh


Bhardwaj

Batch: 23
SAP ID: 500119057
Roll No: 713
Submitted To: Mr. Arun Singh Bhadhwal
Ques) What is Linux.

Ans) Full Form of LINUX is Lovable Intellect Not Using XP. Linux was built by and
named after Linus Torvalds. Linux is an open-source operating system for servers,
computers, mainframes, mobile systems, and embedded systems. Requests from
device software are handled by Linux and relayed to computer hardware.

Step 1: Open Terminal

Step 1: Open Terminal


PRACTICE SOME BASIC COMMANDS ON LINUX

 basic navigation commands:


1. ls (list):

display the contents of a directory. ls is a Linux shell command that lists


directory contents of files and directories. It provides valuable information
about files, directories, and their attributes.

Syntax of ls command in Linux

ls [option] [file/directory]

ls will display the contents of the current directory. By default, ls lists files and
directories in alphabetical order.

2.cd (change directory):


move between directories

cd command in Linux known as the change directory command. It is used to


move efficiently from the current working directory to different directories in
our System.

Syntax of the cd command in Linux

cd [directory]

Here, replace [directory] with the path of the destination directory you want to
navigate to.

2. pwd (print working directory):


show the current directory

pwd stands for Print Working Directory. It prints the path of the working
directory, starting from the root. pwd is shell built-in command(pwd) or an
actual binary(/bin/pwd). PWD is an environment variable that stores the path
of the current directory. This command has two flags.

Syntax of pwd command in Linux

pwd [OPTIONS]

This command doesn’t have any arguments or options, but it can accept flags
for specific behaviour.

Mkdir (directory):
create new directories

mkdir command in Linux allows the user to create directories (also referred to
as folders in some operating systems). This command can create multiple
directories at once as well as set the permissions for the directories. It is
important to note that the user executing this command must have enough
permission to create a directory in the parent directory, or he/she may receive
a ‘permission denied’ error.
Syntax:

mkdir [options...] [directories ...]

https://usatrendings.net/

3. rmdir (remove directory):


remove empty directories

The rmdir command is useful when you want to remove the empty directories
from the filesystem in Linux. This command lets you specify the terminal
to remove a particular directory right from the terminal. However, having
correct knowledge of the rmdir command is essential, or you may end up
deleting any important directory.

 File Operations: introduce fundamental file operations using


the following commands:
1. touch:
Create new files

The touch command is a standard command used in UNIX/Linux operating


system which is used to create, change and modify timestamps of a file.
Basically, there are two different commands to create a file in the Linux
system which is as follows:

 cat command : It is used to create the file with content.


 touch command: It is used to create a file without any content. The file
created using touch command is empty. This command can be used when
the user doesn’t have data to store at the time of file creation.
2. cp(copy):
copy files and directories

cp stands for a copy. This command is used to copy files or groups of files
or directories. It creates an exact image of a file on a disk with a different
file name. cp command requires at least two filenames in its arguments.

Syntax:

cp [OPTION] Source Destination

cp [OPTION] Source Directory

cp [OPTION] Source-1 Source-2 Source-3 Source-n Directory

The first and second syntax is used to copy the Source file to the Destination
file or Directory. The third syntax is used to copy multiple Sources(files) to
the Directory.

3. mv(move):
move or rename file and directories

In UNIX-based operating systems like Linux and macOS, mv stands for


“move”. But in this article, we will be talking about the “mv command in
Linux”. As its name suggests this command is used to rename file
directories and move files from one location to another within a file system.

Two Distinct Functions of mv Command

 1) Renaming a file or directory.


 2) Moving a file or directory to another location

Syntax for the mv command in Linux


Syntax: mv [options(s)] [source_file_name(s)] [Destination_file_name]
4. rm(remove):
delete file and directories

rm stands for remove here. rm command is used to remove objects such as


files, directories, symbolic links and so on from the file system like UNIX.
To be more precise, rm removes references to objects from the filesystem,
where those objects might have had multiple references (for example, a file
with two different names). By default, it does not remove
directories. This command normally works silently and you should be very
careful while running rm command because once you delete the files then
you are not able to recover the contents of files and directories.

Syntax:

rm [OPTION]... FILE...

 File viewing and editing: introduce commands for viewing


and editing files, such as:

1. cat:
display file contents

Cat(concatenate) command is very frequently used in Linux. It reads


data from the file and gives its content as output. It helps us to create,
view, and concatenate files. So let us see some frequently used cat
commands.

Syntax: cat file_name


2. less and more:
view files with pagination

less:

Less command is a Linux utility that can be used to read the contents of
a text file one page (one screen) at a time. It has faster access because if
a file is large, it doesn’t access the complete file, but accesses it page by
page. For example, if it’s a large file and you are reading it using any
text editor, then the complete file will be loaded to the main memory.
The less command doesn’t load the entire file but loads it part by part
which makes it faster.

Syntax of less command in Linux

The basic syntax of the less command is as follows:

less [options] filename

more:

more command is used to view the text files in the command prompt,
displaying one screen at a time in case the file is large (For example log
files). The more command also allows the user do scroll up and down
through the page. The syntax along with options and command is as
follows. Another application of more is to use it with some other
command after a pipe. When the output is large, we can use more
command to see output one by one.

Syntax:

more [-options] [-num] [+/pattern] [+linenum] [file_name]

 user management: discuss commands for user management


tasks, including

1. whoami:
display the current user

whoami command is used both in Unix Operating System and as well as


in Windows Operating System.

 It is basically the concatenation of the strings “who”, “am”,


 “i” as whoami.
 It displays the username of the current user when this command is invoked.
 It is similar as running the id command with the options –un\

2. who:
show users currently logged in
who command is used to find out the following information:
1. Time of last system boot
2. Current run level of the system
3. List of logged in users and more.
Description: The who command is used to get information about currently
logged in user on to system.
Syntax: $who [options] [filename]

 VI
EDITOR:
The default editor that comes with the UNIX operating system is
called vi (visual editor). Using vi editor, we can edit an existing file or create a
new file from scratch. we can also use this editor to just read a text file. The
advanced version of the vi editor is the vim editor.
How to open VI editor?

To open vi editors, we just need to type the command mentioned below.


vi [file_name]

EXPERIMENT 3:
(i) Files and Directories commands
Working with Files:
1. touch: Create an empty file or update the access/modify timestamps of an
existing file.
2. cp: Copy files and directories.
3. mv: Move or rename files and directories.
4. rm: Remove files and directories.
5. cat: Concatenate and display the contents of a file.
6. less: Display the contents of a file one page at a time.
7. head: Display the first few lines of a file.
8. tail: Display the last few lines of a file.

STEP 1: Make directory by mkdir command and then move to that particular directory
by cd command.

Syntax: mkdir (directory name)


Syntax: cd (directory name)
Syntax: touch (file name.ext)
STEP 2: Create 2 files by txt extension.

STEP 3: Use cat command to concentrate/ display the contents of the file. Then use cp
command to copy the file. And in the end by ls command, the result will be displayed.
Syntax: cat (file name)

Syntax: cp (file name) (file name)


STEP 4: Use mv command to move files from one directory to another, then use ls
command to display the output
Syntax: mv (file name) ~/(directory name)
terSyntax: ls ~/(directory name)

STEP 5: Remove files one by one in one directory by rm command.


Syntax: rm (file name.ext)

(ii)
(iii) File Permissions and Ownership:

I} Explain the ls -l command to display detailed file information, including permissions


and ownership-

The ls is the list command in Linux. It will show the full list or content of your
directory.
o -l: It stands for long format. It shows Unix file types, number of hard links,
permissions, group, owner, last modified name and date-time, and size.
If the changed date is older than six months, the time is substituted with
the year. A few implementations add extra flags to permissions
II} Discuss the three sets of permissions: owner, group, and others.

Read, write and execute:


Letters
‘r’ “read” the file’s contents.
‘w’ “write”, or modify, the file’s contents.
‘x’ “execute” the file. This permission is given only if
the file is a program.

When permissions and users are represented by letters, that is called symbolic mode.
The first digit is for owner permissions, the second digit is for group permissions, and
the third is for other users. Each permission has a numeric value assigned to it:

 r (read): 4
 w (write): 2
 x (execute): 1

These are called octal values.

For example, a file might have read, write, and execute permissions for its owner, and
only read permission for all other users. That looks like this:

 Owner: rwx = 4+2+1 = 7


 Group: r-- = 4+0+0 = 4
 Others: r-- = 4+0+0 = 4

User, group and others:

Reference Class Description

The user permissions apply only to the owner of the file or


‘u’ User directory.

The group permissions apply only to the group that has been
‘g’ Group assigned to the file or directory.

‘o’ Others The other permissions apply to all other users on the system.

‘a’ All All three [owner, groups, others]


Symbols ‘+’, ‘-‘ and ’=’

Operators Definition

‘+’ Adds permission

‘-‘ Removes permission

‘=’ Set the permissions to the specified value

III} Explain the chmod command to modify file permissions and discuss the chown and
chgrp commands to change file ownership and group-

We can modify file and directory permissions with the chmod command, which stands
for "change mode." To change file permissions in numeric mode, you enter chmod and
the octal value you desire. To change file permissions in symbolic mode, you enter a
user class and the permissions you want to grant them next to the file name. For
example:

$ chmod ug+rwx example.txt


$ chmod o+r example2.txt

These grants read, write, and execute for the user and group, and only read for others.

Symbolic mode Representation


chmod u Permits for the user owner.
chmod g Other users in the file's group
chmod o Other users not in the file's group
chmod a For all users
chown Change the user owner itself
chgrp Change the group ownership of a file
Syntax: sudo chgrp [new group team name] [file name]

Chmod command in symbolic mode: Adding permissions

(iv) Advanced File and Directory Operations:


find: Search for files and directories based on various criteria.

grep: Search for specific patterns within files.


tar: Archive files and directories into a single file.

gzip/gunzip: Compress and decompress files.


ln: Create hard and symbolic links
EXPERIMENT: 4

 What is a “Shell”?
It is a program that provides the user an interface to use operating system services.

 Different Types of Shells: There are eight types of shells in Linux:


a. Bourne Shell (sh)
b. C Shell (csh)
c. TENEX C Shell (tcsh)
d. Korn Shell (ksh)
e. Debian Almquist Shell (dash)
f. Bourne Again Shell (bash)
g. Z Shell (zsh)
h. Friendly Interactive Shell (fish)

1. Write a simple shell script that prints “Hello, World!” when executed.

a. Creating a shell file with .sh extension.

All Codes done till now:

Can be obtained by using the command history.


-------------------------------------------------Thank You !! --------------------------------------------

You might also like