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

Assignment : -Execution of various file/directory handling commands.

TOOLS: UNIX operating system/any flavor of Linux.

STANDARD PROCEDURE:
Analyzing the Problem:
Start the Linux and enter the user name and password.
Now write startx and after that open the terminal.
At the terminal try the different commands and see the output.

Designing the Solution:


At the terminal first perform the command without and with the different options
available for it. The exercises in this lab cover the usage of some of the most basic
system utilities that users and administrators alike need to be familiar with. Most of the
commands are used in navigating and manipulating the file system. The file system is
made up of files and directories.

THEORY:

1) pwd COMMAND:
pwd - Print Working Directory. pwd command prints the full filename of
the current working directory.
SYNTAX:
The Syntax is
pwd [options]

2) cd COMMAND:
cd command is used to change the directory.
SYNTAX:
The Syntax is
cd [directory | ~ | ./ | ../ | - ]

3) ls COMMAND:
ls command lists the files and directories under current working directory.

SYNTAX:
The Syntax is
ls [OPTIONS]... [FILE]
OPTIONS:
-l
Lists all the files, directories and their mode, Number of links,
owner of the file, file size, Modified date and time and filename.
-t Lists in order of last modification time.
-a Lists all entries including hidden files.
-d Lists directory files instead of contents.
-p Puts slash at the end of each directories.
-u List in order of last access time.
-i Display inode information.
4) rm COMMAND:
rm linux command is used to remove/delete the file from the directory.
SYNTAX:
The Syntax is
rm [options..] [file | directory]

OPTIONS:
-f Remove all files in a directory without prompting the user.
-i
Interactive. With this option, rm prompts for confirmation before
removing any files.
5) mv COMMAND:
mv command which is short for move. It is used to move/rename file from one directory
to another. mv command is different from cp command as it completely removes the file
from the source and moves to the directory specified, where cp command just copies
the content from one file to another.

SYNTAX:
mv [-f] [-i] oldname newname
OPTIONS:
-f This will not prompt before overwriting (equivalent to -- reply=yes). mv -f will move the
file(s) without prompting even if it is writing over an existing target. -i Prompts before
overwriting another file.

6) cat COMMAND:
cat linux command concatenates files and print it on the standard output.
SYNTAX:
The Syntax is
cat [OPTIONS] [FILE]...
OPTIONS:
-A Show all.
-b Omits line numbers for blank space in the output.

-E Displays a $ (dollar sign) at the end of each line.


-n Line numbers for all the output lines.

7) cmp COMMAND:
cmp linux command compares two files and tells you which line numbers are different.
SYNTAX:
The Syntax is
cmp [options..] file1 file2

OPTIONS:
- c Output differing bytes as characters.
-l
Print the byte number (decimal) and the differing byte values
(octal) for each difference.
- s Prints nothing for differing files, return exit status only.

8) cp COMMAND:
cp command copy files from one location to another. If the destination is an existing file,
then the file is overwritten; if the destination is an existing directory, the file is copied into
the directory (the directory is not overwritten).
SYNTAX:
The Syntax is
cp [OPTIONS]... SOURCE DEST
10) echo COMMAND:
echo command prints the given input string to standard output.
SYNTAX:
The Syntax is
echo [options..] [string]

11)mkdir COMMAND:
mkdir command is used to create one or more directories.
SYNTAX:
The Syntax is
mkdir [options] directories
OPTIONS:
-m Set the access mode for the new directories.
-p Create intervening parent directories if they don't exist.
-v Print help message for each directory created.

12) paste COMMAND:


paste command is used to paste the content from one file to another file. It is
also used to set column format for each line.
SYNTAX:
paste [options]
OPTIONS:
-s Paste one file at a time instead of in parallel.
-d Reuse characters from LIST instead of TABs .

13) rmdir COMMAND:


rmdir command is used to delete/remove a directory and its subdirectories.
SYNTAX:
The Syntax is
rmdir [options..] Directory
OPTIONS:
-p Allow users to remove the directory dir name and its parent directories which become
empty.

CONCLUSIONS:
In this way we can run different file and directory handling commands and see the
output on standard output window.
Assignment: - Shell scripts to check various attributes of files and directories.

TOOLS: UNIX operating system/any flavor of Linux.

STANDARD PROCEDURE:
Step 1: start UNIX OS in your computer and login in it and enter Username
and Password.
Step 2: Create a folder with your Id Number or Name Followed by Roll No.
Step 3: now go to your folder from the terminal and after that open the VI editor
with the desired program name with extension .sh.
Step 4: now write your program and quit back to the terminal.
Step 5: After writing program make it executable by using $chmod +x program
name.
Step 6: Now run the program using any one of the methodE
sh program name

