Sie sind auf Seite 1von 13

National Institute of

Technology, Tiruchirappalli

Subject: UNIX basic commands.

Submitted to: Dr. V.Gayathri

Submitted by: Jinendra pratap


singh
MCA
205114027

UNIX COMMANDS
Red Hat Enterprise Linux Workstation release 6.2 (Santiago)
Kernel 2.6.32-220.el6.x86_64 on an x86_64
login: mcalab27
Password:
Last login: Fri Feb 5 09:15:27 from 10.1.21.141
[mcalab27@localhost ~]$
[mcalab27@localhost ~]$ mkdir dir1
[mcalab27@localhost ~]$ ls
a.out dead.letter dir1 jinendra sh shell sjfp.c
1) who COMMAND with all options.
a) -a, --all

Same as using the options -b -d --login -p -r -t -T -u

[mcalab27@localhost ~]$ who -a


system boot 2016-02-05 09:12
run-level 5 2016-02-05 09:12
LOGIN

tty2

2016-02-05 09:13

2630 id=2

LOGIN

tty3

2016-02-05 09:13

2632 id=3

LOGIN

tty4

2016-02-05 09:13

2634 id=4

LOGIN

tty5

2016-02-05 09:13

2636 id=5

LOGIN

tty6

2016-02-05 09:13

2644 id=6
3051 (:0)

root

+ tty1

2016-02-05 09:13 old

root

+ pts/0

2016-02-05 09:13 00:11

3468 (:0.0)

mcalab10 + pts/1

2016-02-05 09:14 00:02

3486 (10.1.21.94)

mcalab25 + pts/2

2016-02-05 09:14 00:01

3488 (cap.octa.edu)

pts/13

2016-02-05 09:19

mcalab43 + pts/5
mcalab55 + pts/12
pts/10

2016-02-05 09:15 .
2016-02-05 09:16 .

2016-02-05 09:17

3578 id=13

term=0 exit=0

3623 (10.1.21.143)
3575 (10.1.21.149)
3701 id=10

term=0 exit=0

mcalab31 + pts/3

2016-02-05 09:16 .

3705 (10.1.21.102)

mcalab68 + pts/7

2016-02-05 09:17 .

3715 (10.1.21.64)

mcalab07 + pts/14
mcalab42 + pts/6

2016-02-05 09:17 .

3754 (10.1.21.158)

2016-02-05 09:17 00:02

3712 (10.1.21.144)

mcalab03 + pts/16

2016-02-05 09:18 .

3936 (10.1.21.148)

mcalab05 + pts/10

2016-02-05 09:18 .

3943 (10.1.21.150)

mcalab82 + pts/4
mcalab90 + pts/11

2016-02-05 09:19 00:05


2016-02-05 09:19 00:04

4017 (10.1.21.151)
4057 (10.1.21.142)

mcalab27 + pts/8

2016-02-05 09:20 .

4101 (10.1.21.141)

mcalab32 + pts/9

2016-02-05 09:21 .

4195 (10.1.21.103)

pts/13

2016-02-05 09:23

4254 id=13

term=0 exit=0

[mcalab27@localhost ~]$ who -all


system boot 2016-02-05 09:12
run-level 5 2016-02-05 09:12
LOGIN

tty2

2016-02-05 09:13

2630 id=2

LOGIN

tty3

2016-02-05 09:13

2632 id=3

LOGIN

tty4

2016-02-05 09:13

2634 id=4

LOGIN

tty5

2016-02-05 09:13

2636 id=5

LOGIN

tty6

2016-02-05 09:13

2644 id=6
3051 (:0)

root

+ tty1

2016-02-05 09:13 old

root

+ pts/0

2016-02-05 09:13 00:11

3468 (:0.0)

mcalab10 + pts/1

2016-02-05 09:14 00:03

3486 (10.1.21.94)

mcalab25 + pts/2

2016-02-05 09:14 00:01

3488 (cap.octa.edu)

pts/13

2016-02-05 09:19

mcalab43 + pts/5
mcalab55 + pts/12
pts/10

3578 id=13

2016-02-05 09:15 .

3623 (10.1.21.143)

2016-02-05 09:16 .

2016-02-05 09:17

term=0 exit=0

3575 (10.1.21.149)
3701 id=10

term=0 exit=0

mcalab31 + pts/3

2016-02-05 09:16 .

3705 (10.1.21.102)

mcalab68 + pts/7

2016-02-05 09:17 .

3715 (10.1.21.64)

mcalab07 + pts/14
mcalab42 + pts/6
mcalab03 + pts/16

2016-02-05 09:17 .
2016-02-05 09:17 00:03
2016-02-05 09:18 .

3754 (10.1.21.158)
3712 (10.1.21.144)
3936 (10.1.21.148)

mcalab05 + pts/10
mcalab82 + pts/4
mcalab90 + pts/11

