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

Lab 1.

Unix Basic Command


2:1 Executing basic commands:
1. To display the current working directory, the command is:
pwd
The output is as follows.
/home/trg1
2. To display the path to and name of your HOME directory is:
echo $HOME
The output is as follows:
/home/dac
3.To display the login name using which you have logged into the system:
whoami
The output is as follows:
dac
4. To display the hidden files of your current directory is:
ls -a
.test
5. To list the names of all the files in your home directory is:
ls /home/dac
The output is as follows:
a
cop
manith
Public
6. To using the long listing format to display the files in your directory is:
ls -l
drwxr-xr-x 3 dac users 20480 Sep 21 18:40 241_216
7. To list the files beginning with chap followed by any
alphabet is:
ls chap{1..20}.txt chap{a..z}.txt
The output is as follows:
chap10.txt chap17.txt chap4.txt chapb.txt chapi.txt
chap11.txt chap18.txt chap5.txt chapc.txt chapj.txt
chap12.txt chap19.txt chap6.txt chapd.txt chapk.txt
chap13.txt chap1.txt
chap7.txt chape.txt chapl.txt
chap14.txt chap20.txt chap8.txt chapf.txt chapm.txt
chap15.txt chap2.txt
chap9.txt chapg.txt chapn.txt
chap16.txt chap3.txt
chapa.txt chaph.txt chapo.txt

number or any lower case

chapp.txt
chapq.txt
chapr.txt
chaps.txt
chapt.txt
chapu.txt
chapv.txt

chapw.txt
chapx.txt
chapy.txt
chapz.txt

8. To give appropriate command to create a directory called C_prog under your home
directory is:
mkdir /home/dac/C_prog
The output when use command ls is as follows:
C_prog as directory
9.To create the following directories under your home directory is:
mkdir /home/dac/newdir /home/dac/newdirectory
The follows output is as follows:
Directory newdir and directory newdirectory are created
10. To list the names of all the files, including the contents of the sub
directories under your home directory is:
ls /home/dac/*
The result is as follows:

/home/dac/hUNIX

/home/dac/zUNIX

/home/dac/arr:
arr.cpp
11. To remove the directory called newdirectory from your working directory is:
rm -r /home/dac/newdirectory/
The result is this directory was deleted.
12. To create a directory called temp under your home directory is:
mkdir /home/dac/temp
The result is this directory was created.
13. To remove the directory called newdir under your home directory and verify the
above with the help of the directory listing command is:
rm -r /home/dac/newdir
ls /home/dac
The result is this directory was deleted.
14. To create another directory directorynew under the temp directory is:
mkdir /home/dac/temp/directorynew
The result is this directory was created.
15. To change the directory to your home directory is:
cd
16. From your home directory, change the directory to directorynew using relative
path :
cd Documents/241
and absolute path is:
cd /home/dac/Documents/241
17. To remove the directory called c_prog, which is in your home directory is
rm -r /home/dac/c_prog
18. To change to the directory /etc and display the files present in it :
cd /etc
ls
The output is as follows :
aclocal_dirlist
hosts.deny
polkit-1
19. To List the names of all the files that begin with a dot in the /usr/bin
directory is:
cd /usr/bin
find -name .*
The output is as follows:
.
./.fipscheck.hmac
./.hmac256.hmac
20. To create a file first.unix with the following contents is:
cat > first.unix then type the contents. When it is done press enter and ctrl+c.
The output is as follows: file first.unix is created with that content.
21. To copy the file first.unix in your home directory to first.unics is:
cp first.unix first.unics
The output is as follows:
ls

file first.unics is created.


22. To list the contents of first.unix and first.unics with a single command is:
cat first.unix first.unics
The output is as follows:
Hi! Good Morning everybody.
Welcome to the first exercise on UNIX.
Hope you enjoy doing the assignments.
Hi! Good Morning everybody.
Welcome to the first exercise on UNIX.
Hope you enjoy doing the assignments.
23. To create a new directory under the temp directory is
mkdir temp/directory
The output is new directory is created.
24. From your home directory, to copy all the files to the directory created under
the temp sub directory is
cp -r * temp/directory
It'll show the promb message as : cp: cannot copy a directory, temp, into itself,
temp/directory/temp
25. To move the file first.unix to the directory temp as second.unix is:
mv first.unix temp/directory/second.unix
The output is new file was created in temp/directory
26. To remove the file called first.unics from the home directory is:
rm temp/directory/second.unix
27. Change your directory to temp and issue the command rm *. I see that:
directory is could not remove with the command rm *.
rm: cannot remove directory: Is a directory
rm: cannot remove directorynew: Is a directory
28. To Move all files whose names end with a, c and o to the HOME directory
mv ./*{a,c,o} /home/dac/
29. Copy all files that end with a UNIX to the temp directory.
cp *.UNIX temp/directory
30. Issuing a single command,
directory itself :
rm -rf ../temp/

and the

31. Try commands cp and mv with invalid number of arguments and note the results.
Error message :
cp: target the last arguments is not a directory
mv: target the last arguments is not a directory
32. Use the cat command to create a file friends, with the following data:
Madhu 6966456 09/07/68
Jamil 2345215 08/09/67
Ajay 5546785 01/04/66
Mano 7820022 09/07/68
David 8281292 09/09/60
Simmi 7864563 12/12/70
Navin 2224311 30/05/68

The fields should be separated by a tab.


Cat > friends.txt
Madhu 6966456 09/07/68
Jamil 2345215 08/09/67
Ajay 5546785 01/04/66
Mano 7820022 09/07/68
David 8281292 09/09/60
Simmi 7864563 12/12/70
Navin 2224311 30/05/68
then enter and ctrl c
33.To display contents of the file friends is :
cat friends.txt
34. To copy contents of friends to newfriend without using the cp command is
cat friends.txt > newfriend.txt
35. To display contents of the file friends and newfriends in a single command is
cat friends.txt newfriend.txt
36. Find all users currently working on the system and store the output in a file
named as users is :
who > users.txt
37. To Append contents of friends file to the file, users:
cat friends.txt >> users.txt
38. To Display current system date and time and record your observations. How is
the time displayed
date > datetime.txt
Mon Sep 26 20:35:08 IST 2016
Time is displayed in 24 hour format before year.
39. Display calendar for the month and year of your birth is:
cal 23 03 1991
40. Try following commands and record your observations.
- date "+ %": it's displayed only % %
- date "+%m": it's displayed only month 09
- date "+%D": it's displayed date format "month-day-last_two_digit_of_year"
09/26/16
- date "+%/%Training Activity": it's displayed time because it convert the last %
and T "%/20:43:14raining Activity"
- date "+%Training Activity": it's displayed time because it convert the % and T
"20:43:14raining Activity"
- date "+%r": it's displayed time in 12 format08:47:58 PM

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