THEORY:
Basic File Attributes - Read, Write and Execute
There are three basic attributes for plain file permissions: read, write, and execute.
Read Permission of a file
If you have read permission of a file, you can see the contents. That means you can use
more, cat, etc.
Write Permission of a file
If you have write permission of a file, you can change the file. This means you can add
to a file, or overwrite a file. You can empty a file called "yourfile" by copying the empty
(/dev/null) file on top of it cat /dev/null yourfile
Execute Permission of a file
If the file has execute permission, then you can ask the operating system to run the
file as if it were a program. If it's a binary file/program, you can execute it like any other
program. If the file is a shell script, then the execute attribute says you can treat it as if it
were a program. To put it another way, you can create a file using your favorite editor,
add the execute attribute to it, and it "becomes" a program. However, since a shell has
to read the file, a shell script has to be readable and executable. A compiled program
does not need to be readable.
The basic permission characters, "r", "w", and "x"
r means read w means write, and x means execute.

Basic Directory Attributes - Read, Write and Search


Directories use these same permissions, but they have a different meaning. Yes,
very different meanings.
Read permission on a directory
If a directory has read permission, you can see what files are in the directory. That
is, you can do an "ls" command and see the files inside the directory. However,
read permission of a directory does not mean you can read the contents of files in
the directory.

Write permission on a directory


Write permission means you can add a new file to the directory. It also means you
can rename or move files in the directory.
Execute permission on a directory
Execute allows you to use the directory name when accessing files inside that
directory. The "x" permission means the directory is "searchable" when searching
for executables. If it's a program, you can execute the program.

CONCLUSIONS:
With the help of given procedure and information about the File operators we can
write shell program to check various attributes of files and directories
Assignment: -Execution of various system administrative commands.

TOOLS: UNIX operating system/any flavor of Linux.

STANDARD PROCEDURE:
Analyzing the Problem:
Start the Linux and enter the user name and password.
Now write startx and after that open the terminal.
At the terminal try the different commands and see the output.
Designing the Solution:
At the terminal first perform the command without and with the different Options
available for it. The exercises in this lab cover the usage of some of the most basic
system utilities that users and administrators alike need to be familiar with. Most of the
commands are used in navigating and manipulating the file system. The file system is
made up of files and directories.

THEORY:
Users and Groups
Users
Show all logged on users. This is the approximate equivalent of who -q.

groups
Lists the current user and the groups she belongs to. This corresponds to the
$GROUPS internal variable, but gives the group names, rather than the numbers.
bash$ groups
bozita cdrom cdwriter audio xgrp
bash$ echo $GROUPS
501

chown, chgrp
The chown command changes the ownership of a file or files. This
command is a useful method that root can use to shift file ownership from
one user to another. An ordinary user may not change the ownership of files,
not even her own files.
root# chown bozo *.txt

The chgrp command changes the group ownership of a file or files. You
must be owner of the file(s) as well as a member of the destination group (or
root) to use this operation.

chgrp --recursive dunderheads *.data


# The "dunderheads" group will now own all the "*.data" files
#+ all the way down the $PWD directory tree (that's what "recursive"
means).
useradd, userdel
The useradd administrative command adds a user account to the system and
creates a home directory for that particular user, if so specified. The corresponding
userdel command removes a user account from the system and deletes associated
files.
The adduser command is a synonym for useradd and is usually a symbolic link to it.
Usermod
Modify a user account. Changes may be made to the password, group
membership, expiration date, and other attributes of a given user's account.
With this command, a user's password may be locked, which has the effect
of disabling the account.

groupmod
Modify a given group. The group name and/or ID number may be changed
using this command.

CONCLUSIONS:
With the help of given procedure and information about the commands we can
execute system administrative task.
Assignment: System Access

A. Logging In:--
Steps 1:- At login time, you'll see a prompt resembling the following:
Username:
Enter your user name

For Ex:
Username: root
Then, Press Enter Key

Steps 2:- Next, enter your password.


Password:
Enter your password:

For Ex:
Password: mca123
Finally, Press Enter Key.
Once you have correctly entered the user name and password, you are officially
logged in to the system.

B. Logging In and Using Remote Linux Systems:--


1. In this logging we have to logging into linux system due that environment for linux
programming is opened.
2. The remote login means to login a linux programming through application i.e. telnet,
putty or through GUI or directly through terminal.
3. Steps to login through putty are as follows:
Step 1: Click on putty icon from desktop. Icon is shown below,

PuTTY.lnk

Step 2: Enter proper Host Name (or IP address) as shown below,