2016-02-05 09:18 .

3943 (10.1.21.150)

2016-02-05 09:19 00:05

4017 (10.1.21.151)

2016-02-05 09:19 00:05

4057 (10.1.21.142)

mcalab27 + pts/8

2016-02-05 09:20 .

4101 (10.1.21.141)

mcalab32 + pts/9

2016-02-05 09:21 .

4195 (10.1.21.103)

pts/13

2016-02-05 09:23

b) -b, --boot

4254 id=13

term=0 exit=0

Display the time of the last system boot.

[mcalab27@localhost ~]$ who -b


system boot 2016-02-05 09:12
[mcalab27@localhost ~]$ who --boot
system boot 2016-02-05 09:12
c) d dead

Display the dead processes

[mcalab27@localhost ~]$ who -d


pts/13

2016-02-05 09:19

3578 id=13

term=0 exit=0

pts/10

2016-02-05 09:17

3701 id=10

term=0 exit=0

pts/13

2016-02-05 09:23

4254 id=13

term=0 exit=0

[mcalab27@localhost ~]$ who --dead


pts/13

2016-02-05 09:19

3578 id=13

term=0 exit=0

pts/10

2016-02-05 09:17

3701 id=10

term=0 exit=0

pts/13

2016-02-05 09:23

4254 id=13

term=0 exit=0

d) -H, --heading Print a line of column headings.


[mcalab27@localhost ~]$ who -H
NAME

LINE

TIME

COMMENT

root

tty1

2016-02-05 09:13 (:0)

root

pts/0

2016-02-05 09:13 (:0.0)

mcalab10 pts/1

2016-02-05 09:14 (10.1.21.94)

mcalab25 pts/2

2016-02-05 09:14 (cap.octa.edu)

mcalab43 pts/5

2016-02-05 09:15 (10.1.21.143)

mcalab55 pts/12
mcalab31 pts/3

2016-02-05 09:16 (10.1.21.149)


2016-02-05 09:16 (10.1.21.102)

mcalab68 pts/7
mcalab07 pts/14
mcalab42 pts/6

2016-02-05 09:17 (10.1.21.64)


2016-02-05 09:17 (10.1.21.158)
2016-02-05 09:17 (10.1.21.144)

mcalab03 pts/16

2016-02-05 09:18 (10.1.21.148)

mcalab05 pts/10

2016-02-05 09:18 (10.1.21.150)

mcalab82 pts/4
mcalab90 pts/11

2016-02-05 09:19 (10.1.21.151)


2016-02-05 09:19 (10.1.21.142)

mcalab27 pts/8

2016-02-05 09:20 (10.1.21.141)

mcalab32 pts/9

2016-02-05 09:21 (10.1.21.103)

mcalab50 pts/17

2016-02-05 09:25 (10.1.21.98)

mcalab25 pts/15

2016-02-05 09:25 (cap.octa.edu)

e) --ips
Print IP addresses instead of hostnames. with --lookup,
canonicalizes based on stored IP, if available, rather than stored
hostname.
[mcalab27@localhost ~]$ who -lps
LOGIN

tty2

2016-02-05 09:13 id=2

LOGIN

tty3

2016-02-05 09:13 id=3

LOGIN

tty4

2016-02-05 09:13 id=4

LOGIN

tty5

2016-02-05 09:13 id=5

LOGIN

tty6

2016-02-05 09:13 id=6

f) -l, --login Print system login processes.


[mcalab27@localhost ~]$ who -l
LOGIN

tty2

2016-02-05 09:13

2630 id=2

LOGIN

tty3

2016-02-05 09:13

2632 id=3

LOGIN

tty4

2016-02-05 09:13

2634 id=4

LOGIN

tty5

2016-02-05 09:13

2636 id=5

LOGIN

tty6

2016-02-05 09:13

2644 id=6

g) --versionDisplay version information, and exit.


[mcalab27@localhost ~]$ who --version
who (GNU coreutils) 8.4

Copyright (C) 2010 Free Software Foundation, Inc.


License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Joseph Arceneaux, David MacKenzie, and Michael Stone.


h) -q, --count
users.

Displays all login names, and a count of all logged-on

[mcalab27@localhost ~]$ who -q


root root mcalab10 mcalab25 mcalab43 mcalab55 mcalab31 mcalab68 mcalab07
mcalab42 mcalab03 mcalab05 mcalab82 mcalab90 mcalab27 mcalab32 mcalab50
.
b25 mscexam01
# users=19
2) whoami
[mcalab27@localhost ~]$ whoami
mcalab27
[mcalab27@localhost ~]$ who am i
mcalab27 pts/8
a)--help

2016-02-05 09:20 (10.1.21.141)

Display a help message, and exit.

[mcalab27@localhost ~]$ whoami --help


