Linux OS Basic Commands
Linux OS Basic Commands
Page 1
UE123029
Page 2
UNIX PROCESSES
When a program is started on UNIX, it creates what is known as a "process" on the system.
Every process is assigned a unique serial number called its process id or PID for short.
Processes can be created by any user, but can only be destroyed by someone with the
permissions to do so - usually the user that created the process or the system administrator. This
ensures that the compute jobs you start on the system will not be disturbed by any other user of
the system until they complete or you decide to stop them yourself.
Processes and process management becomes important on UNIX systems
that are shared between a number of users. The concept of users and PIDs is
the main tool by which the available system resources are shared fairly
among everybody who needs access to them. Processes can be suspended
or given lower priority in cases where one or more users should step out of
the way for someone else, but wish to do so without losing their work up to
that point.
One further consideration on this topic is the fact that a running UNIX
process can spawn "child" processes. For example, any program you run
from inside a UNIX shell will be a child process of that shell. Conversely, the
shell is the parent process of this child. Child proceses have associated with
them both their own process id (PID) as well as their parent's process id
UE123029
Page 3
(PPID).
Normally this concept of parent and child processes is not something you
need to be bothered with as a user. However, it can be useful to understand
how UNIX organizes processes if you are trying to keep track of certain
system resources (e.g. memory and CPU), if you are working with
environment variables, or if you need to track down a rogue program or
script. Some of these items will be discussed later so it's good to have a
basic idea about what a UNIX process is.
LINUX
Linux is a UNIX-base operating system. Its original creator was a Finnish
student name Linus Torvalds, although being open source it has change a
great deal since its original conception. It belongs to nobody, and is free to
download and use. Any changes to it are open for all to adopt, and as a result
it has developed into a very powerful OS that is rapidly gaining in popularity
worldwide, particularly among those seeking an alternative to Windows.
In 1991, hardware was expanding rapidly, and DOS was the king of operating
systems. Software development was slower, and Macs, while better, were
also much pricier than PCs. UNIX was growing, but at that time in its history
the source code was jealously guarded and expensive to use.
Linus Torvalds was a Helsinki university student who liked playing around
with software and computers, and in 1991 he announced the creation of a
new core operating system that he had named Linux. It is now one of the
most used systems for the PC, and is particularly suitable for businesses with
small IT budgets. Linux is free to use and install, and is more reliable than
almost all other systems, running for many months and even years without a
reboot being necessary.
Advantages and Benefits of Linux
One of the significant benefits of open source software such as Linux is that
because it has no owner, it can be debugged without resource to a license
owner or software proprietor. Businesses therefore have the flexibility to do
as they wish with the OS without having to worry about conforming to
complex license agreements.
The major advantage of Linux is its cost: the core OS is free, while many
software applications also come with a GNU General public License. It can
also be used simultaneously by large numbers of users without slowing down
or freezing and it is very fast. It is an excellent networking platform and
performs at optimum efficiency even with little available hard disk space.
Linux also runs on a wide range of hardware types, including PCs, Macs,
mainframes, supercomputers, some cell phones and industrial robots. Some
prefer to dual-boot Linux and Windows while others prefer Linux and Mac OS.
System76 machines come pre-installed with Linux in the form of Ubuntu, a
Debian distribution of Linux. This is the most popular distribution of Linux for
laptops.
UE123029
Page 4
Page 5
Page 6
functions.
Utilities - Utility programs giving user most of the functionalities of an
operating systems.
Linux Vs Windows
The main benefits and advantages of Linux over other operating systems,
particularly Microsoft Windows, are:
It is free to use and distribute.
Support is free through online help sites, blogs and forums.
It is very reliable more so than most other operating systems with
very few crashes.
A huge amount of free open source software has been developed for it.
It is very resistant to malware such as spyware, adware and viruses.
It runs in a wide variety of machines than cannot be updated to use
newer Windows versions.
Since the source code is visible, backdoors are easily spotted, so
Linux offers greater security for sensitive applications.
Linux offers a high degree of flexibility of configuration, and significant
customization is possible without modifying the source code.
The Linux operating system is widely use by both home and business users,
and its usage is increasing daily. It is considered that Linux will eventually
overtake Microsoft Windows as the most popular operating system, which
could also open the door further for more free software such as Open Office,
The Gimp, Paint, Thunderbird, Firefox and Scribus. It is easy to install and run
alongside your existing operating system, so give it a try, because it is also
easy to remove if you dont like it which is unlikely.
UBUNTU
Ubuntu is an operating system that is developed by a worldwide community
of programmers as well as by employees of Ubuntu's commercial sponsor,
Canonical. Ubuntu is based on the concept of free or open-source software,
meaning that you do not pay any licensing fees for Ubuntu, and you can
download, use, and share the operating system free of charge.
Being a Linux-based operating system, Ubuntu has a well-deserved
reputation for stability and security. Historically, Linux has proven itself to be
a workhorse server operating system, and this is where, up until now, it has
been most widely used and best known. As of June, 2007, 78 percent of the
world's top 500 supercomputers were running Linux, according to
Top500.org.
However, in recent years, Linux has also become viable on desktop and
laptop computers, making it an option for individuals and businesses. Ubuntu
is generally acknowledged to be the most widely used version of Linux
available, and Mark Shuttleworth, the founder and CEO of Canonical,
estimates Ubuntu has between six and eight million users. Because the
UE123029
Page 7
Page 8
months. After 18 months, security updates and bug fixes will no longer be
provided, but you're free to keep using that version of Ubuntu if you like, or
update online (free of charge) to a newer version that is supported in this
way. Moreover, every two years, Ubuntu releases a version that provides bug
fixes and security updates for a longer period of time three years on
desktops or laptops, and five years on servers making it a good solution
for those who want a longer rest between releases.
Of course, being open source gives Ubuntu one other major difference over
Windows and OS X, and that is the ability for users to modify it in any way
that suits them. There are two types of modifications most relevant here:
Bug fixes, security fixes, or feature enhancements, which are
contributed back to Ubuntu or the original application authors if
relevant.
Customizations to Ubuntu for a given set of circumstances, called a
derivatives. Some examples are highlighted below, but a full list can be
found on Ubuntu's Web site:
nUbuntu, a security-testing platform.
Ubuntu Studio, for multi-media editing and creation.
b) AIM :- How to Install Linux on your System
1.Its easy to install Ubuntu from a DVD. Heres what you need to do:
Put the Ubuntu DVD into the DVD-drive
Restart your computer. You should see a welcome screen prompting you to
choose your language and giving you the option to install Ubuntu or try it
from the DVD.
If your computer doesnt automatically do so, you might need to press
the F12 key to bring up the boot menu, but be careful not to hold it down that can cause an error message.
UE123029
Page 9
2
Prepare to install Ubuntu
Make sure you have enough space on your computer to install Ubuntu
It is advised to select Download updates while installing and Install this thirdparty software now
Should stay connected to the internet so you can get the latest updates while you
install Ubuntu
3 Set up wireless
If you are not connected to the internet, you will be asked to select a wireless
network, if available. We advise you to connect during the installation so we
can ensure your machine is up to date. So, if you set up your wireless
UE123029
Page 10
network at this point, its worth then clicking the Back button to go back to
the last screen (Preparing to install Ubuntu) and ticking the box
marked Download updates while installing.
UE123029
Page 11
Page 12
UE123029
Page 13
10 Thats it. All thats left is to restart your computer and start enjoying Ubuntu!
UE123029
Page 14
EXPERIMENT 2
Aim: To implement various linux/unix commands :
Echo,cat,touch,man,mkdir,cd,rmdir,pwd,ls,who,whoami,wc,cal,ncal,more,less,
cp,mv,cmp,head,tail
COMMAND ECHO
display a line of text i.e Echo the STRING(s) to standard output.
SYNTAX :echo [OPTION]... [STRING]...
DESCRIPTION :
-n
-e
-E
--help
-versio
n
backslash
\a
alert (BELL)
\b
backspace
\c
UE123029
Page 15
\e
escape
\f
form feed
\n
new line
\r
carriage return
\t
horizontal tab
\v
vertical tab
\0NNN
\xHH
USAGE:
1.Using echo without any options:
gurprem@ubuntu:~/gurprem$ echo "lets get started"
lets get started
2.Using e with \n escape sequence:
gurprem@ubuntu:~/gurprem$ echo -e "lets \n get \n started"
lets
get
started
3.Using n to not output the trailing newline
gurprem@ubuntu:~/gurprem$ echo -n "lets \nget \n started"
lets \nget \n started
gurprem@ubuntu:~/gurprem$ echo -n "lets "
lets
gurprem@ubuntu:~/gurprem$ echo -n "lets \n get"
lets \n
getgurprem@ubuntu:~/gurprem$ echo 'ls'
ls
4.Using E to disable interpretation of backslash escapes
gurprem@ubuntu:~/gurprem$ echo -E " lets\n get \n started"
lets\n get \n started
5. Using option \b backspace with backslash interpretor -e which
removes all the spaces in between.
gurprem@ubuntu:~/gurprem$ echo -e "Tecmint \\bis \\ba \\bcommunity
\\bof \\bLinux \\bNerds"
UE123029
Page 16
TecmintisacommunityofLinuxNerds
6. Using option \n New line with backspace interpretor -e treats
new line from where it is used.
gurprem@ubuntu:~/gurprem$ echo -e "Tecmint \\nis \\na \\ncommunity
\\nof \\nLinux \\nNerds"
Tecmint
is
a
community
of
Linux
Nerds
7. Using option \t horizontal tab with backspace interpretor -e
to have horizontal tab spaces.
gurprem@ubuntu:~/gurprem$ echo -e "Tecmint \\tis \\ta \\tcommunity
\\tof \\tLinux \\tNerds"
Tecmint
is
a
community of
Linux
Nerds
8. How about using option new Line \n and horizontal tab \t
simultaneously.
gurprem@ubuntu:~/gurprem$ echo -e "\\n\\tTecmint \\n\\tis \\n\\ta
\\n\\tcommunity \\n\\tof \\n\\tLinux \\n\\tNerds"
Tecmint
is
a
community
of
Linux
Nerds
9. Using option \v vertical tab with backspace interpretor -e to
have vertical tab spaces.
gurprem@ubuntu:~/gurprem$ echo -e "\\vTecmint \\vis \\va
\\vcommunity \\vof \\vLinux \\vNerds"
Tecmint
is
a
community
of
Linux
Nerds
10. How about using option new Line \n and vertical tab \v
simultaneously.
gurprem@ubuntu:~/gurprem$ echo -e "\\n\\vTecmint \\n\\vis \\n\\va
\\n\\vcommunity \\n\\vof \\n\\vLinux \\n\\vNerds"
UE123029
Page 17
Tecmint
is
a
community
of
Linux
Nerds
Note: We can double the vertical tab, horizontal tab and new line
spacing using the option two times or as many times as required.
11. Using option \r carriage return with backspace interpretor e to have specified carriage return in output.
gurprem@ubuntu:~/gurprem$ echo -e "Tecmint \\ris a community of Linux
Nerds"
is a community of Linux Nerds
12. Using option \c suppress trailing new line with backspace
interpretor -e to continue without emitting new line.
gurprem@ubuntu:~/gurprem$ echo -e "Tecmint is a community \\cof Linux
Nerds"
Tecmint is a community avi@tecmint:~$
13. Omit echoing trailing new line using option -n.
gurprem@ubuntu:~/gurprem$ echo -n "Tecmint is a community of Linux
Nerds"
Tecmint is a community of Linux Nerdsavi@tecmint:~/Documents$
14. Using option \a alert return with backspace interpretor -e
to have sound alert.
gurprem@ubuntu:~/gurprem$ echo -e "Tecmint is a community of \\aLinux
Nerds"
Tecmint is a community of Linux Nerds.
COMMAND CAT
It can
SYNTAX:
cat [OPTIONS]... filename
UE123029
Page 18
If the output has multiple empty lines it replaces it with one empty line.
Displays the tab characters in the output.
Non-printing characters (with the exception of tabs, new-lines and
form-feeds) are printed visibly.
-v
Usage:
1.-A
2.
-b,
gurprem@ubuntu:~/gurprem$ cat -b os1
hello world!!
gurprem@ubuntu:~/gurprem$ cat -b os1
1
hello world!!in os1!
2
hii!
3.
E
gurprem@ubuntu:~/gurprem$ cat -E os1
hello world!!in
os1!$ NOTE:Dispalys tabs inpalce of tab.
$
hii!$
-n,
gurprem@ubuntu:~/gurprem$ cat -n os1
UE123029
Page 19
1
2
3
s
gurprem@ubuntu:~/gurprem$ cat demo
hello
world
night night
gurprem@ubuntu:~/gurprem$ cat -s demo
hello
world
night night
4.
-t ,T, v
gurprem@ubuntu:~/gurprem$ cat -v demo
hello
good evening
gurprem@ubuntu:~/gurprem$ cat -vT demo
hello^I^Igood evening
gurprem@ubuntu:~/gurprem$ cat -T demo
hello^I^Igood evening
gurprem@ubuntu:~/gurprem$ cat -t demo
hello^I^Igood evening
5. To Create a new file:
gurprem@ubuntu:~/gurprem$ cat>demo
hello world !
This command creates a new file demo.txt. After typing into the file
press control+d (^d) simultaneously to end the file.
6.To Append data into the file:
gurprem@ubuntu:~/gurprem$ cat>>demo
hello...this is my first file.
To append data into the same file use append operator >> to write into
the file, else the file will be overwritten (i.e., all of its contents
will be erased).
7.To display a file:
gurprem@ubuntu:~/gurprem$ cat demo
UE123029
Page 20
hello world!
This command displays the data in the file.
8.To concatenate several files and display:
gurprem@ubuntu:~/gurprem$ cat file1 file2
The above cat command will concatenate the two files (file1.txt and
file2.txt) and it will display the output in the screen.
9.To concatenate several files and to transfer the output to another
file.
gurprem@ubuntu:~/gurprem$ cat os1>>file2
gurprem@ubuntu:~/gurprem$ cat file2
hello world!!in os1!
hello world!!in os1!
-In the above example the output is redirected to new file file2. The
cat command will create new file file3.txt and store the concatenated
output into file3.txt.
COMMAND MAN:
man command which is short for manual, provides in depth information about the
requested command (or) allows users to search for commands related to a
particular keyword.
SYNTAX:
man commandname [OPTIONS]
DESCRIPTION:
-a
-k
USAGE:
1. gurprem@ubuntu:~/gurprem$ man mkdir
Display the information about mkdir command.
COMMAND
TOUCH :
touch command is used to update last modified time and date of a file. It is also
used to create a new empty file with current date and time.
SYNTAX:
touch [options] File
DESCRIPTION:
-a
update only the access time.
-B,
Modify the time by going back SECONDS seconds.
--backward=SE
UE123029
Page 21
CONDS
-c, --no-create do not create any files.
-d,
parse STRING and use it instead of current time.
--date=STRING
-m
change only the modification time.
set time given by WORD: access atime use (same as -a)
--time=WORD
modify mtime (same as -m).
USAGE:
1.
gurprem@ubuntu:~/gurprem$ touch os1
gurprem@ubuntu:~/gurprem$ ls -l
total 516
-rw-rw-r-- 1 gurprem gurprem
45
-rw-rw-r-- 1 gurprem gurprem
44
-rw-rw-r-- 1 gurprem gurprem
0
....
-rw-rw-r-- 1 gurprem gurprem
35
-rw-rw-r-- 1 gurprem gurprem
57
-rw-rw-r-- 1 gurprem gurprem 211370
-rw-rw-r-- 1 gurprem gurprem 197214
2.
gurprem@ubuntu:~/gurprem$ touch -a file1
gurprem@ubuntu:~/gurprem$ ls -l
total 516
-rw-rw-r-- 1 gurprem gurprem
45 Sep 2
-rw-rw-r-- 1 gurprem gurprem
44 Sep 2
-rw-rw-r-- 1 gurprem gurprem
35 Aug 27
-rw-rw-r-- 1 gurprem gurprem
14 Aug 27
....
3.
gurprem@ubuntu:~/gurprem$ touch -c fff
gurprem@ubuntu:~/gurprem$ cat fff
cat: fff: No such file or directory
13:16
13:15
02:53
03:17
demo
demo~
file
file1
4.
gurprem@ubuntu:~/gurprem$ touch -d "next thursday" file1
gurprem@ubuntu:~/gurprem$ ls -l
total 516
-rw-rw-r-- 1 gurprem gurprem
45 Sep 2 13:16 demo
-rw-rw-r-- 1 gurprem gurprem
44 Sep 2 13:15 demo~
-rw-rw-r-- 1 gurprem gurprem
35 Aug 27 02:53 file
-rw-rw-r-- 1 gurprem gurprem
14 Sep 4 2014 file1
-rw-rw-r-- 1 gurprem gurprem
42 Aug 27 02:56 file
COMMAND LS:
ls - list directory contents
List information about the FILEs (the current directory by default).
UE123029
Page 22
1.
gurprem@ubuntu:~/gurprem$ ls
demo~ f2~ f5~ file1
gg2
f1
f3
f6
file1~
lab work 1.2
f1~
f4
f7
file2~
lab work 1.3
f10
f4~ f8
file file new$documnet#
f2
f5
f9
gg1
new$documnet#~
2. a
gurprem@ubuntu:~/gurprem$ ls -a
.
f1~ f3
f5~ f9
file file
..
f10 f4
f6
file1
gg1
demo~ f2
f4~ f7
file1~ gg2
typescript~
UE123029
Page 23
os1~
test
typescript
typescript~
typescript-lab1
test
typescript
f1
f2~ f5
typescript-lab1
f8
file2~
3. -A
gurprem@ubuntu:~/gurprem$ ls -A
demo~ f2~ f5~ file1
gg2
f1
f3
f6
file1~
lab work 1.2
f1~
f4
f7
file2~
lab work 1.3
f10
f4~ f8
file file new$documnet#
f2
f5
f9
gg1
new$documnet#~
os1~
4. b
gurprem@ubuntu:~/gurprem$ ls
demo~ f2~ f5~ file1
f1
f3
f6
file1~
f1~
f4
f7
file2~
f10
f4~ f8
file\ file
f2
f5
f9
gg1
-b
gg2
lab\ work\ 1.2
lab\ work\ 1.3
new$documnet#
new$documnet#~
os1~
test
typescript
typescript~
typescript-lab1
5. -B
gurprem@ubuntu:~/gurprem$ ls -B
f1
f3 f6 f9
gg1
f10 f4 f7 file1
gg2
f2
f5 f8 file file lab work 1.2
os1~
test
typescript
typescript~
typescript-lab1
typescript
typescript-lab1
6. c
gurprem@ubuntu:~/gurprem$ ls -c
f10 f9
f6
f1~
file1~ typescript-lab1 file file
os1~
f5
typescript f5~ f2
gg1
lab work 1.2
new$documnet#
file2~
f4
f7
f3
f2~
test
lab work 1.3
new$documnet#~
f8
f4~
f1
file1 demo~
typescript~
gg2
gurprem@ubuntu:~/gurprem$ ls -c
new f8
f4~ f1
file1
demo~
typescript~
gg2
f10 f9
f6
f1~ file1~ typescript-lab1 file file
os1~
f5
typescript f5~ f2
gg1
lab work 1.2
new$documnet#
file2~
f4
f7
f3
f2~ test
lab work 1.3
new$documnet#~
6.1 c lt
gurprem@ubuntu:~/gurprem$ ls -c -lt
total 560
-rw-rw-r-- 1 gurprem gurprem
0
-rw-rw-r-- 1 gurprem gurprem
0
-rw-rw-r-- 1 gurprem gurprem
24
-rw-rw-r-- 1 gurprem gurprem
8
-rw-rw-r-- 1 gurprem gurprem
0
-rw-rw-r-- 1 gurprem gurprem
0
-rw-rw-r-- 1 gurprem gurprem 16384
UE123029
Sep
Sep
Sep
Sep
Sep
Sep
Sep
Page 24
6
3
3
3
3
3
3
11:17
04:01
03:58
03:54
03:46
03:46
03:44
new
f10
f5
f4
f8
f9
typescript
-rw-rw-r--rw-rw-r--rw-rw-r--rw-rw-r--rw-rw-r--rw-rw-r--rw-rw-r--rw-rw-r--rw-rw-r--rw-rw-r--rw-rw-r-drwxrwxr-x
dr--r--rw-rw-rw-r--rw-rw-r--rw-rw-r--rw-rw-r--rw-rw-r--rw-rw-r--rw-rw-r--rw-rw-r-drw-rw-r--rw-rw-r--rw-rw-r--
1
1
1
1
1
1
1
1
1
1
1
2
2
1
1
1
1
1
1
1
1
2
1
1
gurprem
gurprem
gurprem
gurprem
gurprem
gurprem
gurprem
gurprem
gurprem
gurprem
gurprem
gurprem
gurprem
gurprem
gurprem
gurprem
gurprem
gurprem
gurprem
gurprem
gurprem
gurprem
gurprem
gurprem
gurprem
18 Sep 3 03:42 f7
gurprem
21 Sep 3 03:31 f4~
gurprem
37 Sep 3 03:22 f6
gurprem
18 Sep 3 03:17 f5~
gurprem
67 Sep 3 03:07 f3
gurprem
48 Sep 3 02:58 f1
gurprem
38 Sep 3 02:58 f1~
gurprem
19 Sep 3 02:47 f2
gurprem
7 Sep 3 02:47 f2~
gurprem
59 Sep 3 02:39 file1
gurprem
9 Sep 3 02:39 file1~
gurprem
4096 Sep 2 23:13 gg1
gurprem
4096 Sep 2 13:46 test
gurprem
44 Sep 2 13:16 demo~
gurprem 197214 Aug 31 05:17 typescript-lab1
gurprem 26409 Aug 31 05:16 lab work 1.2
gurprem 29950 Aug 31 05:16 lab work 1.3
gurprem 211370 Aug 31 05:08 typescript~
gurprem
0 Aug 31 04:39 file file
gurprem
23 Aug 31 04:16 new$documnet#
gurprem
0 Aug 31 04:16 new$documnet#~
gurprem
4096 Aug 27 03:38 gg2
gurprem
57 Aug 27 03:11 os1~
gurprem
35 Aug 27 02:54 file2~
6.2 c l
gurprem@ubuntu:~/gurprem$ ls -c -l
total 560
-rw-rw-r-- 1 gurprem gurprem
44 Sep 2 13:16 demo~
-rw-rw-r-- 1 gurprem gurprem
48 Sep 3 02:58 f1
-rw-rw-r-- 1 gurprem gurprem
38 Sep 3 02:58 f1~
-rw-rw-r-- 1 gurprem gurprem
0 Sep 3 04:01 f10
-rw-rw-r-- 1 gurprem gurprem
19 Sep 3 02:47 f2
-rw-rw-r-- 1 gurprem gurprem
7 Sep 3 02:47 f2~
-rw-rw-r-- 1 gurprem gurprem
67 Sep 3 03:07 f3
-rw-rw-r-- 1 gurprem gurprem
8 Sep 3 03:54 f4
-rw-rw-r-- 1 gurprem gurprem
21 Sep 3 03:31 f4~
-rw-rw-r-- 1 gurprem gurprem
24 Sep 3 03:58 f5
-rw-rw-r-- 1 gurprem gurprem
18 Sep 3 03:17 f5~
-rw-rw-r-- 1 gurprem gurprem
37 Sep 3 03:22 f6
-rw-rw-r-- 1 gurprem gurprem
18 Sep 3 03:42 f7
-rw-rw-r-- 1 gurprem gurprem
0 Sep 3 03:46 f8
-rw-rw-r-- 1 gurprem gurprem
0 Sep 3 03:46 f9
-rw-rw-r-- 1 gurprem gurprem
59 Sep 3 02:39 file1
-rw-rw-r-- 1 gurprem gurprem
9 Sep 3 02:39 file1~
-rw-rw-r-- 1 gurprem gurprem
35 Aug 27 02:54 file2~
-rw-rw-r-- 1 gurprem gurprem
0 Aug 31 04:39 file file
drwxrwxr-x 2 gurprem gurprem
4096 Sep 2 23:13 gg1
drw-rw-r-- 2 gurprem gurprem
4096 Aug 27 03:38 gg2
-rw-rw-r-- 1 gurprem gurprem 26409 Aug 31 05:16 lab work 1.2
-rw-rw-r-- 1 gurprem gurprem 29950 Aug 31 05:16 lab work 1.3
-rw-rw-r-- 1 gurprem gurprem
0 Sep 6 11:17 new
UE123029
Page 25
31
31
27
2
3
31
31
04:16
04:16
03:11
13:46
03:44
05:08
05:17
new$documnet#
new$documnet#~
os1~
test
typescript
typescript~
typescript-lab1
7. C
gurprem@ubuntu:~/gurprem$ ls C
demo~
lab1
f1
f1~
f10
f2
f2~
f5~
file1
gg2
new$documnet#~
f3
f4
f4~
f5
f6
f7
f8
f9
file1~
file2~
file file
gg1
os1~
test
typescript
typescript~
8. f
gurprem@ubuntu:~$ cd gurprem
gurprem@ubuntu:~/gurprem$ ls
f5~
f4~
new$documnet# file1
file file
f2~
lab1
file2~
f1~
.
lab work 1.3
f9
f5
demo~
test
-f
gg1
lab work 1.2
typescript
f2
f1
typescript~
f8
..
typescript-
gg2
f10
f6
new
f3
file1~
f7
new$documnet#~
f4
os1~
new$documnet#~
typescript-
9. F
gurprem@ubuntu:~/gurprem$ ls -F
demo~ f2~ f5~ file1
gg2/
lab1
f1
f3
f6
file1~
lab work 1.2
f1~
f4
f7
file2~
lab work 1.3
f10
f4~ f8
file file new
f2
f5
f9
gg1/
new$documnet#
10. g
gurprem@ubuntu:~/gurprem$ ls -g
total 560
-rw-rw-r-- 1 gurprem
44 Sep
-rw-rw-r-- 1 gurprem
48 Sep
-rw-rw-r-- 1 gurprem
38 Sep
-rw-rw-r-- 1 gurprem
0 Sep
-rw-rw-r-- 1 gurprem
19 Sep
-rw-rw-r-- 1 gurprem
7 Sep
-rw-rw-r-- 1 gurprem
67 Sep
-rw-rw-r-- 1 gurprem
8 Sep
-rw-rw-r-- 1 gurprem
21 Sep
UE123029
typescript-
2
3
3
3
3
2
3
3
3
13:15
02:58
02:57
04:01
02:47
23:29
03:07
03:54
03:30
Page 26
os1~
test/
typescript
typescript~
demo~
f1
f1~
f10
f2
f2~
f3
f4
f4~
-rw-rw-r--rw-rw-r--rw-rw-r--rw-rw-r--rw-rw-r--rw-rw-r--rw-rw-r--rw-rw-r--rw-rw-r--rw-rw-r-drwxrwxr-x
drw-rw-r--
1
1
1
1
1
1
1
1
1
1
2
2
gurprem
gurprem
gurprem
gurprem
gurprem
gurprem
gurprem
gurprem
gurprem
gurprem
gurprem
gurprem
24
18
37
18
0
0
59
9
35
0
4096
4096
11. h l
gurprem@ubuntu:~/gurprem$ ls
total 560K
-rw-rw-r-- 1 gurprem gurprem
-rw-rw-r-- 1 gurprem gurprem
-rw-rw-r-- 1 gurprem gurprem
-rw-rw-r-- 1 gurprem gurprem
-rw-rw-r-- 1 gurprem gurprem
-rw-rw-r-- 1 gurprem gurprem
-rw-rw-r-- 1 gurprem gurprem
-rw-rw-r-- 1 gurprem gurprem
-rw-rw-r-- 1 gurprem gurprem
-rw-rw-r-- 1 gurprem gurprem
-rw-rw-r-- 1 gurprem gurprem
-rw-rw-r-- 1 gurprem gurprem
-rw-rw-r-- 1 gurprem gurprem
-rw-rw-r-- 1 gurprem gurprem
-rw-rw-r-- 1 gurprem gurprem
-rw-rw-r-- 1 gurprem gurprem
-rw-rw-r-- 1 gurprem gurprem
-rw-rw-r-- 1 gurprem gurprem
-rw-rw-r-- 1 gurprem gurprem
drwxrwxr-x 2 gurprem gurprem
drw-rw-r-- 2 gurprem gurprem
-rw-rw-r-- 1 gurprem gurprem
-rw-rw-r-- 1 gurprem gurprem
-rw-rw-r-- 1 gurprem gurprem
-rw-rw-r-- 1 gurprem gurprem
-rw-rw-r-- 1 gurprem gurprem
-rw-rw-r-- 1 gurprem gurprem
dr--r--rw- 2 gurprem gurprem
-rw-rw-r-- 1 gurprem gurprem
-rw-rw-r-- 1 gurprem gurprem
-rw-rw-r-- 1 gurprem gurprem
Sep 3 03:58 f5
Sep 3 03:10 f5~
Sep 3 03:22 f6
Sep 3 03:42 f7
Sep 3 03:46 f8
Sep 3 03:46 f9
Sep 3 02:39 file1
Sep 2 23:36 file1~
Aug 27 02:53 file2~
Aug 31 04:39 file file
Sep 2 23:13 gg1
Aug 27 03:38 gg2
-h -l
44
48
38
0
19
7
67
8
21
24
18
37
18
0
0
59
9
35
0
4.0K
4.0K
26K
30K
0
23
0
57
4.0K
16K
207K
193K
Sep
Sep
Sep
Sep
Sep
Sep
Sep
Sep
Sep
Sep
Sep
Sep
Sep
Sep
Sep
Sep
Sep
Aug
Aug
Sep
Aug
Aug
Aug
Sep
Aug
Aug
Aug
Sep
Sep
Aug
Aug
2
3
3
3
3
2
3
3
3
3
3
3
3
3
3
3
2
27
31
2
27
31
31
6
31
31
27
2
3
31
31
12. si
gurprem@ubuntu:~/gurprem$ ls -si
total 560
803507
4 demo~ 803511
4 f6
UE123029
Page 27
13:15
02:58
02:57
04:01
02:47
23:29
03:07
03:54
03:30
03:58
03:10
03:22
03:42
03:46
03:46
02:39
23:36
02:53
04:39
23:13
03:38
05:03
05:15
11:17
04:16
04:12
03:11
13:46
03:44
05:05
05:08
demo~
f1
f1~
f10
f2
f2~
f3
f4
f4~
f5
f5~
f6
f7
f8
f9
file1
file1~
file2~
file file
gg1
gg2
lab work 1.2
lab work 1.3
new
new$documnet#
new$documnet#~
os1~
test
typescript
typescript~
typescript-lab1
803475
803406
803362
803517
803508
803478
803510
803515
803509
803513
803506
4
4
0
4
4
4
4
4
4
4
f1
f1~
f10
f2
f2~
f3
f4
f4~
f5
f5~
803512
803410
803516
803411
803502
803405
803455
803412
803413
803437
4
0
0
4
4
4
0
4
4
28
f7
f8
f9
file1
file1~
file2~
file file
gg1
gg2
lab work 1.2
803521
0 new
803440
4 new$documnet#
803353
0 new$documnet#~
803407
4 os1~
803503
4 test
803399 16 typescript
803472 208 typescript~
803469 196 typescript-lab1
13. hide
gurprem@ubuntu:~/gurprem$ ls --hide 'g*'
demo~ f2~ f5~ file1
lab work 1.3
f1
f3
f6
file1~
new
f1~
f4
f7
file2~
new$documnet#
f10
f4~ f8
file file
new$documnet#~
f2
f5
f9
lab work 1.2 os1~
test
typescript
typescript~
typescript-lab1
file1~
file2~
file file
gg1
gg2
lab work 1.2
lab work 1.3
typescript-lab1
803440
803353
803407
803503
803399
803472
803469
new$documnet#
new$documnet#~
os1~
test
typescript
typescript~
typescript-
new
15. k m
gurprem@ubuntu:~/gurprem$ ls -k -m
demo~, f1, f1~, f10, f2, f2~, f3, f4, f4~, f5, f5~, f6, f7, f8, f9,
file1,
file1~, file2~, file file, gg1, gg2, lab work 1.2, lab work 1.3, new,
new$documnet#, new$documnet#~, os1~, test, typescript, typescript~,
16. n
gurprem@ubuntu:~/gurprem$ ls -n
total 560
-rw-rw-r-- 1 1000 1000
44 Sep
-rw-rw-r-- 1 1000 1000
48 Sep
-rw-rw-r-- 1 1000 1000
38 Sep
-rw-rw-r-- 1 1000 1000
0 Sep
-rw-rw-r-- 1 1000 1000
19 Sep
UE123029
2
3
3
3
3
13:15
02:58
02:57
04:01
02:47
Page 28
demo~
f1
f1~
f10
f2
7 Sep
67 Sep
8 Sep
2 23:29 f2~
3 03:07 f3
3 03:54 f4
17. p
gurprem@ubuntu:~/gurprem$ ls -p
demo~ f2~ f5~ file1
gg2/
lab1
f1
f3
f6
file1~
lab work 1.2
f1~
f4
f7
file2~
lab work 1.3
f10
f4~ f8
file file new
f2
f5
f9
gg1/
new$documnet#
new$documnet#~
typescript-
os1~
test/
typescript
typescript~
18. Q
gurprem@ubuntu:~/gurprem$
"demo~" "f3"
"f7"
"typescript-lab1"
"f1"
"f4"
"f8"
"f1~"
"f4~" "f9"
"f10"
"f5"
"file1"
"f2"
"f5~" "file1~"
"f2~"
"f6"
"file2~"
ls -Q
"file file"
"new$documnet#"
"gg1"
"gg2"
"lab work 1.2"
"lab work 1.3"
"new"
"new$documnet#~"
"os1~"
"test"
"typescript"
"typescript~"
19. r
gurprem@ubuntu:~/gurprem$ ls -r
typescript-lab1 os1~
f1~
typescript~
new$documnet#~
f1
typescript
new$documnet#
demo~
test
new
file file
f9
f5~
f3
file2~
f8
f5
f2~
gg2
file1~
f7
f4~
f2
gg1
file1
f6
f4
f10
20. s S
gurprem@ubuntu:~/gurprem$ ls -s -S
total 560
208 typescript~
4 f3
4 f5
196 typescript-lab1
4 file1
4 new$documnet#
32 lab work 1.3
4 os1~
4 f4~
28 lab work 1.2
4 f1
4 f2
16 typescript
4 demo~
4 f5~
4 gg1
4 f1~
4 f7
4 gg2
4 f6
4 file1~
4 test
4 file2~
4 f4
gurprem@ubuntu:~/gurprem$ ls -r -s -S
total 560
0 new$documnet#~
4 file1~
0 new
4 f7
0 file file
4 f5~
0 f9
4 f2
UE123029
Page 29
4
4
4
4
f6
f1~
demo~
f1
4
0
0
0
0
0
0
4
4
16
28
f2~
f10
f8
f9
file file
new
new$documnet#~
gg2
gg1
typescript
lab work 1.2
0
0
4
4
f8
f10
f2~
f4
4
4
4
4
f4~
new$documnet#
f5
file2~
21. w
gurprem@ubuntu:~/gurprem$ ls
demo~ file1~
f1
file2~
f1~
file file
f10
gg1
f2
gg2
f2~
lab work 1.2
f3
lab work 1.3
f4
new
f4~
new$documnet#
f5
new$documnet#~
f5~
os1~
f6
test
f7
typescript
f8
typescript~
f9
typescript-lab1
file1
22. -1
gurprem@ubuntu:~/gurprem$ ls
demo~
f1
f1~
f10
f2
f2~
f3
f4
f4~
f5
f5~
f6
f7
f8
f9
file1
file1~
file2~
file file
gg1
gg2
lab work 1.2
lab work 1.3
new
UE123029
-w 25
-1
Page 30
4
4
4
4
os1~
file1
f3
test
new$documnet#
new$documnet#~
os1~
test
typescript
typescript~
typescript-lab1
COMMAND MKDIR:
mkdir command is used to create one or more directories.
SYNTAX:
The Syntax is
mkdir [options] directories
DESCRIPTION:
-m
-p
-v
USAGE:
Create directory:
gurprem@ubuntu:~/gurprem$ mkdir test
The above command is used to create the directory 'test'.
Create directory and set permissions:
gurprem@ubuntu:~/gurprem$ mkdir -m -wx test
gurprem@ubuntu:~/gurprem$ cd test
bash: cd: test: Permission denied
Command WHO
who command can list the names of users currently logged in, their terminal,
the time they have been logged in, and the name of the host from which they have
logged in.
SYNTAX:
The Syntax is
who [options] [file]
DESCRIPTION:
am i
-b
-d
-H
-m
Print the username of the invoking user, The 'am' and 'i' must be
space separated.
Prints time of last system boot.
print dead processes.
Print column headings above the output.
Same as who am i.
UE123029
Page 31
-q
-T,-w
USAGE:
1.
gurprem@ubuntu:~/gurprem$ who
gurprem :0
2014-09-02 13:05 (:0)
gurprem pts/1
2014-09-02 13:12 (:0)
2. gurprem@ubuntu:~/gurprem$ whoami
Gurprem
3.
gurprem@ubuntu:~/gurprem$ who -b
system boot 2014-09-01 19:47
4.
gurprem@ubuntu:~/gurprem$ who -d
pts/0
2014-09-01 20:14
term=0 exit=0
0 id=/0
5.
gurprem@ubuntu:~/gurprem$ who -H
NAME
LINE
TIME
COMMENT
gurprem :0
2014-09-02 13:05 (:0)
gurprem pts/1
2014-09-02 13:12 (:0)
6.
gurprem@ubuntu:~/gurprem$ who -m
gurprem pts/1
2014-09-02 13:12 (:0)
7.
gurprem@ubuntu:~/gurprem$ who -q
gurprem gurprem
# users=2
COMMAND PWD:
pwd - Print Working Directory. pwd command prints the full filename of the
current working directory.
SYNTAX:
The Syntax is
pwd [options]
OPTIONS:
UE123029
Page 32
-P
-L
USAGE:
1.
gurprem@ubuntu:~/gurprem$ pwd
/home/gurprem/gurprem
COMMAND
WC
Word Count (Wc) command counts and displays the number of lines, words,
character and number of bytes enclosed in a file.
SYNTAX:
The Syntax is
wc [filename]
OPTIONS:
-c
-m, --chars
-l, --lines
-L, --max-linelength
-w, --words
--help
--version
USAGE:
1.
4
gurprem@ubuntu:~/gurprem$ wc test
18 102 test.txt
4 = Lines
18 = Words
102 = Bytes
In the above example, the word count cmd counts and displays the
number of lines, words, bytes in the file test.txt.
gurprem@ubuntu:~/gurprem$ wc c demo
31 demo
gurprem@ubuntu:~/gurprem$ wc l demo
UE123029
Page 33
1 demo
gurprem@ubuntu:~/gurprem$ $ wc L demo
30 demo
gurprem@ubuntu:~/gurprem$ wc m demo
31 demo
gurprem@ubuntu:~/gurprem$ wc w demo
5 demo
Displays
Displays
Displays
Displays
Displays
Displays
USAGE:
1.
gurprem@ubuntu:~/gurprem$ cal -1
September 2014
Su Mo Tu We Th Fr Sa
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
2
gurprem@ubuntu:~/gurprem$ cal -3
August 2014
September
Su Mo Tu We Th Fr Sa
Su Mo Tu We
1 2
1 2 3
3 4 5 6 7 8 9
7 8 9 10
10 11 12 13 14 15 16
14 15 16 17
17 18 19 20 21 22 23
21 22 23 24
24 25 26 27 28 29 30
28 29 30
UE123029
2014
Th Fr
4 5
11 12
18 19
25 26
Page 34
Sa
6
13
20
27
October 2014
Su Mo Tu We Th
1 2
5 6 7 8 9
12 13 14 15 16
19 20 21 22 23
26 27 28 29 30
Fr
3
10
17
24
31
Sa
4
11
18
25
3
gurprem@ubuntu:~/gurprem$ cal -j
September 2014
Su Mo Tu We Th Fr Sa
244 245 246 247 248 249
250 251 252 253 254 255 256
257 258 259 260 261 262 263
264 265 266 267 268 269 270
271 272 273
4.
gurprem@ubuntu:~/gurprem$ cal 3 2013
March 2013
Su Mo Tu We Th Fr Sa
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
5.
gurprem@ubuntu:~/gurprem$ ncal
September 2014
Su
7 14 21 28
Mo 1 8 15 22 29
Tu 2 9 16 23 30
We 3 10 17 24
Th 4 11 18 25
Fr 5 12 19 26
Sa 6 13 20 27
Command RMDIR :
Removes a directory.
SYNTAX :
rmdir [-p] directory ...
DESCRIPTION:
The rmdir utility removes the directory entry specified by each
directory argument , provided the directory is empty.
Arguments are processed in the order given. In order to remove both a parent
directory and a subdirectory of that parent, the subdirectory must be specified first
so the parent directory is empty when rmdir tries to remove it.
Options
--ignorefail-onnon-
UE123029
Page 35
empty
-p
-v, -verbose
USAGE:
1.
gurprem@ubuntu:~/gurprem$ rmdir -p gg //gg empty
gurprem@ubuntu:~/gurprem$ ls
demo~ f4
gg1
lab work 1.3
os1~
f1
file2~
gg2
new$documnet#
test
f2
file file lab work 1.2 new$documnet#~ test2
gurprem@ubuntu:~/gurprem$ rmdir -v gg1
rmdir: removing directory, gg1
rmdir: failed to remove gg1: Directory not empty
typescript~
typescript-lab1
Command CP:
Copies files and directories.
SYNTAX:
cp [OPTION]...SOURCE DESTINATION
USAGE:
1.
gurprem@ubuntu:~/gurprem$ cp f1 f2
gurprem@ubuntu:~/gurprem$ cat f1
in f1!
gurprem@ubuntu:~/gurprem$ cat f2
in f1!
This command shall copy f1 contents into f2 and overwrite f2.
2.
gurprem@ubuntu:~/gurprem$ cp -v
f1 -> f2
f1 f2
Command MV:
The mv command is used to move or rename files.
UE123029
Page 36
SYNTAX:
mv [OPTIONS].. filename NewName
USAGE:
gurprem@ubuntu:~/gurprem$ mv f1 file1
gurprem@ubuntu:~/gurprem$ ls
demo~ f2~
file2~
gg2
new$documnet#
test
f1~
f4
file file1 lab work 1.2 new$documnet#~ typescript~
f2
file1 gg1
lab work 1.3 os1~
typescriptlab1this is my second file
Command DIFF:
Diff analyzes two files and prints the lines that are different. Essentially, it outputs
a set of instructions for how to change first file in order to make it identical to the
second file.
Command CD
The cd command, which stands for "change directory", changes the shell's current
working directory.
DESCRIPTION:
The cd command is one of the commands you will use the most at the command
line in linux. It allows you to change your present working directoryx. You use it to
move around within the hierarchy of your file system.
UE123029
Page 37
USAGE:
gurprem@ubuntu:~/gurprem cd Desktop
gurprem@ubuntu:~/gurprem/Desktop$ cd os
gurprem@ubuntu:~/gurprem/Desktop/os$ cd oslab1
gurprem@ubuntu:~/gurprem/Desktop/os/oslab1$
Command RMDIR:
Removes a directory.
SYNTAX:
rmdir [-p] directory ...
DESCRIPTION:
The rmdir utility removes the directory entry specified by each directory argument,
provided the directory is empty.
Arguments are processed in the order given. In order to remove both a parent
directory and a subdirectory of that parent, the subdirectory must be specified first
so the parent directory is empty when rmdir tries to remove it.
OPTIONS:
--ignore-fail-on-nonempty
-p
-v, --verbose
--help
--version
USAGE:
gurprem@ubuntu:~/gurprem/Desktop/os/oslab1$ rmdir mydir
Removes the directory mydir.
Command whoami
Whoami Prints current user ID. Equivalent to id -un.
USAGE:
gurprem@ubuntu:~/gurprem$ whoami
gurprem
COMMAND MORE:
Displays text, one screen at a time.
UE123029
Page 38
DESCRIPTION:
more is a filter for paging through text one screen at a time. It does not provide as
many options or enhancements as less, but is nevertheless quite useful and simple
to use.
Options
-num
Sets the number of lines that makes up a screenful. lines must be an integer.
lines
Causes more to count logical, rather than screen lines (i.e., long lines are not
-f
wrapped).
Do not scroll. Instead, clear the whole screen and then display the text. This
-p
option is switched on automatically if the more executable is named page.
Do not scroll. Instead, paint each screen from the top, clearing the remainder
-c
of each line as it is displayed.
-s
Squeeze multiple blank lines into one blank line.
-u
Do not display underlines.
+/strin Search for the string string, and advance to the first line containing string
g
when the file is displayed.
+num Start displaying text at line number num.
USAGE:
1.more +3 myfile
Display the contents of file myfile, beginning at line 3.
gurprem@ubuntu:~/gurprem$ more +3 myfile
this is line 3
this is line 4
this is last line
2.more +/"super" myfile
Display the contents of file myfile, beginning at the first line
containing the string "super".
gurprem@ubuntu:~/gurprem$
...skipped
UE123029
Page 39
List the contents of the current directory with ls, using more to
display the list one screen at a time.
gurprem@ubuntu:~/gurprem $ ls|more
area1
area1~
bubble
demo~
demo1
myfile
myfile~
4.-s
UE123029
Page 40
-n
-q
(default)
-v
1.
gurprem@ubuntu:~/gurprem$ head labwork
sane-v4l (5)
- SANE interface for Video for Linux API
savelog (8)
- save a log file
scalb (3)
- multiply floating-point number by integral
pow...
scalbf (3)
- multiply floating-point number by integral
pow...
scalbl (3)
- multiply floating-point number by integral
pow...
scalbln (3)
- multiply floating-point number by integral
pow...
scalblnf (3)
- multiply floating-point number by integral
pow...
scalblnl (3)
- multiply floating-point number by integral
pow...
scalbn (3)
- multiply floating-point number by integral
pow...
scalbnf (3)
- multiply floating-point number by integral
pow...
2. c
gurprem@ubuntu:~/gurprem$ head -c 10 labwork
sane-v4l (
sane-v4l (gurprem@ubuntu:~/gurprem$ head -c -5 file1
in file1
i am a bad boy!
hello !
lets get started!
gurprem@ubuntu:~/gurprem$ head file1
in file1
i am a bad boy!
hello !
lets get started!
bye!
gurprem@ubuntu:~/gurprem$
UE123029
Page 41
3.-n
gurprem@ubuntu:~/gurprem$ head -n 2 file1
in file1
i am a bad boy!
gurprem@ubuntu:~/gurprem$ head -n -4 file1
in file1
i am a bad boy!
hello !
4.-q
gurprem@ubuntu:~/gurprem$ head -q file1
in file1
i am a bad boy!
hello !
lets get started!
bye!
5. v
gurprem@ubuntu:~/gurprem$ head -v file1
==> file1 <==
in file1
i am a bad boy!
hello !
lets get started!
bye!
COMMAND
TAIL:
UE123029
Page 42
-v
1.-c
gurprem@ubuntu:~/gurprem$ tail -c 5 file1
bye!
gurprem@ubuntu:~/gurprem$ tail -c +5 file1
ile1
i am a bad boy!
hello !
lets get started!
bye!
2.n
gurprem@ubuntu:~/gurprem$ tail -n 4 file1
lets get started!
bye!
gurprem@ubuntu:~/gurprem$ tail -n +4 file1
hello !
lets get started!
bye!
gurprem@ubuntu:~/gurprem$
3.-q
gurprem@ubuntu:~/gurprem$ tail -q
in file1
i am a bad boy!
file1
hello !
lets get started!
bye!
4 . v
gurprem@ubuntu:~/gurprem$ tail -v
==> file1 <==
in file1
i am a bad boy!
file1
hello !
lets get started!
UE123029
Page 43
bye!
COMMAND LESS:
less - opposite of more
OPTIONS:
option
-n
-N
--pattern=pattern
-s
+x
description
Suppress numbering
Display numbering
Match according to pattern
Squeeze the multiple blank lines into one
Skip x lines from beggining
Usage:
1 gurprem@ubuntu:~$ less myfile11 or less n myfile11
this is line 1
this is line 2
this is line 3
this is line 4
this is line 5
this is line 6
this is line 7
it is line 8
it is line 9
2 gurprem@ubuntu:~$.less N myfile11
1 this is line 1
2 this is line 2
3 this is line 3
4 this is line 4
5 this is line 5
6 this is line 6
7
8
9
10
11 this is line 7
12 it is line 8
13 it is line 9 and \n this is line 10
14
UE123029
Page 44
UE123029
Page 45
Music
myfile
myfile1
myfile1!
myfile11
myfile11~
Pictures
prog1
prog2
prog3
prog4
prog5
Public
Templates
Videos
EXPERIMENT 3
AIM:To implement various linux/unix commands :
Sort,comm.,diff,grep,whatis,whereis,gzip,gunzip,tar,zip,unzip,chmod
COMMAND SORT:
sort - sort lines of text files
SYNTAX:
sort [OPTION]... [FILE]...
sort [OPTION]... --files0-from=F
DESCRIPTION
Write sorted concatenation of all FILE(s) to standard output.
-b
(default)
UE123029
Page 46
-d
(Default)
-R
-sort==WO
RD
-c
-m
-o
USAGE:
1.
gurprem@ubuntu:~/gurprem$ sort
file1
bye!
hello !
i am a bad boy!
in file1
lets get started!
gurprem@ubuntu:~/gurprem$ sort
-b file1
bye!
hello !
i am a bad boy!
in file1
lets get started!
2.
gurprem@ubuntu:~/gurprem$ sort
1bye!
hello !
i am a bad boy!
in file1
lets get started!
3.-R
gurprem@ubuntu:~/gurprem$ sort
LETS GET STARTED!
i am a bad boy!
1bye!
in file1
HELLO!
-d file1
-R file1
4.--sort
UE123029
Page 47
gurprem@ubuntu:~/gurprem$ sort
HELLO!
i am a bad boy!
in file1
LETS GET STARTED!
1bye!
--sort=g file1
5. c
gurprem@ubuntu:~/gurprem$ sort -c file1
sort: file1:2: disorder:
i am a bad boy!
gurprem@ubuntu:~/gurprem$ sort -o f11 file1
gurprem@ubuntu:~/gurprem$ sort f11
1bye!
HELLO!
i am a bad boy!
in file1
LETS GET STARTED
6. m
gurprem@ubuntu:~/gurprem$ sort -m f4 f6
1
1234
2
3
3
45
45
45
abc
b3
hey
hgj
hgn
yz
EXP -3
COMMAND WHATIS
whatis command is used to know about what a particular command is applied for, and it displays
the keyword, use of the keyword in a single line.
SYNTAX:
whatis keyword(s)
USAGE:
Page 48
man (1)
manuals
man (7)
Command whereis
whereis command is used to search and locate source or binary files in the system. This
command will return the path where the files are located.
SYNTAX:
whereis [OPTIONS] files
OPTIONS:
-b
-m
-s
-u
-B
-M
-S
USAGE:
1.
gurprem@ubuntu:~/gurprem$ whereis ls
ls: /bin/ls /usr/share/man/man1/ls.1.gz
2.
gurprem@ubuntu:~/gurprem$ whereis -b ls
ls: /bin/ls
3.
gurprem@ubuntu:~/gurprem$ whereis -s ls
ls:
gurprem@ubuntu:~/gurprem$ whereis -m ls
ls: /usr/share/man/man1/ls.1.gz
gurprem@ubuntu:~/gurprem$
UE123029
Page 49
Page 50
UE123029
compressed size
uncompressed
size
compression ratio (0.0% if
unknown)
uncompressed_na name of the uncompressed
me
file
The uncompressed size is given as -1 for files not in gzip format,
such as compressed .Z files. To get the uncompressed size for
such a file, you can use:
ratio
zcat file.Z | wc -c
In combination with the --verbose option, the following fields are
also displayed:
method
compression method
the
32-bit
CRC
of
the
crc
uncompressed data
date
& time
stamp
for
the
time
uncompressed file
The compression methods currently supported are deflate,
compress, lzh (SCO compress -H) and pack. The crc is given as
ffffffff for a file not in gzip format.
-L, --license Display the gzip license and exit.
When compressing, do not save the original file name and
timestamp by default. (The original name is always saved if the
name had to be truncated.) When decompressing, do not restore
-n, --no-name the original file name if present (remove only the gzip suffix from
the compressed file name) and do not restore the original time
stamp if present (copy it from the compressed file). This option is
the default when decompressing.
When compressing, always save the original file name and time
stamp; this is the default. When decompressing, restore the
-N, --name
original file name and time stamp if present. This option is useful
on systems which have a limit on file name length or when the
time stamp has been lost after a file transfer.
-q, --quiet
Suppress all warnings.
Travel the directory structure recursively. If any of the file names
specified on the command line are directories, gzip will descend
-r, --recursive
into the directory and compress all the files it finds there (or
decompress them in the case of gunzip).
-S
.suf, When compressing, use suffix .suf instead of .gz. Any non-empty
--suffix .suf
suffix can be given, but suffixes other than .z and .gz should be
avoided to avoid confusion when files are transferred to other
UE123029
Page 52
systems.
When decompressing, add .suf to the beginning of the list of
suffixes to try, when deriving an output file name from an input
file name.
Verbose. Display the name and percentage reduction for each
-v, --verbose
file compressed or decompressed.
Version. Display the version number and compilation options
-V, --version
then quit.
Regulate the speed of compression using the specified digit #,
where -1 or --fast indicates the fastest compression method (less
-#,
--fast,
compression) and -9 or --best indicates the slowest compression
--best
method (best compression). The default compression level is -6
(that is, biased towards high compression at expense of speed).
USAGE:
1.gurprem@ubuntu:~/gurprem$ gzip backup.tar
Compresses
the
tar
archive
backup.tar,
backup.tar.gz.
and
renames
it
renaming
it
the
gzipped
file
backup.tar.gz,
UE123029
Page 53
gg2
mask4
labwork
mask5
new
maks5
mask1
mask2
mask3
new$documnet#
new$documnet#~
os1~
test
file2~
file file
gg1
gg2
mask4.gz
labwork
mask5
new
maks5
newDir
mask1
mask2
mask3
new$documnet#
new$documnet#~
os1~
8. to redirect c
gurprem@ubuntu:~/gurprem$ gzip
gurprem@ubuntu:~/gurprem$
gurprem@ubuntu:~/gurprem$ ls
abd
dir f3
f8
os1~
chmodfile f1
f4
f9
test
d1
f1~ f4~ file1~
typescript
d2
f10 f5
file1.gz
typescript~
UE123029
mask4.gz
labwork
mask5
new
maks5
newDir
Page 54
d4
f11 f5~
typescript-lab1
demo~
f2
f6
demo3
f2~ f7
file2~
mask1
new$documnet#
file file
gg1
mask2
mask3
new$documnet#~
new.gz
gurprem@ubuntu:~/gurprem$ gzip
gurprem@ubuntu:~/gurprem$ ls
abd
dir f3
f7
new.gz
chmodfile f1
f3.gz f8
os1~
d1
f1~ f4
f9
test
d2
f10 f4~
file1~
typescript
d4
f11 f5
file1.gz
typescript~
demo~
f2
f5~
file2~
typescript-lab1
demo3
f2~ f6
file file
-k f3
gg1
mask3
gg2
mask4.gz
labwork
mask5
new
maks5
newDir
mask1
new$documnet#
mask2
new$documnet#~
gurprem@ubuntu:~/gurprem$ gzip
-k -l
f7 f8
f7 f8
ratio uncompressed_name
6.8% file1
UE123029
Page 55
the
GNU
General
Public
<http://www.gnu.org/licenses/gpl.html>.
There is NO WARRANTY, to the extent permitted by law.
License
gurprem@ubuntu:~/gurprem$
gurprem@ubuntu:~/gurprem$
abd
f1~
f4
new$documnet#~
chmodfile f10
f4~
d1
f10.gz f5
d2
f11
f5~
d4
f11.gz f6
demo~
f2
f7
typescript~
demo3
f2~
f7.gz
typescript-lab1
dir
f3
f8
f1
f3.gz
f8.gz
mask1
mask2
mask3
mask4.gz
mask5
new.gz
os1~
test
typescript
gg2
new
labwork
lab work 1.3
newDir
new$documnet#
gurprem@ubuntu:~/gurprem$
gurprem@ubuntu:~/gurprem$
abd
f1~
f4
chmodfile f10
f4~
d1
f10.gz f5
d2
f11
f5~
d4
f11.gz f6
demo~
f2
f7
demo3
f2~
f7.gz
dir
f3
f8
lab1
f1
f3.gz
f8.gz
gzip -S .gg -k f9
ls
f9
lab work 1.3
f9.gg
maks5
file1~
mask1
file1.gz
mask2
file2~
mask3
file file mask4.gz
gg1
mask5
gg2
new
labwork
newDir
Page 56
new$documnet#
new$documnet#~
new.gz
os1~
test
typescript
typescript~
typescript-
COMMAND TAR:
Tar stores and extracts files from a tape or disk archive.
1. Cvf
c Creates a new .tar archive file.
v Verbosely show the .tar file progress.
f File name type of the archive file.
f9.gg
maks5
file1~
file1.gz
file2~
mask1
mask2
mask3
new.gz
os1~
file file
gg1
mask4.gz
mask5
test
gg2
new
labwork
newDir
new$documnet#
COMMAND CHMOD:
change file mode bits
SYNTAX:
chmod [OPTION]... MODE[,MODE]... FILE...
UE123029
tarfile.tar newDir
Page 57
Option:
-c
-v
Description:
like verbose but report only when a change is made
output a diagnostic for every file processed
USAGE:
1.default for directory -775
drwxrwxr-x 2 gurprem gurprem
4096 Sep
7 01:43 gg1
UE123029
Page 58
COMMAND comm
Compare two sorted files line-by-line.
SYNTAX
comm [OPTION]... FILE1 FILE2
Description
Compare sorted files FILE1 and FILE2 line-by-line.
With no options, comm produces three-column output. Column one contains
lines unique to FILE1, column two contains lines unique to FILE2, and
column three contains lines common to both files. Each of these columns can
be suppressed individually with options.
Options
-1
-2
-3
--check-order
--nocheck-order
--output-delimiter=STR
--help
--version
USAGE:
comm -12 gur1 gur2
Print only the lines present in both gur1 and gur2.
gurprem@ubuntu:~/gurprem$ comm gur1 gur2
hello
i am from chandigarh
i am from hoshiarpur
i am not much used to crowded places.
i like travelling and explore new places
my name is gurprem
gurprem@ubuntu:~/gurprem$ comm -12 gur1 gur2
hello
UE123029
Page 59
UE123029
Page 60
EXPERIMENT 4
AIM:To implement various linux/unix commands :
Tty,rm,bc,tr,cut,umask,free
COMMAND TTY:
Print the file name of the terminal connected to standard input.
SYNTAX:
tty [OPTION]...
OPTIONS:
-s, --silent,
--quiet
--help
--version
USAGE:
tty
Running tty by itself will display the current tty session as shown below:
gurprem@ubuntu:~$ tty
/dev/pts/0
COMMAND: rm
The rm command removes (deletes) files or directories.
SYNTAX:
rm. [OPTION]... FILE...
Description
rm removes each specified FILE. By default, it does not remove
directories; seeRemoving Directories below for details.
UE123029
Page 61
Options
-f, --force
-i
-I
-v, --verbose
USAGE:
1.
gurprem@ubuntu:~/gurprem$ rm demo
2.
rm: cannot remove fle1: No such file or directory
gurprem@ubuntu:~/gurprem$ rm -i file1
rm: remove regular file file1? n
3.
gurprem@ubuntu:~/gurprem$ rm -I f1 f2 f3 f4
rm: remove all arguments? N
4.
gurprem@ubuntu:~/gurprem$ rm -v f3
removed f3
COMMAND bc
bc is an arbitrary-precision language for performing math calculations.
DESCRIPTION
bc is a language that supports arbitrary-precision numbers, meaning that it
delivers accurate results regardless of how large (or very very small) the
numbers are.
It has an interactive mode, accepting input from the terminal and providing
calculations on request. As a language, its syntax is similar to the C
UE123029
Page 62
Command : tr
The tr command automatically translates (substitutes) sets of characters.
Syntax
tr [-Ccsu] string1 string2
Description
The tr utility copies the standard input to the standard output with
substitution or deletion of selected characters.
UE123029
Page 63
Options
-C
-c
-d
-s
-u
Complement the set of characters in string1, that is "-C ab" includes every
character except for 'a' and 'b'.
Same as -C but complement the set of values in string1.
Delete characters in string1 from the input.
Squeeze multiple occurrences of the characters listed in the last operand
(either string1 or string2) in the input into a single instance of the
character. This occurs after all deletion and translation is completed.
Guarantee that any output is unbuffered.
UE123029
Page 64
Command CUT
remove sections from each line of files
SYNOPSIS
cut OPTION... [FILE]...
DESCRIPTION
Print selected parts of lines from each FILE to standard output.
-c
select only these characters in that line
-d
use DELIM instead of TAB for field delimiter
-f
select only these fields; also print any line that contains
no delimiter character, unless the -s option is specified
-complement the set of selected bytes, characters or fields
complement
-s
do not print lines not containing delimiters
1. c
gurprem@ubuntu:~/gurprem$ cut -c 3 file1
i
L
T
Y
//3rd character
UE123029
Page 65
e!
//3rd character onwards
gurprem@ubuntu:~/gurprem$ cut -c 3- file1
file1
i
am a bad boy!
LLO!
TS GET STARTED!
ye!
// upto 3rd character
gurprem@ubuntu:~/gurprem$ cut -c -3
in
i
HEL
LET
1by
file1
//whole line
gurprem@ubuntu:~/gurprem$ cut -c 1- file1
in
file1
i am a bad boy!
HELLO!
LETS GET STARTED!
1bye!
2. d f
gurprem@ubuntu:~/gurprem$ cut -d' ' -f2 file1
file1
HELLO!
GET
1bye!
//use
as delimiter
-f
gurprem@ubuntu:~/gurprem$ cut
in
i
HELLO!
LETS GET STARTED!
1bye!
-f1 file1
UE123029
Page 66
-f1 file1
HELLO!
LETS GET STARTED!
1bye!
gurprem@ubuntu:~/gurprem$ cut -f1 file1
in
i
HELLO!
LETS GET STARTED!
1bye!
gurprem@ubuntu:~/gurprem$ cat file1
in
file1
i am a bad boy!
HELLO!
LETS GET STARTED!
1bye!
4. s
gurprem@ubuntu:~/gurprem$ cut -s -f1 file1
in
i
gurprem@ubuntu:~/gurprem$ cat file1
in
file1
i am a bad boy!
HELLO!
LETS GET STARTED!
1bye!
??? mention pipe command and diff btw pipe and ;
COMMAND TEE:
read from standard input and write to standard output and files
SYNOPSIS
tee [OPTION]... [FILE]...
DESCRIPTION
Copy standard input to each FILE, and also to standard output.
Option:
Description:
-a
append to the given FILEs, do not overwrite
1.-a
gurprem@ubuntu:~/gurprem$ tee -a file1
adding text to file1
adding text to file1
^C
gurprem@ubuntu:~/gurprem$ cat file1
in
file1
i am a bad boy!
HELLO!
LETS GET STARTED!
1bye!
UE123029
Page 67
q
gurprem@ubuntu:~/gurprem$ tee f2
adding to f2
adding to f2
gurprem@ubuntu:~/gurprem$ cat f2
adding to f2
2. Using cut tee
gurprem@ubuntu:~/gurprem$ cut -c 3-5 file1 | tee f2
fi
i
LLO
TS
ye!
din
ain
gurprem@ubuntu:~/gurprem$ cat f2
fi
i
LLO
TS
ye!
din
ain
3. The following command (with the help of tee command) writes the
output both to the screen (stdout) and to the file.
gurprem@ubuntu:~/gurprem$ ls -l | tee f3
total 560
-rw-rw-r-- 1 gurprem gurprem
44 Sep 2 13:15 demo~
-rw-rw-r-- 1 gurprem gurprem
48 Sep 3 02:58 f1
-rw-rw-r-- 1 gurprem gurprem
38 Sep 3 02:57 f1~
-rw-rw-r-- 1 gurprem gurprem
0 Sep 3 04:01 f10
-rw-rw-r-- 1 gurprem gurprem
58 Sep 6 12:40 f11
-rw-rw-r-- 1 gurprem gurprem
29 Sep 6 23:59 f2
-rw-rw-r-- 1 gurprem gurprem
7 Sep 2 23:29 f2~
-rw-rw-r-- 1 gurprem gurprem
0 Sep 7 00:05 f3
-rw-rw-r-- 1 gurprem gurprem
8 Sep 3 03:54 f4
UE123029
Page 68
3
3
3
3
3
3
3
6
6
27
31
2
27
31
31
6
31
31
27
2
3
31
31
03:30
03:58
03:10
03:22
03:42
03:46
03:46
23:56
12:35
02:53
04:39
23:13
03:38
05:03
05:15
11:17
04:16
04:12
03:11
13:46
03:44
05:05
05:08
f4~
f5
f5~
f6
f7
f8
f9
file1
file1~
file2~
file file
gg1
gg2
labwork
lab work 1.3
new
new$documnet#
new$documnet#~
os1~
test
typescript
typescript~
typescript-lab1
4. Ech0 + tee
gurprem@ubuntu:~/gurprem$ echo " echo and tee combined" | tee f1
echo and tee combined
gurprem@ubuntu:~/gurprem$ cat f1
echo and tee combined
5. Tee with multiple files at once //without displaying on stdoutput
gurprem@ubuntu:~/gurprem$
1234
45
gurprem@ubuntu:~/gurprem$
1234
45
1234
45
1234
45
gurprem@ubuntu:~/gurprem$
f4to f5
^C
gurprem@ubuntu:~/gurprem$
f4to f5
gurprem@ubuntu:~/gurprem$
f4to f5
gurprem@ubuntu:~/gurprem$
-a f4 to f5
^C
UE123029
cat f4
cat f5
tee f4>f5
cat f4
cat f5
tee -a f4>f5
Page 69
gurprem@ubuntu:~/gurprem$ cat f4
f4to f5
-a f4 to f5
gurprem@ubuntu:~/gurprem$ tee -a f4>f5
6. Writing to multiple files without displaying again on console
gurprem@ubuntu:~/gurprem$
in f4 f5
in f4 f5
^C
gurprem@ubuntu:~/gurprem$
in f4 f5
in f4 f5
gurprem@ubuntu:~/gurprem$
again in f4 f5
again in f4 f5
^C
gurprem@ubuntu:~/gurprem$
gurprem@ubuntu:~/gurprem$
in f4 f5
again in f4 f5
in f4 f5
again in f4 f5
tee f4 f5
cat f4 f5
tee -a f4 f5
cat f4 f5
COMMAND PASTE:
merge lines of files
SYNOPSIS
paste [OPTION]... [FILE]...
DESCRIPTION :
Write lines consisting of the sequentially corresponding lines from each
FILE, separated by TABs, to standard output. With no FILE, or when FILE is -,
read standard input
Option:
-s
-d
Description:
paste one file at a time instead of in parallel
reuse characters from LIST instead of TABs
USAGE:
1.
gurprem@ubuntu:~/gurprem$ paste f1
f1 file!
welcome !
great weather!
2.s
gurprem@ubuntu:~/gurprem$ paste file1 f1
in:file1
f1 file!
UE123029
Page 70
UE123029
Page 71
NAME
SYNOPSIS
#include <sys/types.h>
#include <sys/stat.h>
mode_t umask(mode_t mask);
1.
gurprem@ubuntu:~/gurprem$ umask 003
gurprem@ubuntu:~/gurprem$ touch mask1
gurprem@ubuntu:~/gurprem$ touch mask2
gurprem@ubuntu:~/gurprem$ ls -l mask1 mask2
-rw-rw-r-- 1 gurprem gurprem 0 Sep 10 03:35 mask1
-rw-rw-r-- 1 gurprem gurprem 0 Sep 10 03:35 mask2
3.
gurprem@ubuntu:~/gurprem$ umask 777
gurprem@ubuntu:~/gurprem$ touch mask3
gurprem@ubuntu:~/gurprem$ ls -l mask3
---------- 1 gurprem gurprem 0 Sep 10 03:38 mask3
In umask for files if on subtracting from 666 results in activation of
x then it wont take that option but the next one .
COMMAND FREE:
SYNTAX
free [options]
DESCRIPTION
free displays the total amount of free and used physical and swap memory
in the system, as well as the buffers used by the kernel.
Option:
-b
-k
-m
-g
-c --count
-l
-s
-t
UE123029
Description:
Display the amount of memory in bytes.
Display the amount of memory in kilo-bytes.
Display the amount of memory in mega-bytes.
Display the amount of memory in giga-bytes.
Dispaly the result count number of times
Show detailed low and high memory statistics.
Continuously display the result delay seconds apart.
Display a line showing the column totals.
Page 72
1.
gurprem@ubuntu:~/gurprem$ free
total
used
cached
Mem:
2063812
1227792
758248
-/+ buffers/cache:
390340
Swap:
1046524
0
free
shared
buffers
836020
13460
79204
shared
buffers
13783040
81104896
shared
buffers
13460
79204
free
shared
buffers
816
13
77
free
shared
buffers
1673472
1046524
2.-b
gurprem@ubuntu:~/gurprem$ free -b
total
used
free
cached
Mem:
2113343488 1257250816 856092672
776462336
-/+ buffers/cache: 399683584 1713659904
Swap:
1071640576
0 1071640576
3 k default
gurprem@ubuntu:~/gurprem$ free -k
total
used
free
cached
Mem:
2063812
1227820
835992
758264
-/+ buffers/cache:
390352
1673460
Swap:
1046524
0
1046524
1. -m
gurprem@ubuntu:~/gurprem$ free -m
total
used
cached
Mem:
2015
1199
740
-/+ buffers/cache:
381
Swap:
1021
0
2. g
gurprem@ubuntu:~/gurprem$ free -g
total
used
cached
Mem:
1
1
0
-/+ buffers/cache:
0
Swap:
0
0
1634
1021
1
0
3. h
gurprem@ubuntu:~/gurprem$ free -h
UE123029
Page 73
total
used
cached
Mem:
2.0G
1.2G
740M
-/+ buffers/cache:
381M
Swap:
1.0G
0B
gurprem@ubuntu:~/gurprem$
free
shared
buffers
816M
13M
77M
shared
buffers
13M
77M
1.6G
1.0G
4. c
gurprem@ubuntu:~/gurprem$ free -h -c 3
total
used
free
cached
Mem:
2.0G
1.2G
816M
740M
-/+ buffers/cache:
381M
1.6G
Swap:
1.0G
0B
1.0G
total
cached
Mem:
2.0G
740M
-/+ buffers/cache:
Swap:
1.0G
used
free
shared
buffers
1.2G
816M
13M
77M
381M
0B
1.6G
1.0G
total
cached
Mem:
2.0G
740M
-/+ buffers/cache:
Swap:
1.0G
used
free
shared
buffers
1.2G
816M
13M
77M
381M
0B
1.6G
1.0G
shared
buffers
13M
77M
shared
buffers
13460
79204
5. l
gurprem@ubuntu:~/gurprem$ free -h -l
total
used
free
cached
Mem:
2.0G
1.2G
816M
740M
Low:
859M
546M
313M
High:
1.1G
653M
502M
-/+ buffers/cache:
381M
1.6G
Swap:
1.0G
0B
1.0G
6. s
gurprem@ubuntu:~/gurprem$ free -s 0.5 -c3
total
used
free
cached
Mem:
2063812
1227952
835860
758268
-/+ buffers/cache:
390480
1673332
Swap:
1046524
0
1046524
UE123029
Page 74
total
cached
Mem:
2063812
758268
-/+ buffers/cache:
Swap:
1046524
total
cached
Mem:
2063812
758272
-/+ buffers/cache:
Swap:
1046524
used
free
shared
buffers
1228208
835604
13460
79204
390736
0
1673076
1046524
used
free
shared
buffers
1228164
835648
13460
79204
390688
0
1673124
1046524
shared
buffers
13M
77M
7. -t
gurprem@ubuntu:~/gurprem$ free -t -h
total
used
free
cached
Mem:
2.0G
1.2G
816M
740M
-/+ buffers/cache:
381M
1.6G
Swap:
1.0G
0B
1.0G
Total:
3.0G
1.2G
1.8G
EXPERIMENT 5
Page 75
?
Usage :
1.
gurprem@ubuntu:~$ find /home/gurprem/Desktop/d1
/home/gurprem/Desktop/d1
2. find file in current dir
gurprem@ubuntu:~$ find hello
hello
3.* displays all the files and dir in current dir
/home/gurprem
gurprem@ubuntu:~$ find *
area
Desktop
Desktop/d1
Documents
Downloads
examples.desktop
hello
hello.c
Music
myfile
myfile1
myfile1!
Pictures
prog1
prog2
prog3
prog4
prog5
Public
Templates
Videos
gurprem@ubuntu:~$ cd Desktop
gurprem@ubuntu:~/Desktop$ find *
d1
COMMAND ULIMIT
ulimit - get and set user limits
COMMAND DF:
report file system disk space usage
SYNTAX:
df [OPTION]... [FILE]...
DESCRIPTION
UE123029
Page 76
df displays the amount of disk space available on the file system containing
each file name argument. If no file name is given, the space available on all
currently mounted file systems is shown. Disk space is shown in 1K
blocks by default
1.
gurprem@ubuntu:~/gurprem$ df
Filesystem
1K-blocks
Used Available Use% Mounted on
/dev/sda1
19478204 3555092 14910632 20% /
none
4
0
4
0% /sys/fs/cgroup
udev
1022332
4
1022328
1% /dev
tmpfs
206384
1112
205272
1% /run
none
5120
0
5120
0% /run/lock
none
1031904
184
1031720
1% /run/shm
none
102400
48
102352
1% /run/user
COMMAND DU:
estimate file space usage
SYNOPSIS
du [OPTION]... [FILE]...
du [OPTION]... --files0-from=F
DESCRIPTION
Summarize disk usage of each FILE, recursively for directories.
1.
gurprem@ubuntu:~/gurprem$ du
4
./test
12
./gg1
4
./gg2
572 .
2. b and -c
gurprem@ubuntu:~/gurprem$ du -b -c
4096 ./test
4142 ./gg1
4096 ./gg2
498341
.
498341
total
3. h
gurprem@ubuntu:~/gurprem$ du -h
4.0K ./test
12K ./gg1
4.0K ./gg2
572K .
COMMAND CLEAR:
UE123029
Page 77
UE123029
Page 78
COMMAND PS:
report a snapshot of the current processes.
SYNOPSIS
ps [options]
DESCRIPTION
ps displays information about a selection of the active processes. If you want a repetitive update
of the selection and the displayed information, use top(1) instead.
Option :
Description:
-e
Select all processes. Identical to -A.
-l
To display BSD long format.
-p x1 x2 or -pid
Select only processes with id x1 x2
-M
Add a column of security data
Usage:
gurprem@ubuntu:~$ ps
PID TTY
TIME
2752 pts/1
00:00:00
2923 pts/1
00:00:00
gurprem@ubuntu:~$ ps -e
PID TTY
TIME
1 ?
00:00:05
2 ?
00:00:00
3 ?
00:00:00
UE123029
CMD
bash
ps
CMD
init
kthreadd
ksoftirqd/0
Page 79
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
25
26
27
28
29
30
31
43
44
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
00:00:00
00:00:00
00:00:01
00:00:02
00:00:00
00:00:00
00:00:00
00:00:00
00:00:00
00:00:00
00:00:00
00:00:00
00:00:00
00:00:00
00:00:00
00:00:00
00:00:00
00:00:00
00:00:00
00:00:00
00:00:00
00:00:00
00:00:00
00:00:00
00:00:00
00:00:00
00:00:00
00:00:00
kworker/0:0
kworker/0:0H
kworker/u16:0
rcu_sched
rcu_bh
migration/0
watchdog/0
khelper
kdevtmpfs
netns
writeback
kintegrityd
bioset
kworker/u17:0
kblockd
ata_sff
khubd
md
devfreq_wq
khungtaskd
kswapd0
ksmd
khugepaged
fsnotify_mark
ecryptfs-kthrea
crypto
kthrotld
kworker/u16:1
.
.
.
gurprem@ubuntu:~$ ps -ef
UID
PID PPID C STIME TTY
root
1
0 1 02:18 ?
root
2
0 0 02:18 ?
root
3
2 0 02:18 ?
root
4
2 0 02:18 ?
root
5
2 0 02:18 ?
root
6
2 0 02:18 ?
root
7
2 0 02:18 ?
root
8
2 0 02:18 ?
root
9
2 0 02:18 ?
root
10
2 0 02:18 ?
root
11
2 0 02:18 ?
root
12
2 0 02:18 ?
root
13
2 0 02:18 ?
root
14
2 0 02:18 ?
root
15
2 0 02:18 ?
root
16
2 0 02:18 ?
root
17
2 0 02:18 ?
root
18
2 0 02:18 ?
root
19
2 0 02:18 ?
UE123029
TIME
00:00:05
00:00:00
00:00:00
00:00:00
00:00:00
00:00:01
00:00:02
00:00:00
00:00:00
00:00:00
00:00:00
00:00:00
00:00:00
00:00:00
00:00:00
00:00:00
00:00:00
00:00:00
00:00:00
Page 80
CMD
/sbin/init
[kthreadd]
[ksoftirqd/0]
[kworker/0:0]
[kworker/0:0H]
[kworker/u16:0]
[rcu_sched]
[rcu_bh]
[migration/0]
[watchdog/0]
[khelper]
[kdevtmpfs]
[netns]
[writeback]
[kintegrityd]
[bioset]
[kworker/u17:0]
[kblockd]
[ata_sff]
root
20
root
21
root
22
root
25
gurprem@ubuntu:~$
2
2
2
2
0
0
0
0
02:18
02:18
02:18
02:18
gurprem@ubuntu:~$ ps -l
F S
UID
PID PPID C PRI
0 S 1000 2752 2736 0 80
0 R 1000 3279 2752 0 80
gurprem@ubuntu:~$ ps
PID TTY
STAT
2 ?
S
3 ?
S
-p 2
TIME
0:00
0:00
gurprem@ubuntu:~$ ps -M
LABEL
unconfined
unconfined
[ksoftirqd/0]
?
?
?
?
00:00:00
00:00:00
00:00:00
00:00:00
NI ADDR SZ WCHAN
0 - 1724 wait
0 - 1248 -
[khubd]
[md]
[devfreq_wq]
[khungtaskd]
TTY
pts/1
pts/1
TIME CMD
00:00:00 bash
00:00:00 ps
3
COMMAND
[kthreadd]
[ksoftirqd/0]
-p 2 3
PID TTY
2 ?
3 ?
STAT
S
S
TIME COMMAND
0:00 [kthreadd]
0:00
COMMAND SHUTDOWN:
bring the system down
SYNOPSIS
shutdown [OPTION]... TIME [MESSAGE]
DESCRIPTION:shutdown arranges for the system to be brought down in a
safe way. All logged-in users are notified that the system is going down and,
within the last five minutes of TIME, new logins are prevented.
TIME may have different formats, the most common is simply the word
'now' which will bring the system down immediately. Other valid formats
are +m, where m is the number of minutes to wait until shutting down and
hh:mm which specifies the time on the 24hr clock.
COMMAND FINGER:
user information lookup program
SYNTAX:
finger [-lmsp] [user ...] [user@host ...]
DESCRIPTION
The finger displays information about the system users.
UE123029
Page 81
Option
-s (default)
-l
Description:
Finger displays the user's login name, real name, terminal
name and write status
Produces a multi-line format displaying all of the
information described for the -s option as well as the user's
home directory, home phone number, login shell, mail
status, and the contents of the files .plan, .project from
the user's home directory.
Usage:
gurprem@ubuntu:~$ finger
Login
Name
Tty
Idle
Office Phone
gurprem
Gurprem
*:0
gurprem
Gurprem
pts/0
gurprem
Gurprem
pts/11
gurprem@ubuntu:~$ finger -s
Login
Name
Tty
Idle
Office Phone
gurprem
Gurprem
*:0
gurprem
Gurprem
pts/0
gurprem
Gurprem
pts/11
gurprem@ubuntu:~$ finger -l
Login: gurprem
Directory: /home/gurprem
On since Sun Nov 23 05:30 (PST) on
On since Sun Nov 23 07:37 (PST) on
On since Sun Nov 23 05:34 (PST) on
3 minutes 4 seconds idle
No mail.
No Plan.
COMMAND LESS:
option
-n
-N
--pattern=pattern
-s
+x
Login Time
Office
Office
description
Suppress numbering
Display numbering
Squeeze the multiple blank lines into one
Skip x lines from beggining
Usage:
1 gurprem@ubuntu:~$ less myfile11 or less n myfile11
this is line 1
this is line 2
this is line 3
this is line 4
UE123029
Page 82
this is line 5
this is line 6
this is line 7
it is line 8
it is line 9
2 gurprem@ubuntu:~$.less N myfile11
1 this is line 1
2 this is line 2
3 this is line 3
4 this is line 4
5 this is line 5
6 this is line 6
7
8
9
10
11 this is line 7
12 it is line 8
13 it is line 9 and \n this is line 10
14
3. gurprem@ubuntu:~$ less s N myfile11
1 this is line 1
2 this is line 2
3 this is line 3
4 this is line 4
5 this is line 5
6 this is line 6
7
11 this is line 7
12 it is line 8
13 it is line 9
14
4 gurprem@ubuntu:~$.less s N pattern=this myfile11
1 this is line 1
2 this is line 2
3 this is line 3
4 this is line 4
5 this is line 5
6 this is line 6
7
UE123029
Page 83
11 this is line 7
12 it is line 8
13 it is line 9
14
5 gurprem@ubuntu:~$
less +4 N myfile11
4 this is line 4
5 this is line 5
6 this is line 6
7
8
9
10
11 this is line 7
12 it is line 8
13 it is line 9
6. gurprem@ubuntu:~$ less -4 -N +/"it" myfile11
12 it is line 8
13 it is line 9 and \n this is line 10
14
7. gurprem@ubuntu:~$ ls|less
area
Desktop
Documents
Downloads
examples.desktop
hello
hello.c
Music
myfile
myfile1
myfile1!
myfile11
myfile11~
Pictures
prog1
prog2
prog3
prog4
prog5
Public
Templates
Videos
UE123029
Page 84
EXPERIMENT 6
AIM: To implement various linux/unix commands :
Script,split,write,wall,dd,sleep,adduser,deluser,banner,useradd,us
erdel,usermod
COMMAND SCRIPT :
Make typescript of terminal session
SYNOPSIS
script [options] [file]
DESCRIPTION
script makes a typescript of everything displayed on your terminal. It is
useful for students who need a hardcopy record of an interactive session
as proof of an assignment, as the typescript file can be printed out later
with lpr.
OPTIONS:
-a
-f
-q
Be quiet.
-t
UE123029
Page 85
USAGE:
gurprem@ubuntu:~/gurprem script
Script started, file is typescript
gurprem@ubuntu:~/gurprem script -a
Script started, file is typescript
COMMAND SPLIT
split - split a file into pieces
SYNOPSIS
split [OPTION]... [INPUT [PREFIX]]
DESCRIPTION
Output fixed-size pieces of INPUT to PREFIXaa, PREFIXab, ...; default
size is 1000 lines, and default PREFIX is 'x'. With no INPUT, or when INPUT is
-, read standard input.
Options
-a
-c
-d
-l
--verbose
UE123029
Page 86
try000
try001
Videos
COMMAND WALL
wall - write a message to all users
SYNOPSIS
wall [-n] [-t timeout] [message | file]
DESCRIPTION
UE123029
Page 87
-n helps us remove the banner when broadcasting the message. But this
previledge is only with root or a superuser. So you need to be in the sudoers
to remove the banner.
COMMAND : DD
dd - convert and copy a file
SYNOPSIS
dd [OPERAND]...
dd OPTION
DESCRIPTION
Copy a file, converting and formatting according to the operands.
OPTIONS:
If
of
bs
Count
USAGE:
gurprem@ubuntu:~$ ls
demofile lab1 lab2
UE123029
lab3
shprog
Page 88
testfolder
Music
Pictures
gurprem@ubuntu:~$ ls -l test.txt
-rw-rw-r-- 1 gurprem gurprem 2097152 Nov 24 05:41 test.txt
gurprem@ubuntu:~$
NOTE: dd should be carefully handled. It can have dire consequencies. For
eg. If we missed the count flag in the above example this continuously write
to the file till my disk is full which is undesirable.
COMMAND SLEEP
sleep - delay for a specified amount of time.
SYNOPSIS
sleep NUMBER[SUFFIX]...
sleep OPTION
DESCRIPTION
Pause for NUMBER seconds. SUFFIX may be 's' for second (the default),
'm' for minutes, 'h' for hours or 'd' for days. Unlike most implementations
that require NUMBER be an integer, here NUMBER may be an arbitrary
floating point number. Given two or more arguments, pause for the amount
of time specified by the sum of their values.
COMMAND ADDUSER
adduser, addgroup - add a user or group to the system
SYNOPSIS
adduser [options] [--home DIR] [--shell SHELL] [--no-cre
ate-home] [--uid ID] [--firstuid ID] [--lastuid ID]
[--ingroup GROUP | --gid ID] [--disabled-password]
[--disabled-login] [--gecos GECOS] [--add_extra_groups]
[--encrypt-home] user
UE123029
Page 89
Page 90
Page 91
-d
-m
-p
-u
EXPERIMENT 7
AIM: To implement various linux/unix commands :
Ps,nohup,kill,nice,batch,at,crontab
COMMAND PS
report a snapshot of the current processes.
SYNTAX:
ps [options]
DESCRIPTION
ps displays information about a selection of the active processes. If you
want a repetitive update of the selection and the displayed information, use
top instead.
Options
-A
-a
-d
-C
-G
UE123029
Page 92
-u
-pid
-ppid
--cols
--lines
USAGE:
gurprem@ubuntu:~$ ps
PID TTY
TIME
2752 pts/1
00:00:00
2923 pts/1
00:00:00
gurprem@ubuntu:~$ ps -e
PID TTY
TIME
1 ?
00:00:05
2 ?
00:00:00
3 ?
00:00:00
4 ?
00:00:00
5 ?
00:00:00
6 ?
00:00:01
7 ?
00:00:02
8 ?
00:00:00
9 ?
00:00:00
10 ?
00:00:00
11 ?
00:00:00
12 ?
00:00:00
13 ?
00:00:00
14 ?
00:00:00
15 ?
00:00:00
16 ?
00:00:00
17 ?
00:00:00
18 ?
00:00:00
19 ?
00:00:00
20 ?
00:00:00
21 ?
00:00:00
22 ?
00:00:00
25 ?
00:00:00
26 ?
00:00:00
27 ?
00:00:00
28 ?
00:00:00
29 ?
00:00:00
30 ?
00:00:00
31 ?
00:00:00
43 ?
00:00:00
44 ?
00:00:00
45 ?
00:00:00
46 ?
00:00:00
UE123029
CMD
bash
ps
CMD
init
kthreadd
ksoftirqd/0
kworker/0:0
kworker/0:0H
kworker/u16:0
rcu_sched
rcu_bh
migration/0
watchdog/0
khelper
kdevtmpfs
netns
writeback
kintegrityd
bioset
kworker/u17:0
kblockd
ata_sff
khubd
md
devfreq_wq
khungtaskd
kswapd0
ksmd
khugepaged
fsnotify_mark
ecryptfs-kthrea
crypto
kthrotld
kworker/u16:1
scsi_eh_0
scsi_eh_1
Page 93
52 ?
69 ?
.
.
.
.
2464 ?
2467 ?
2471 ?
2476 ?
2508 ?
2515 ?
2556 ?
2561 ?
2569 ?
2583 ?
2588 ?
2594 ?
2604 ?
2638 ?
2660 ?
2671 ?
2686 ?
2688 ?
2702 ?
2736 ?
2751 ?
2752 pts/1
2799 pts/11
2840 ?
2841 ?
2848 ?
2883 ?
2907 pts/11
2916 pts/11
2926 pts/1
00:00:00 kworker/0:2
00:00:00 deferwq
00:00:00 gconfd-2
00:00:00 gvfs-gphoto2-vo
00:00:00 gvfs-afc-volume
00:00:00 gvfs-mtp-volume
00:00:00 gvfsd-burn
00:00:00 gvfsd-trash
00:00:00 gvfsd-metadata
00:00:00 telepathy-indic
00:00:00 mission-control
00:00:00 zeitgeist-datah
00:00:00 zeitgeist-daemo
00:00:00 zeitgeist-fts
00:00:00 cat
00:00:00 update-notifier
00:00:00 deja-dup-monito
00:00:00 unity-scope-hom
00:00:04 unity-scope-loa
00:00:00 unity-files-dae
00:00:00 unity-music-dae
00:00:05 gnome-terminal
00:00:01 gnome-pty-helpe
00:00:00 bash
00:00:00 bash
00:00:00 sh
00:00:00 run-parts
00:00:00 apt
00:00:00 sleep
00:00:00 man
00:00:00 pager
00:00:00 ps
gurprem@ubuntu:~$ ps -ef
UID
PID PPID C STIME TTY
root
1
0 1 02:18 ?
root
2
0 0 02:18 ?
root
3
2 0 02:18 ?
root
4
2 0 02:18 ?
root
5
2 0 02:18 ?
root
6
2 0 02:18 ?
root
7
2 0 02:18 ?
root
8
2 0 02:18 ?
root
9
2 0 02:18 ?
root
10
2 0 02:18 ?
root
11
2 0 02:18 ?
root
12
2 0 02:18 ?
UE123029
TIME
00:00:05
00:00:00
00:00:00
00:00:00
00:00:00
00:00:01
00:00:02
00:00:00
00:00:00
00:00:00
00:00:00
00:00:00
Page 94
CMD
/sbin/init
[kthreadd]
[ksoftirqd/0]
[kworker/0:0]
[kworker/0:0H]
[kworker/u16:0]
[rcu_sched]
[rcu_bh]
[migration/0]
[watchdog/0]
[khelper]
[kdevtmpfs]
root
13
root
14
root
15
root
16
root
17
root
18
root
19
root
20
root
21
root
22
root
25
root
26
root
27
root
28
root
29
root
30
root
31
root
43
root
44
root
45
root
46
root
52
root
69
root
70
root
125
root
126
root
127
root
128
root
137
root
138
root
294
--daemon
root
299
udevd --dae
message+
397
--fork
root
421
root
434
logind
syslog
448
root
451
avahi
452
[ubuntu.lo
avahi
457
helper
root
482
--daemon
root
491
root
626
root
679
root
721
1/polkitd --n
UE123029
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
02:18 ?
02:18 ?
02:18 ?
02:18 ?
02:18 ?
02:18 ?
02:18 ?
02:18 ?
02:18 ?
02:18 ?
02:18 ?
02:18 ?
02:18 ?
02:18 ?
02:18 ?
02:18 ?
02:18 ?
02:18 ?
02:18 ?
02:18 ?
02:18 ?
02:18 ?
02:18 ?
02:18 ?
02:18 ?
02:18 ?
02:18 ?
02:18 ?
02:18 ?
02:18 ?
0 02:18 ?
00:00:00 [netns]
00:00:00 [writeback]
00:00:00 [kintegrityd]
00:00:00 [bioset]
00:00:00 [kworker/u17:0]
00:00:00 [kblockd]
00:00:00 [ata_sff]
00:00:00 [khubd]
00:00:00 [md]
00:00:00 [devfreq_wq]
00:00:00 [khungtaskd]
00:00:00 [kswapd0]
00:00:00 [ksmd]
00:00:00 [khugepaged]
00:00:00 [fsnotify_mark]
00:00:00 [ecryptfs-kthrea]
00:00:00 [crypto]
00:00:00 [kthrotld]
00:00:00 [kworker/u16:1]
00:00:00 [scsi_eh_0]
00:00:00 [scsi_eh_1]
00:00:00 [kworker/0:2]
00:00:00 [deferwq]
00:00:00 [charger_manager]
00:00:00 [mpt_poll_0]
00:00:00 [mpt/0]
00:00:00 [kpsmoused]
00:00:00 [scsi_eh_2]
00:00:00 [jbd2/sda1-8]
00:00:00 [ext4-rsv-conver]
00:00:00 upstart-udev-bridge
0 02:18 ?
00:00:00 /lib/systemd/systemd-
0 02:18 ?
1 0 02:18 ?
1 0 02:18 ?
00:00:00 /usr/sbin/bluetoothd
00:00:00 /lib/systemd/systemd-
1 0 02:18 ?
2 0 02:18 ?
1 0 02:18 ?
00:00:00 rsyslogd
00:00:00 [krfcommd]
00:00:01 avahi-daemon: running
452
1
2
1
1
0 02:18 ?
0 02:18 ?
00:00:00 upstart-file-bridge
0 02:18 ?
0 02:18 ?
0 02:18 ?
1 0 02:18 ?
00:00:00 [ttm_swap]
00:00:00 /usr/sbin/ModemManager
00:00:00 NetworkManager
00:00:00 /usr/lib/policykit-
Page 95
root
778
1 0 02:18 ?
--daemon
root
823
679 0 02:18 ?
-sf /usr/lib/N
root
852
1 0 02:18 tty4
tty4
root
857
1 0 02:18 tty5
tty5
root
863
1 0 02:18 tty2
tty2
root
864
1 0 02:18 tty3
tty3
root
867
1 0 02:18 tty6
tty6
root
910
1 0 02:18 ?
root
915
1 0 02:18 ?
kernoops
927
1 0 02:18 ?
whoopsie
937
1 0 02:18 ?
root
955
1
0 02:18
/etc/acpi/events -s /va
root
960
1 0 02:18 ?
root
994
960 10 02:18 tty7
-seat seat0
root
999
1
0
/usr/lib/accountsservice/account
root
1010
1 0 02:18 ?
nobody
1015
679
0 02:18 ?
--no-resolv -root
1036
1 0 02:18 tty1
tty1
root
1401
2 0 02:18 ?
root
1568
960 0 02:19 ?
child 12 19
root
1596
1
0
/usr/lib/upower/upowerd
rtkit
1635
1 0 02:19 ?
daemon
root
1892
1 0 02:19 ?
colord
1907
1 0 02:19 ?
lp
1922
1892
0
/usr/lib/cups/notifier/dbus dbus
lp
1923
1892
0
/usr/lib/cups/notifier/dbus dbus
root
1958
1 0 02:19 ?
gurprem
2023
1
0 02:19 ?
keyring-daemon -gurprem
2030 1568 0 02:19 ?
gurprem
2122 2030 0 02:19 ?
gurprem
2127
2030
0 02:19 ?
--session --a
gurprem
2135 2030 0 02:19 ?
UE123029
00:00:00 upstart-socket-bridge
00:00:00 /sbin/dhclient -d
00:00:00 /sbin/getty -8 38400
00:00:00 /sbin/getty -8 38400
00:00:00 /sbin/getty -8 38400
00:00:00 /sbin/getty -8 38400
00:00:00 /sbin/getty -8 38400
00:00:00
00:00:00
00:00:00
00:00:00
?
anacron -s
cron
/usr/sbin/kerneloops
whoopsie
00:00:00 acpid -c
00:00:00 lightdm
00:00:47 /usr/bin/X -core :0
02:18
00:00:00
00:00:00 /usr/sbin/cups-browsed
00:00:00 /usr/sbin/dnsmasq
00:00:00 /sbin/getty -8 38400
00:00:00 [kauditd]
00:00:00 lightdm --session02:19
00:00:00
00:00:00
00:00:00 tpvmlpd2
00:00:00 /usr/bin/gnome00:00:00 init --user
00:00:00 ssh-agent -s
00:00:01 dbus-daemon --fork
00:00:00 upstart-event-bridge
Page 96
gurprem
2138 2030 0 02:19 ?
gnu/hud/wind
gurprem
2152 2030 0 02:19 ?
--daemon --s
gurprem
2154 2030 0 02:19 ?
--daemon --s
gurprem
2156 2030 0 02:19 ?
--daemon --u
gurprem
2158 2030 0 02:19 ?
--daemonize
gurprem
2173
2030
0 02:19 ?
settings-daemon/u
gurprem
2177 2030 0 02:19 ?
gnu/hud/hudgurprem
2180
2030
0 02:19 ?
core/at-spi-bus
gurprem
2181
2030
0 02:19 ?
--session=ubuntu
gurprem
2183 2030 0 02:19 ?
panel-servi
gurprem
2187
2180
0 02:19 ?
--config-file=/
gurprem
2193 2030 0 02:19 ?
gurprem
2195
2030
0 02:19 ?
core/at-spi2-re
gurprem
2200 2030 0 02:19 ?
fuse /run/us
gurprem
2202 2158 0 02:19 ?
dconf
gurprem
2203 2158 0 02:19 ?
gtk3
gurprem
2205 2030 0 02:19 ?
gnu/bamf/bam
gurprem
2211 2030 0 02:19 ?
--kill-da
gurprem
2239 2030 0 02:19 ?
gnu/indicato
gurprem
2241 2030 0 02:19 ?
gnu/indicato
gurprem
2246 2030 0 02:19 ?
gnu/indicato
gurprem
2250 2030 0 02:19 ?
gnu/indicato
gurprem
2251 2030 0 02:19 ?
gnu/indicato
gurprem
2257 2030 0 02:19 ?
gnu/indicato
gurprem
2258 2030 0 02:19 ?
gnu/indicato
gurprem
2262 2030 0 02:19 ?
gnu/indicato
UE123029
Page 97
gurprem
2271 2030 0 02:19 ?
00:00:00 /usr/lib/i386-linuxgnu/indicato
gurprem
2295
2030
0 02:19 ?
00:00:00
/usr/lib/evolution/evolution-sou
gurprem
2306 2030 0 02:19 ?
00:00:01 /usr/bin/pulseaudio
--start --lo
gurprem
2332 2030 0 02:19 ?
00:00:00 /usr/lib/i386-linuxgnu/notify-o
gurprem
2338 2158 0 02:19 ?
00:00:00 /usr/lib/ibus/ibusengine-simple
gurprem
2339 2181 3 02:19 ?
00:00:14 compiz
/etc/cron.dai
root
2848
2841
0 02:23 ?
00:00:00 /bin/sh
/etc/cron.daily/apt
gurprem
2907 2799 0 02:25 pts/11
00:00:00 man ps
gurprem
2916 2907 0 02:25 pts/11
00:00:00 pager -s
root
2963 2848 0 02:26 ?
00:00:00 apt-get -qq -y update
root
2966
2963
0 02:26 ?
00:00:00
/usr/lib/apt/methods/http
root
2967
2963
0 02:26 ?
00:00:00
/usr/lib/apt/methods/http
root
2968
2963
0 02:26 ?
00:00:00
/usr/lib/apt/methods/http
root
2970
2963
0 02:26 ?
00:00:00
/usr/lib/apt/methods/gpgv
root
2973
2963 38 02:26 ?
00:00:04
/usr/lib/apt/methods/copy
root
2979
2963
6 02:26 ?
00:00:00
/usr/lib/apt/methods/bzip2
gurprem
2981 2752 0 02:26 pts/1
00:00:00 ps -ef
gurprem@ubuntu:~$
gurprem@ubuntu:~$ ps -l
F S
UID
PID PPID C PRI
0 S 1000 2752 2736 0 80
0 R 1000 3279 2752 0 80
NI ADDR SZ WCHAN
0 - 1724 wait
0 - 1248 -
TTY
pts/1
pts/1
TIME CMD
00:00:00 bash
00:00:00 ps
COMMAND NOHUP
run a command immune to hangups, with output to a non-tty
SYNTAX:
nohup COMMAND [ARG]...
nohup OPTION
DESCRIPTION
Run COMMAND, ignoring hangup signals.
If standard input is a terminal, redirect it from /dev/null. If standard
output is a terminal, append output to 'nohup.out' if
possible,
UE123029
Page 98
Page 99
-L, --table
List signal names in a nice table.
NOTES Your shell (command line interpreter) may have a built-in kill
command. You may need to run the command described here
as
/bin/kill to solve the conflict.
USAGE:
kill -9 -1
Kill all processes you can kill.
kill -l 11
Translate number 11 into a signal name.
kill -L
List the available signal choices in a nice table.
kill 123 543 2341 3453
Send the default signal, SIGTERM, to all those processes.
COMMAND : NICE
run a program with modified scheduling priority
SYNTAX:
nice [OPTION] [COMMAND [ARG]...]
DESCRIPTION :
Run COMMAND with an adjusted niceness, which affects process
scheduling.
With no COMMAND, print the current niceness. Niceness values range
from
-20 (most favorable to the process) to 19 (least favorable to the
process).
Mandatory arguments to long options are mandatory for short options
too.
-n, --adjustment=N
add integer N to the niceness (default 10)
gurprem@ubuntu:~/gurpremnice -n 10 ls
foo bar
UE123029
Page 100
Mail the user when job has been completed even if there was no
output
-M
-f
Reads the job from the file rather than standard input
-t
To execute a one-time task when the load average is below 0.8 (for RH
systems) 1.5 (Ubuntu), use the batch command.
After typing the batch command, the at> prompt is displayed. Type the
command to execute, press , and type Ctrl-D. More than one command can
be specified by typing each command followed by the key. After typing all
the commands, press to go to a blank line and type Ctrl-D. Alternatively, a
shell script can be entered at the prompt, pressing after each line in the
script, and typing Ctrl-D on a blank line to exit. If a script is entered, the shell
used is the shell set in the user's SHELL environment, the user's login shell,
or /bin/sh (whichever is found first). As soon as the load average is below
0.8/1.5, the set of commands or script is executed.
If the set of commands or script tries to display information to standard out,
the output is emailed to the user.
COMMAND CRONTAB
-maintain crontab files for individual users (Vixie Cron)
SYNTAX:
crontab [ -u user ] file
crontab [ -u user ] [ -i ] { -e | -l | -r }
DESCRIPTION:
crontab is the program used to install, deinstall or list the tables used to
drive the cron daemon in Vixie Cron. Each user can have their own crontab,
and though these are files in /var/spool/cron/crontabs, they are not intended
to be edited directly.
If the /etc/cron.allow file exists, then you must be listed (one user per line)
therein in order to be allowed to use this command. If the
UE123029
Page 101
/etc/cron.allow file does not exist but the /etc/cron.deny file does exist,
then you must not be listed in the /etc/cron.deny file in order to use this
command.
USAGE:
gurprem@ubuntu:~/gurprem crontab -e
no crontab for gurprem - using an empty one
crontab: installing new crontab
gurprem@ubuntu:~/gurprem date
Mon Nov 24 00:38:12 IST 2014
gurprem@ubuntu:~/gurpremcat ./hello.txt
cat: ./hello.txt: No such file or directory
gurprem@ubuntu:~/gurpremdate
Mon Nov 24 00:39:04 IST 2014
gurprem@ubuntu:~/gurpremcat ./hello.txt
hello linux
EXPERIMENT 8
Aim: Introduction to the vi editor
The vi editor is a command-based editor used by many Linux users. The vi
editor has powerful features to aid programmers, but many beginning users
avoid using vi because the plentiful features overwhelm them. Although
there are quite a lot of graphical based text editor provided by different
distributions of Linux, learning vi is still important because in many
situations, such as for server configuration, the graphical user interface is
not available. Text editing has to be done with a command-based editor like
vi.
vi is a screen-oriented text editor originally created for the Unixoperating
system. The portable subset of the behavior of vi and programs based on it,
and the ex editor language supported within these programs, is described by
(and thus standardized by) the Single Unix Specification andPOSIX.
The original code for vi was written by Bill Joy in 1976, as the visual mode for
aline editor called ex that Joy had written with Chuck Hal Bill Joy's ex 1.1 was
released as part of the first BSD Unix release in March, 1978. It was not until
version 2.0 of ex, released as part of Second Berkeley Software Distribution
in May, 1979 that the editor was installed under the name vi (which took
UE123029
Page 102
users straight into ex's visual mode), and the name by which it is known
today. Some current implementations of vi can trace their source code
ancestry to Bill Joy; others are completely new, largely compatible
reimplementations.
The name vi is derived from the shortest unambiguous abbreviation for the
command visual in ex; the command in question switches the line editor ex
to visual mode. The name vi is pronounced /via/ (as in the discrete English
letters v and i), or, much less commonly, /va/, but never "six" as in the
Roman numeral VI.[]
In addition to various non-free software implementations of vi distributed
with proprietary implementations of Unix, several free and open source
software implementations of vi exist. A 2009 survey of Linux Journalreaders
found that vi was the most widely used text editor among respondents,
beating gedit, the second most widely used editor by nearly a factor of two
(36% to 19%)
Starting the vi Editor
The vi editor lets a user create new files or edit existing files. The command
to start the vi editor is vi, followed by the filename.
Usage: vi <filename>
Example: vi test.txt
When you start vi for the first time, you will see a screen filled with tildes (A
tilde looks like this: ~ ) on the left side of the screen. Any blank lines beyond
the end of the file are shown this way. At the bottom of your screen, the
filename should be shown if you have specified an existing file, and the size
UE123029
Page 103
The two modes of vi are command mode and insert mode. The command
mode allows the entry of commands to manipulate text. These commands
are usually one or two characters long, and can be entered with few
keystrokes. The insert mode puts anything typed on the keyboard into the
current file. vi starts out in command mode. There are several commands
that put the vi editor into insert mode. The most commonly used commands
to get into insert mode are a and i. Once you are in insert mode, you get out
of it by hitting the escape key. You can hit escape two times in a row and vi
would definitely be in command mode. Hitting escape while you are already
in command mode does not take the editor out of command mode. It may
beep to tell you that you are already in that mode.
Getting out of vi
The vi editor has two modes and in order to get out of vi, you have to be in
command mode. Hit the key labeled "Escape" or "Esc" to get into command
mode.
Some simple vi commands
1. Cutting, Deleting and Undo commands
The command commonly used for cutting is d. This command deletes text
from the file. The command is preceded by an optional count and followed
by a movement specification. If you double the command by typing dd, it
deletes the current line. Here are some combinations of
these:
x : delete character under the cursor.
d^ : deletes from current cursor position to the beginning of the line.
d$ : deletes from current cursor position to the end of the line.
dw : deletes from current cursor position to the end of the word.
3dd : deletes three lines from current cursor position downwards.
u : undo the last change to the file. Typing u again will re-do the change.
2. Copying and pasting commands
y : copy selected characters to the system buffer
p : paste the system buffer to the current cursor position
3. Search commands
The vi editor has two kinds of searches: string and character. For string
search, the / and ? commands are used. When you use these commands in
the command mode, the command just typed will be shown on the bottom
UE123029
Page 104
line. You should then type the string to search for. These two commands
differ only in the direction where the search takes place. The / command
searches forwards (downwards) in the file, while the ? command searches
backwards (upwards) in the file. The n and N commands repeat the previous
search command in the same or opposite direction, respectively.
EXPERIMENT 9
AIM: Introduction to
statements in vi Editor.
command
line
arguments
and
logical
Page 105
Page 106
G
1G
nG
0
^
$
<Ret> or +
-
Page 107
Page 108
Replace all the characters from the cursor to end of line. A $ will appear as
the last character of the line (to show you what you are replacing).
cw Change to end of word. A $ will appear at the end of the word.
ncwChange to end of n'th word. A $ will appear at the end of the n'th word.
cW Change to end of WORD (including punctuation). A $ will appear at the end
of the WORD.
cc Change (replace) the current line. The line disappears and the cursor is
positioned at the beginning of the line.
ncc Change n lines.
s
Substitute character. A $ will appear at the cursor location. You replace the
current character and append additional text until you press <Esc>.
ns Substitute n characters. A $ will replace the nth character.
Undo Commands
u Undo the last change.
Undo all changes to the
U
current line.
Save and Exit Commands
ZZ
Save changes and exit.
:wq<Ret>
Save changes and exit.
:w<Ret>
Save changes without exiting.
:q!<Ret>
Quit without saving changes.
:q<Ret>
Try to quit. Invokes a warning message if there are any changes
in the edit buffer and does not quit.
:w
Save changes to the file newfile without exiting.
newfile<Ret>
:w!
filename<Ret Overwrite the existing file filename.
>
Page 109
Syntax:
expr
op1
math-operator
Examples:
$
expr
1
$
expr
2
$
expr
10
$
expr
20
$
expr
10
$ echo `expr 6 + 3`
Note:
expr 20 %3 - Remainder read as 20 mod 3
expr 10 \* 3 - Multiplication use \* and not * since its wild card.
The read Statement
op2
+
/
%
\*
and
3
1
2
3
3
remainder
is
2.
Use to get input (data from user) from keyboard and store (data) to variable.
Syntax:
read variable1, variable2,...variableN
if and test command or [ expr ]
test command or [ expr ] is used to see if an expression is true, and if it is true it return zero(0),
otherwise returns nonzero for false.
Syntax:
test expression OR [ expression ]
Comparison operators:
For [ expr ]
statement with
if command
-eq
is equal to
5 == 6
if [ 5 -eq 6 ]
-ne
is not equal to
5 != 6
if [ 5 -ne 6 ]
-lt
is less than
5<6
if [ 5 -lt 6 ]
-le
is less than or
5 <= 6
equal to
if [ 5 -le 6 ]
-gt
is greater than
if [ 5 -gt 6 ]
-ge
is greater than or
5 >= 6
equal to
5>6
if [ 5 -ge 6 ]
if...else...fi
Page 110
fi
for Loop
Syntax:
for { variable name } in { list }
do
execute one for each item in the list until the list is
not finished (And repeat all statement between do and done)
done
Even you can use following syntax:
Syntax:
for
((
expr1;
expr2;
expr3
))
do
.....
...
repeat all statements between do and
done until expr2 is TRUE
Done
In above syntax BEFORE the first iteration, expr1 is evaluated. This is usually used to initialize
variables for the loop.
All the statements between do and done is executed repeatedly UNTIL the value of expr2 is
TRUE.
AFTER each iteration of the loop, expr3 is evaluated. This is usually use to increment a loop
while loop
Syntax:
while [ condition ]
do
command1
command2
command3
..
....
done
The case Statement
The case statement is good alternative to Multilevel if-then-else-fi statement. It enable you to
match several values against one variable. Its easier to read and write.
Syntax:
case $variable-name in
pattern1) command
...
..
UE123029
Page 111
command;;
pattern2) command
...
..
command;;
patternN) command
...
..
command;;
*)
command
...
..
command;;
esac
The $variable-name is compared against the patterns until a match is found.
The shell then executes all the statements up to the two semicolons that are
next to each other. The default is *) and its executed if no match is found.
EXPERIMENT 10
AIM: To implement following programs in vi-editor
1)To input length, breadth and radius and calculate area,perimeter
and circumference.
Code:
echo "Enter the lenght: "
read len
echo "Enter the breadth: "
read bre
echo "Enter radius of radius: "
read radius
echo "Area rectangle: " `echo $len*$br | bc`
echo "Perimeter rec: " `echo 2*\($len+$ber\) | bc`
echo "Area circle: " `echo 3.14*$radius*$radius | bc`
OUTPUT:
UE123029
Page 112
OUTPUT:
UE123029
Page 113
4)To find total salary if DA is 40% of basic pay and Hr is 20% of basic
pay
Code:
echo "enter salary"
read sal
total=`echo $sal+0.40*$sal+0.20*$sal|bc`
echo $total
OUTPUT:
UE123029
Page 114
EXPERIMENT 11
AIM: To implement following programs in vi-editor
1).Factorial of a number :
Code :
echo "enter number"
read num
result=1
for i in $(seq 1 1 $num)
do
result=`echo $result*$i|bc`
done
echo "factorial of num "$num" is "$result""
OUTPUT:
2)Fibonacci series :
Code:
echo "Enter the number of terms "
read t
a=1
b=1
echo $a
echo $b
for i in $(seq 1 1 $t)
do
UE123029
Page 115
x=$a
a=$b
b=`echo
echo $b
$b+$x | bc`
done
OUTPUT :
Page 116
from 1 to 100
UE123029
Page 117
EXPERIMENT 12
AIM: To implement following programs in vi-editor.
1)Find the entered year is a leap year or not.
Code:
echo "enter year "
read year
year4=`echo $year%4|bc`
year400=`echo $year%400|bc`
if [ $year4 -eq 0 -a $year400 -ne 0 ]
then
echo "$year" "is leap year""
else
echo "$year" "is not leap year""
fi
OUTPUT:
UE123029
Page 118
Page 119
rem=`echo
sum=`echo
rev=`echo
num=`echo
rem=`echo
sum=`echo
rev=`echo
num=`echo
rem=`echo
sum=`echo
rev=`echo
num=`echo
echo "sum
echo "the
$num%10|bc`
$sum+$rem|bc`
$rev*10+$rem|bc`
$num/10|bc`
$num%10|bc`
$sum+$rem|bc`
$rev*10+$rem|bc`
$num/10|bc`
$num%10|bc`
$sum +$rem|bc`
$rev*10+$rem|bc`
$num/10|bc`
of the digits of three digit number is " " $sum" "
reverse of number is " "$rev""
Output:
UE123029
Page 120
UE123029
Page 121
Page 122
mid=`echo $low+$high|bc`
mid=`echo $mid/2|bc`
fi
fi
done
if test $low -gt $high
then
echo "number is not in the list"
fi
Output:
EXPERIMENT 13
AIM: To implement following programs in vi-editor
1.Find if the entered integer is palindrome or not .
Code:
echo "enter the number"
read n
m=$n
temp=$n
i=0
while test $m -ne 0
do
i=`echo $i+1|bc`
UE123029
Page 123
m=`echo $m/10|bc`
done
rev=0
while test $i -ne 0
do
eval rem=`echo $temp%10|bc`
eval rev=`echo $rev*10+$rem|bc`
eval temp=`echo $temp/10|bc`
eval i=`echo $i-1|bc`
done
if test $rev -eq $n
then
echo " Palindrome "
else
echo " Not Palindrome"
fi
Output:
Page 124
3.Find the overtime rate for 5 employees ,given that if they work
for more than 40 hrs/day then the overtime rate is Rs.12/hr.
Code:
echo "enter time taken by 5 employees :"
for i in $(seq 1 1 5)
do
read x$i
done
echo "overtime rate for employees is :"
for i in $(seq 1 1 5)
do
eval temp=\$x$i
overtime=`echo $temp-40|bc`
overrate=`echo $overtime*12|bc`
echo $overrate
done
OUTPUT:
UE123029
Page 125
Code:
echo " enter option "
echo "press 1 cd .. 2) echo pwd 3) echo whoami
4) echo who 5) echo ls "
read option
case $option in
1) echo `cd ..`;;
2) echo `pwd`;;
3) echo `whoami`;;
4) echo `who`;;
5) echo `ls`;;
*) echo "default option";;
Esac
OUTPUT:
EXPERIMENT 14
AIM:To implement following programs.
Q) To get user to enter string of ten char and if 10 chr not entered print erorr msg
Code:
i=1
while [ $i ]
do
read -p "Enter a String of length 10 : " string
length=`echo $string | wc -m`
if [ $length -eq 11 ]
then
echo "lenght is right"
break
else
echo "lenght is not right enter again"
fi
done
UE123029
Page 126
OUTPUT:
Page 127
fi
done
cd - > /dev/null
done
EXPERIMENT 15
AIM :- To implement the following programs in vi Editor:
1)To rename every file of directory.
1.
CODE:
for i in *
do
d=new$i
mv $i $d
done
OUTPUT:
UE123029
Page 128
Output:
UE123029
Page 129
EXPERIMENT 16
AIM :- To implement the following programs in vi Editor:
1)To display all files in the current directory to which you have read , write
and execute permissions.
CODE:
for i in *
do
if [ -r $i -a -w $i -a -x $i ]
then
echo $i
fi
done
OUTPUT:
UE123029
Page 130
Page 131
UE123029
Page 132