Once’s you enter host name, click on “Open” button

Step 3: Once’s you enter proper host address then enter login name and password
as shown below,
Be sure about password because password is not display on screen.

Once you have correctly entered the user name and password, you are officially logged in to
the system
Assignment: Starting and Stopping Linux

A. Shutting Down a Linux System :--


a) poweroff command
f) It turns off your system completely.
[root@localhost ~]#poweroff
b) shutdown command
i) To halts your system after shutdown at 16:30PM.
[root@localhost ~]# shutdown –h 16:30

ii) To shutdown system right away used following command.


[root@localhost ~]# shutdown –h now

iii) The shutdown command can be used to restart a system with the r option
instead of the h option.
[root@localhost ~]# shutdown –r +5 “server will start within 5 minutes. Plz save
your work”.
Output:
All other logged in users will see a broadcast message in their terminal like this
[root@localhost ~]#
Broadcast message from root@dhcppc1
(/dev/tty1) at 21:35 ...

The system is going down for reboot in 5 minutes!


Server will restart in 5 minutes. Please save your work.

B. Booting a Linux System:--


a) reboot command
i) To reboot your system use following command.
[root@localhost ~]# reboot

b) shutdown command
i) The command to reboots the system after 40 minutes of issuing this command.
[root@localhost ~]# reboot –r +40
Assignment: User Accounts

A. Creating Additional User Accounts:--


a. users command
i) To Create new user.
[root@localhost ~]# useradd -m sonal

ii) To create new user upto particular date.


[root@localhost ~]# useradd -e 2014/12/13 minal

i) To see user account expires date.


[root@localhost ~]# chage -l minal
Output:
Last password change : May 21, 2007
Password expires : never
Password inactive : never
Account expires : Dec 13, 2014
Minimum number of days between password change :0
Maximum number of days between password change : 99999
Number of days of warning before password expires :7

B. Groups:--
a) Groups command
i) To create new group with specific id.
[root@localhost ~]# groupadd –g 503 family

ii) To add user (chaaya) to group(family)


[root@localhost ~]# useradd -g family chaaya

iii) To add user(amita) to multiple group(family,family1)


[root@localhost ~]# useradd -G family,family1 amita

C. Managing Users and Groups:--


a. passwd command
i) To set password to particular user.
Output:
[root@localhost ~]# passwd minal
Changing password for user minal.
New UNIX password:
Retype new UNIX password:
passwd: all authentication tokens updated successfully.

b. su command
i) It is use to switch from one user to another user.
[bca123@localhost ~]$ su root
Password:
Output:
[root@localhost bca123]#
Assignment: File system

A. File system Navigation:--


a) pwd command
g) Print name of current working directory.
[bca123@localhost mamta]$ pwd
Output:
/home/bca123/mamta

b) cd command
i) It is use to change directory.
[bca123@localhost ~]$ cd sonu

ii) grep command


i) It allows you to search one files or multiple files for lines that contain a pattern
[bca123@localhost ~]$ ps
Output:
PID TTY TIME CMD
23087 pts/20 00:00:00 bash
23106 pts/20 00:00:00 ps
[bca123@localhost ~]$ ps | grep 23087
Output:
23087 pts/20 00:00:00 bash

ii) -o display the number of matched lines


[bca123@localhost mamta]$ cat>>file2
mamta
sonia
mamta
dipali
[bca123@localhost mamta]$ grep -o di file2
Output:
di
di
di
di

d) mkdir command
i) Make directories
[bca123@localhost ~]$ mkdir mumbai

ii) -v option print a message for each created directory.