Usage: whoami [OPTION]...
Print the user name associated with the current effective user ID.
Same as id -un.

--help

display this help and exit

--version output version information and exit

Report whoami bugs to bug-coreutils@gnu.org


GNU coreutils home page: <http://www.gnu.org/software/coreutils/>
General help using GNU software: <http://www.gnu.org/gethelp/>

For complete documentation, run: info coreutils 'whoami invocation'


[mcalab27@localhost ~]$ whoami --version
whoami (GNU coreutils) 8.4
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Richard Mlynarik.


b) --version output version information and exit
[mcalab27@localhost ~]$ whoami --version
whoami (GNU coreutils) 8.4
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Richard Mlynarik.


3) Changing your password.
[mcalab27@localhost ~]$ passwd
Changing password for user mcalab27.
Changing password for mcalab27.
(current) UNIX password:
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
4)ls command with all options
[mcalab27@localhost ~]$ ls
a.out dead.letter dir1 jinendra sh shell sjfp.c
a) -a, --all

do not ignore entries starting with .

[mcalab27@localhost ~]$ ls -a
. a.out
shell .swp

.bash_logout .bashrc

dir1

jinendra .prime.swn .prime.swp

.. .bash_history .bash_profile dead.letter .gnome2 .mozilla .prime.swo sh


sjfp.c .viminfo
b) -A, --almost-all
do not list implied . and ..
[mcalab27@localhost ~]$ ls -A
a.out
.swp

.bash_logout .bashrc

dir1

jinendra .prime.swn .prime.swp shell

.bash_history .bash_profile dead.letter .gnome2 .mozilla .prime.swo sh


sjfp.c .viminfo
c) --author
with -l, print the author of each file
[mcalab27@localhost ~]$ ls --author
a.out dead.letter dir1 jinendra sh shell sjfp.c
d) -b, --escape
print octal escapes for nongraphic characters
[mcalab27@localhost ~]$ ls -b
a.out dead.letter dir1 jinendra sh shell sjfp.c
e) -B, --ignore-backups
do not list implied entries ending with ~
[mcalab27@localhost ~]$ ls -B
a.out dead.letter dir1 jinendra sh shell sjfp.c
f) -c with -lt: sort by, and show, ctime (time of last modification of file
status information) with -l: show ctime and sort by name otherwise: sort
by ctime
[mcalab27@localhost ~]$ ls -c
dir1 a.out sjfp.c jinendra dead.letter shell sh

g) -C list entries by columns


[mcalab27@localhost ~]$ ls -C

a.out dead.letter dir1 jinendra sh shell sjfp.c


[mcalab27@localhost ~]$ ls --color
a.out dead.letter dir1 jinendra sh shell sjfp.c
h) -d, --directory
list directory entries instead of contents, and do not dereference
[mcalab27@localhost ~]$ ls -d
.
i) -D, --dired generate output designed for Emacs dired mode
[mcalab27@localhost ~]$ ls -D
a.out dead.letter dir1 jinendra sh shell sjfp.c
j) -f

do not sort, enable -aU, disable -lst

[mcalab27@localhost ~]$ ls -f
.
.bash_profile .prime.swn .prime.swo .prime.swp dir1 .mozilla
.bash_history ..
.bash_logout
.viminfo .bashrc
jinendra

dead.letter .gnome2

sjfp.c

sh

k) -F, --classify
append indicator (one of */=>@|) to entries
[mcalab27@localhost ~]$ ls -F
a.out* dead.letter dir1/ jinendra/ sh shell/ sjfp.c
[mcalab27@localhost ~]$ ls -g
total 28
-rwxrwxr-x. 1 mcalab27 8978 Oct 26 16:12 a.out
-rw-------. 1 mcalab27

0 Oct 26 15:34 dead.letter

drwxrwxr-x. 2 mcalab27 4096 Feb 5 09:20 dir1


drwxrwxr-x. 7 mcalab27 4096 Oct 26 16:10 jinendra
-rw-rw-r--. 1 mcalab27

0 Aug 10 14:48 sh

drwxrwxr-x. 2 mcalab27 4096 Sep 14 12:57 shell


-rw-rw-r--. 1 mcalab27 3089 Oct 26 16:12 sjfp.c
[mcalab27@localhost ~]$ ls -G
a.out dead.letter dir1 jinendra sh shell sjfp.c

.swp

shell

a.out

[mcalab27@localhost ~]$ ls -h
a.out dead.letter dir1 jinendra sh shell sjfp.c
[mcalab27@localhost ~]$ ls -H
a.out dead.letter dir1 jinendra sh shell sjfp.c
[mcalab27@localhost ~]$ ls -m
a.out, dead.letter, dir1, jinendra, sh, shell, sjfp.c
[mcalab27@localhost ~]$ ls -n
total 28
-rwxrwxr-x. 1 530 530 8978 Oct 26 16:12 a.out
-rw-------. 1 530 530

