Вы находитесь на странице: 1из 6

Experiment 1

(1) Date (Displaying date and time)


Unix has a date command that shows the date and time in the form used on the Internet.
Syntax:
$date
Fri
Aug
$_

19

13:28:34

IST

2005

Date is a valid command, and it displays both the date and time. Notice another security
feature of UNIX; the command doesnt prompt you to change either the date or time. This
facility is available only to the administrator, and the strange thing is that he uses the same
command.
(2) ls
This command is used see the list of files and directory at current location or specified
path. This command supports us to see the list of file and directory.
Syntax:
$ls [-Option] [Path]
Options:
x
-F
-a
-R
-r
-1
-l
-d
-t
-lt
-u
-lu
-lut
-i

Multicolumn output
Marks executable with * directories with / and symbolic links with @
Show all filenames beginning with a dot including . and ..
Recursive list
Sorts filenames in reverse order (ASCII collating sequence by default)
One filename in each line
Long listing in ASCII collating sequence showing seven attributes of a file
List only directory
Sorts filenames by last modification time
Sorts filenames listing by last modification time
Sorts filenames by last access time
Sort by ASCII collating sequence but listing shows last access time
As above but sorted by last access time
Display inode number

(3) Who
This command is used to get information about users (including yourself), you can use
several commands. The who command reports on users who are presently logged in. The who
command normally reports certain information about logged-in users. By using its options, you

can specify that it report information about the processes initiated by init, and that it report
reboots changes to the system clock, and logoffs. If you invoke who with no option or argument,
you get the following output:
Syntax:
$who
Output:
Username
Username
Option

tty00 Date
tty01 Date

-u
this option is used to see time since the last activity (idle time) and the process ID
number for each logged-in user. A process ID number is an integer number assigned by UNIX
to uniquely identify a given process.
Example
$who u
Output
Username
Username

tty00
tty01

Date
Date

Process No.
Process No.

-q
This option is used to shows login IDs and a count of the logged-in users q stands for
quick.
Example
$who q
Output
User Name
User Name
#Users = 2

Terminal Name
Terminal Name

3(A) who am i
Sometime we logged in from several terminals under different accounts, and we forget
that which username or terminal name we are using at that time this command is useful to know
username and terminal name.
Syntex:
$who am i
Output
User Name

Terminal Name

Date and Time

(4) Cal
Cal is a handy tools that you can invoke any time to see the calendar of any specific
moth, or a complete year. To see the calendar for the month of July 2009, provide the month
number and year as the two argument to cal:
Syntax
$cal [Month Number Year]
Month Number Year
This option will show you the calendar for the particular month of particular year. To see
the Aug 2009 calendar then following command will be invoked.
$cal 8 2009
Above command will show you the calendar for the month of august 2009.
User can see also all year calendar for the particular year for that user has to write year
number after cal command.
Example
$cal

2009

Above command will show you 12month calendar for the year of 2009.
With cal, you can produce the calendar for any month or year between the year 1 and
9999. This should serve our requirements.
(5) ps (Process Status)
Displays status of current running processes. By default, it shows process ID, terminal
with which process is associated, time consumed by the process since it has been started and
process name (generally command name or program name).
Syntax
$ps [Option]
-f
-e or A
-u
-l
-t
Example
$ps

Full listing showing the PPID (Parent Process ID) of each process
All processes including user and system processes
Process of user usr only
Long listing showing memory-related information
Processes running on terminal term, (say /dev/console)

Simple ps command will display following output


PID
36724
37796

TT
tty10
tty10

TIME
0
0

COMMAND
ksh.exe
ps.exe

To run processes in background


To run a process in the background, Unix provides the ampersand (&) symbol. While
executing a command, if this symbol is placed at the end of the command then the command will
be executed in the background. When you run a process in the background a number is
displayed on the screen.
This number is nothing but the PID of the process that you have just executed in the
background. Lets understand this with an example.
$sort employee.dat > emp.out &
17653
$
The task of sorting the file employee.dat and storing the output in emp.out has now been
assigned to the background, letting the user free to carry out any other task in the foreground.
(6) wc (Word Count)
This command is used to count number of characters, words and lines in an given input
file. If file is not given, it takes input from standard input.
Syntax
$wc [Option] File Name
Options
-l
-w
-c

Counts number of lines


Counts number of words
Counts number of characters

Example
A file abc.txt having following data
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
$ wc abc.txt
Output

20

42

abc.txt

Note: Spacebar and Enter also known as on character


(7) Cat
This command is use to displays files contents, creates new file, or appends data to an
existing file.
Syntax 1
To display the content of file
$cat File Name
Example
$cat Example1.txt
Syntax 2
To create a new file
$cat > File Name
Enter the file content
Ctrl + d
Example
$cat > Example2.txt
Enter the file content
Ctrl+d
Syntax 3

To append existing file

$cat >> File Name


Enter the file content want to append
Ctrl+d
Example
$cat >>Example1.txt
Enter the file content want to append
Ctrl+d
(9) pwd: (Path for working directory)
This command is used to see path for working directory in unix you cannot see the
prompt with path at that time if we want to know the what is our current path. The pwd
command supports to know path for working directory.
Syntax
$pwd
Example
If current directory is /home guest then

$pwd will show you /home/guest


(10) mkdir: (Make Directory)
This command is used to create a directory on current path or specified path.
Syntex:
$mkdir Directory Name
Some time you are giving right command still directory is not going to be created for
following reasons.
Error Message
Mkdir: directory name: [file exists]
The directory name is given with mkdir is already exist
There may be a an ordinary file by that name in the current directory
The permission set for the current directory dont permit
(11) rmdir: (Remove directory)
This command is used to remove directory form current path and specified path.
Syntex:
$rmdir [Path] Directory Name
This command is useful to remove empty directory the prime condition of this command
is this that whatever the directory is, you are going to remove it that must be empty else message
will display on the screen that directory is not empty.
Error Message
rmdir: dirname: cannot remove [Directory not empty]

Вам также может понравиться