[bca123@localhost ~]$ mkdir -v rajasthan
mkdir: created directory `rajasthan'

h) rmdir command
i) Delete the particular directory.
[bca123@localhost ~]$ rmdir mumbai
ii) -p option remove Directory and its ancestors.
[bca123@localhost ~]$ rmdir -p rajasthan

B. File Oriented Commands:--


a) cat command
i) Creating new file
[bca123@localhost ~]$ cat>>city

ii) Read contain of file


[bca123@localhost ~]$ cat city
Output:
Shirpur
Dhule
Pune
Mumbai
Surat
Goa

iii) Concatting File


[bca123@localhost ~]$ cat>>city
Bhuswal
Amalner
[bca123@localhost ~]$ cat city
Output:
Shirpur
Dhule

b) head command
Display line from top to bottom
i) By default show 10 lines from top of file "city".
[bca123@localhost ~]$ head city
Output:
Shirpur
Dhule
Pune
Mumbai

ii) It will show top 5 lines.


[bca123@localhost ~]$ head -5 city
Output:
Shirpur
Dhule
Pune
Mumbai
Surat

iii) -c option units of bytes.


[bca123@localhost ~]$ head -c10 city
Output:
Shirpur
Dh

c) tail command
Display line from bottom to top
i) By default show 10 lines from bottom of file "city".
[bca123@localhost ~]$ tail city
Output:
Badnera
Jalgaon
Wagoli
Kashmir
Jammu

ii) It will show bottom 5 lines.


[bca123@localhost ~]$ tail -5 city
Output:
Srinagar
Patna
Indore
Bhusawal
Amalner

iii) -c option units of bytes


[bca123@localhost ~]$ tail -c12 city
Output:
wal
Amalner

d) cut command
i) Cut out selected fields of each line of a line.
[bca123@localhost ~]$ cut -c2 shalik2
Output:
h
e
r

ii) -c option specifies character positions.


[bca123@localhost ~]$ cat>dog
Output:
Hello Shirpur.
[bca123@localhost ~]$ cut -c 7 dog
S

iii) More word cut at one command


[bca123@localhost ~]$ date
Mon May 21 02:11:21 IST 2007
[bca123@localhost ~]$ date | cut -b 2,5
Output:
oM
iv) Use of cut command in different ways
[bca123@localhost ~]$ echo "123456789" | cut -c 5-
56789
[bca123@localhost ~]$ echo "123456789" | cut -c 5
5
[bca123@localhost ~]$ echo "123456789" | cut -c 3-5
345

e) paste command
i) Use of paste command
[bca123@localhost ~]$ cat>txt1
a
b
c

[bca123@localhost ~]$ cat>txt2


1
2
[bca123@localhost ~]$ paste txt1 txt2
Output:
a 1
b 2
c

ii) -s,-d option use -d (delimiter)and -s (serial)option


[bca123@localhost ~]$ paste -s -d: txt1 txt2
Output:
a:b:c
1:2

f) wc command
i) Short for word count, we displays a count of files, words and characters in a file.
[bca123@localhost ~]$ cat>txt5
Output:
Hi
MBM
Good luck

[bca123@localhost ~]$ wc txt5


3 4 17 txt5

ii) -c option count bytes


[bca123@localhost ~]$ wc -c txt5
Output:
17 txt5

iii) -l option count lines


[bca123@localhost ~]$ wc -l txt5
Output:
3 txt5

g) rm command
i) Remove the file permanently.
[bca123@localhost ~]$ rm rahul3

ii) -r option recursively remove directories and subdirectories in the argument list.
[bca123@localhost ~]$ rm -r amit6

h) sort command
i) It is use for sorting message in a alphabetical order of a given file.
[bca123@localhost ~]$ cat>>ram3
hi
by
why
[bca123@localhost ~]$ sort ram3
Output:
by
hi
shy
they
why

ii) -k option start a key at position 1


[bca123@localhost ~]$ sort -k 2 ram3
Output:
by
hi
shy
they

C. Locating Files:--

a) find command
i) To find particular file
[bca123@localhost mamta]$ find fib
Output:
Fib

ii) To Find all .txt files


[bca123@localhost ~]$ find -name "*.txt"
Output:
./tillu/error.txt
./vivwk/error.txt
./pankaj/arror.txt
To display all .tar files that are stored in the directory /home/bca123/vaishnavi.
[bca123@localhost ~]$ find /home/bca123/vaishnavi -name "*.tar"
Output:
/home/bca123/vaishnavi/do.tar
/home/bca123/vaishnavi/file3.tar
/home/bca123/vaishnavi/a.tar
/home/bca123/vaishnavi/file.tar
b) locate command
i) It find the file by the name.
[bca123@localhost ~]$ locate india
Output:
/home/bca123/india
/home/bca123/c2/india
/home/bca123/dhanshri25/india
/home/bca123/trupti/indian
/home/bca123/vinu29/indian
/home/bca123/vinu363/india

ii) –l option specify limit over locate command.


[bca123@localhost ~]$ locate -l 5 query
Output:
/usr/bin/bonobo-activation-run-query
/usr/bin/gdk-pixbuf-query-loaders-32
/usr/bin/gtk-query-immodules-2.0-32
iii)–S option show statics of database.
[bca123@localhost ~]$ locate –S

Output:
Database /var/lib/mlocate/mlocate.db:
12,097 directories
128,575 files
5,894,919 bytes in file names
2,594,095 bytes used to store database

c) tac command
i) To reverse the contain of file.
[bca123@localhost vinu29]$ cat >>kuku
first line
second line
third line
[2]+ Stopped cat >>kuku

Output:
[bca123@localhost vinu29]$ tac kuku
third line
second line
Assignment: Working with Linux Permissions

A. Changing File and Directory Permissions:--


a) chmod command
i) It is used to change permission of file after its creation
[bca123@localhost ~]$ chmod u+x greater
[bca123@localhost ~]$ ls -l greater
Output:
-rwxrw-r-- 1 bca123 bca123 262 May 21 01:55 greater

ii) To give permission to more than one user (owner, group) simultaneously
[bca123@localhost ~]$ chmod go+x greater; ls -l greater
Output:
-rwxrwxr-x 1 bca123 bca123 262 May 21 01:55 greater

iii) To denied particular permission of particular file


[bca123@localhost ~]$ chmod u-x greater;ls -l greater
Output:
-rw-rwxr-x 1 bca123 bca123 262 May 21 01:55 greater

iv) To give permission to more than one file at a same time


[bca123@localhost ~]$ chmod u+x greater greter
[bca123@localhost ~]$ ls -l greater greter
Output:
-rwxrwxr-x 1 bca123 bca123 262 May 21 01:55 greater
-rwxrw-r-- 1 bca123 bca123 4 May 21 01:22 greter

B. Changing Default Permissions and Ownership:--


a) umask command
i) To change the default permission of file and directory.
[bca123@localhost vinu29]$ umask 033
[bca123@localhost vinu29]$ mkdir ukk
Output->
[bca123@localhost vinu29]$ ls –l
drwxr--r-- 2 bca123 bca123 4096 Mar 9 15:45 ukk
Assignment: Working in X Windows

A. Customizing X Windows
Windows:--
a. xterm command
i) To Open terminal we used simply xterm command.
[root@localhost ~]# xterm
Output:

ii) To set background color and foreground color of your screen.


[root@localhost ~]# xterm -bg red -fg blue
Output:
It will open terminal having red background and blue foreground.

iii) To set default window size and location.


[root@localhost ~]# xterm -geometry 20*50+10+10

iv) To set color to cursor of your terminal.


[root@localhost ~]# xterm -cr green

B. X- Window Utilities:-- --
a. gedit command
i. It is used to launch gedit application which is very similar to windows notepad.
notepad
[root@localhost ~]# gedit
Output:

b. xclock command
i. To see clock that apperars on GNOME Panel
Panel.. By default analog clock is appears.
[root@localhost ~]# xclock
Output:

ii. To see digital clock on GNOME Panel.


[root@localhost ~]# xclock –d
Output:

c. gcalctool command
i. To have GNOME Calculator on our screen use following command.
[root@localhost
root@localhost ~]# gcalctool
Output:
Assignment : Printing Files

A. Configuring a Local Printer:--


Printer
Step 1:- To Open the printer configuration, select "System" menu-"Administration
"Administration"-
"Printing". The Printer configuration
nfiguration window will appears as shown below:

Step 2:- Click on “New Printer", the new window will appears as shown below, w write
following information,
a. Name:- Add the name of printer you want to use for printing.
b. Description:-Add few words describing the printer, such as it features.
c. Location of printer:- Mention location of printer from where you want to access.

Click on Forward Button.

Step 3:- Once’ss you click on forward button, choose the device to which printer is
connected as shown in given below screen shots.

Click again on Forward Button

Step 4:- Select your printer name which you gave during step 2 from given database list as
shown in given
ven below diagram.
Click on forward Button.
Now select your printer model number and also select appropriate driver from given
step 5:-Now
list.

Click on forward Button.

Step 6:- You will see following window and then click on apply button.
button

Once’s you click on apply button your printer name is seen in list of printer configuration as
shown in following screenshots. Select your printer; you can see information about your
printer.

Step 7:- Now you are ask if you want to print a test page. Click ‘yes’ to print test page. This
test page will tell you intersecting information about your printer, such as resolution and
the type of interpreter used.

Step 8:- Choose apply to save changes. If you would like to try other test pages, Click Test &
select one of the following: JPEG, ASCII test page etc.
B. Printing:--
a) pr command
i) pr - convert text files for printing
[bca123@localhost ~]$ pr file1

b) lpq command
i) To see position of printing job at any given time.
[root@localhost ~]# lpq –P printer1
Output:
printer1 is ready
Rank Owner Job File(s) Total Size
1st root 6 30720 bytes
2nd root 7 Test Page 18432 bytes

c) lprm command
i) To cancel unwanted printing job.
[root@localhost ~]# lprm –P printer1 6

d) lpr command
i) To send particular file for printing connected to your system.
Output:
[root@localhost ~]# lp –P printer1 myself.txt

You might also like