0 Oct 26 15:34 dead.letter

drwxrwxr-x. 2 530 530 4096 Feb 5 09:20 dir1


drwxrwxr-x. 7 530 530 4096 Oct 26 16:10 jinendra
-rw-rw-r--. 1 530 530

0 Aug 10 14:48 sh

drwxrwxr-x. 2 530 530 4096 Sep 14 12:57 shell


-rw-rw-r--. 1 530 530 3089 Oct 26 16:12 sjfp.c
[mcalab27@localhost ~]$ ls -N
a.out dead.letter dir1 jinendra sh shell sjfp.c
[mcalab27@localhost ~]$ ls -o
total 28
-rwxrwxr-x. 1 mcalab27 8978 Oct 26 16:12 a.out
-rw-------. 1 mcalab27

0 Oct 26 15:34 dead.letter

drwxrwxr-x. 2 mcalab27 4096 Feb 5 09:20 dir1


drwxrwxr-x. 7 mcalab27 4096 Oct 26 16:10 jinendra
-rw-rw-r--. 1 mcalab27

0 Aug 10 14:48 sh

drwxrwxr-x. 2 mcalab27 4096 Sep 14 12:57 shell


-rw-rw-r--. 1 mcalab27 3089 Oct 26 16:12 sjfp.c
[mcalab27@localhost ~]$ ls -p
a.out dead.letter dir1/ jinendra/ sh shell/ sjfp.c
[mcalab27@localhost ~]$ ls -q
a.out dead.letter dir1 jinendra sh shell sjfp.c

5) Operations in a directory.
a) Create a new directory dir1
mkdir
[mcalab27@localhost ~]$ mkdir dir1
[mcalab27@localhost ~]$ ls
dir1 odr u work
Creating Parent Directories
[mcalab27@localhost ~]$mkdir -p /home/205114027/dir1/new/new1/new2
[mcalab27@localhost ~]$cd $HOME
[mcalab27@localhost ~]$ls
dir1 dir2 odr u work
[mcalab27@localhost ~]$cd dir1
[mcalab27@localhost ~]$ls
new
[mcalab27@localhost ~]$cd new
[mcalab27@localhost ~]$ls
new1
[mcalab27@localhost ~]$cd new1
[mcalab27@localhost ~]$ls
new2
mkdir with -m option is used to control the permissions of new directories
[mcalab27@localhost ~]$ mkdir -m 077 dir2
[mcalab27@localhost ~]$ ls
dir1 dir2 odr u work
Here 077 means 0=user 7=group and 7=others
7=All read write and execute permissions
0=No permissions at all.
b) Try to read the directory dir2(having no read permission to user)
[mcalab27@localhost ~]$ cd dir2
-bash: cd: dir2: Permission denied

c) Change the mode of permission of dir2 to make it accessible to user


[mcalab27@localhost ~]$ chmod 777 dir2
[mcalab27@localhost ~]$ cd dir2
[mcalab27@localhost ~]$ ls -a
. ..
d) Try to see in which directory currently you are.
[mcalab27@localhost ~]$ pwd
/home/205114027/dir2

Difference in home directory and root directory


The directory in which you find yourself when you first login is called your home
directory.
While
The root directory is the directory on Unix-like operating systems that contains
all other directories and files on the system and which is designated by a forward
slash ( / ).
e) How to go to home directory directly.
[mcalab27@localhost ~]$ls
dir1 dir2 odr u work
[mcalab27@localhost ~]$cd ~
[mcalab27@localhost ~]$ls
dir1 dir2 odr u work
[mcalab27@localhost ~]$cd $HOME
[mcalab27@localhost ~]$ls
dir1 dir2 odr u work
[mcalab27@localhost ~]$cd
[mcalab27@localhost ~]$ls
dir1 dir2 odr u work
f) To go in your last directory you can use following command
[mcalab27@localhost ~]$cd dir1
[mcalab27@localhost ~]$ls

dir3
[mcalab27@localhost ~]$cd /home/205114027
[mcalab27@localhost ~]$ls
dir1 dir2 odr u work
[mcalab27@localhost ~]$cd /home/205114027/dir1
[mcalab27@localhost ~]$ls
dir3
b) Removing Directories
For Empty Directories
[mcalab27@localhost ~]$ls
dir dir1 dir2 odr u work
[mcalab27@localhost ~]$cd dir1
[mcalab27@localhost ~]$ls
dir3 new
[mcalab27@localhost ~]$rmdir dir3
[mcalab27@localhost ~]$ls
New
If directory isnt empty you must use command rm rf to remove it with
the content.
[mcalab27@localhost ~]$rm rf dir3
[mcalab27@localhost ~]$ls

Das könnte Ihnen auch gefallen