0% found this document useful (0 votes)
54 views3 pages

PCA1 Unix

The document is a laboratory report on Unix and Shell Programming. It provides 14 examples of common Unix commands like who, pwd, mkdir, rmdir, cd, ls, touch, cp, mv, rm, chmod, cat, wc, and sort. For each command it gives a brief explanation of what the command does and provides an example usage with output.

Uploaded by

Sayan Bose
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views3 pages

PCA1 Unix

The document is a laboratory report on Unix and Shell Programming. It provides 14 examples of common Unix commands like who, pwd, mkdir, rmdir, cd, ls, touch, cp, mv, rm, chmod, cat, wc, and sort. For each command it gives a brief explanation of what the command does and provides an example usage with output.

Uploaded by

Sayan Bose
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Dinabandhu Andrews Institute of Technology

and Management

LABORATORY
REPORT
Paper Name- Unix and Shell Programming Lab

NAME: Sayan Bose


University Roll No. : 15401220049
Paper Code.: BCAC691
Stream: BCA
Semester: 6th
Session: 2020-23

Dinabandhu Andrews Institute of Technology and Management


[ Affiliated to Maulana Abul Kalam Azad University of Technology, West Bengal ]
Block-S, 1/406A, Baishnabghata, Near Satyajit Ray Park, Patuli, Kolkata – 700094.
1. who : The ‘$ who’ command displays all the users who have logged into the system currently.As
shown above on my system I am the only user currently logged in.The thing tty2 is terminal line the
user is using and the next line gives the current date and time
$ who
Output: harssh tty2 2017-07-18 09:32 (:0)

2. pwd : The ‘$pwd’ command stands for ‘print working directory’ and as the name says,it displays the
directory in which we are currently (directory is same as folder for Windows OS users). In the output
we are harssh directory(folder for Windows OS that are moving to Linux),which is present inside the
home directory
$ pwd
Output: /home/harsh

3. mkdir : The ‘$ mkdir’ stands for ‘make directory’ and it creates a new directory.We have used ‘$ cd’
(which is discussed below) to get into the newly created directory and again on giving ‘$ pwd’
command,we are displayed with the new ‘newfolder’ directory.
$ mkdir newfolder
$ cd newfolder
$ pwd
Output: /home/harssh/newfolder

4. rmdir : The ‘$ rmdir’ command deletes any directory we want to delete and you can remember it by
its names ‘rmdir’ which stands for ‘remove directory’.
$ rmdir newfolder

5. cd : The ‘$ cd’ command stands for ‘change directory’ and it changes your current directory to the
‘newfolder’ directory.You can understand this a double-clicking a folder and then you do some stuff
in that folder.
$ cd newfolder (assuming that there is a directory named 'newfolder' on your system)

6. ls : The ‘ls’ command simply displays the contents of a directory.


$ ls
Output: Desktop Documents Downloads Music Pictures Public Scratch Templates Videos
$ ls => displays all files and folders
$ ls -l => lists seven attributes of all files in the current directory
[ It shows seven attributes for each file. The list is preceded by the words total [value], which
indicates that a total of [value] blocks are occupied by these files in the disk, each block consisting of
512 bytes (1024 in Linux).
First character : '-' indicates file and 'd' indicates directory.
Next three characters : read(r), write(w) and execute(x) for owner
Next three characters : read(r), write(w) and execute(x) for other group members.
Next three characters : read(r), write(w) and execute(x) for other members.
Next fields give the number of links, owner name, group name, size of files in bytes,last modified date
and time and file name.
$ ls -a => displays files including hidden files
$ ls abc* => displays all files whose name starts with “abc”
$ ls .c => displays files whose extension is '.c'
$ ls ?a.c => displays files with extension '.c' and whose name is two length characters with 'a' is the
second character.
$ ls a??.c => displays files with extension '.c' and whose name is three-length characters with 'a' is the
first character.
$ ls [aeiou]* => displays files whose name starts with 'a' or 'e' or 'i' or 'o' or 'u'
$ ls [!aeiou]* => displays files whose name does not start with 'a' or 'e' or 'i' or 'o' or 'u'
$ ls [a-m][C-Z][4-9]?? => displays files whose name is five-length; first, second and third character
should be within 'a' to 'm', 'C' to 'Z', '4' to '9' respectively.
7. touch : The ‘$ touch’ command creates a file(not directory) and you can simple add an extension such
as .txt after it to make it a Text File.

8. cp : This ‘$ cp ‘ command stands for ‘copy’ and it simply copy/paste the file wherever you want to.In
the above example, we are copying a file ‘file.txt’ from the directory harssh to a new directory new.
$ cp /home/harssh/file.txt /home/harssh/new/

9. mv : The ‘$ mv’ command stands for ‘move’ and it simply move a file from a directory to another
directory.In the above example a file named ‘file.txt’ is being moved into a new directory ‘new’
$ mv /home/harssh/file.txt /home/harssh/new

10. rm : The ‘$ rm ‘ command for remove and the ‘-r’ simply recursively deletes file. Try ‘$ rm
filename.txt’ at your terminal
$ rm file.txt

11. 11. chmod : The ‘$ chmod’ command stands for change mode command.As there are many modes in
Unix that can be used to manipulate files in the Unix environment.Basically there are 3 modes that we
can use with the ‘chmod’ command
1. +w (stands for write and it changes file permissions to write)
2. +r (stands for read and it changes file permissions to read)
3. +x (generally it is used to make a file executable)
$ chmod +w file.txt
$ chmod +r file.txt
$ chmod +x file.txt
‘.’ And ‘..’
In filesystems, we use the double dot (..) to access the parent directory, whereas the single dot (.)
represents the current directory.

12. $ cat>file1.txt => creates a file file1.txt. You need to type your text. To [type text] save the text you
should press ctrl+d ctrl+d
$ cat file1.txt => displays the content of the file file1.txt
$ cat file1.txt file2.txt > file3.txt => creates a new file file3.txt (if exists, will be deleted) with the
contents of file1.txt and file2.txt.
$ cat file1.txt file2.txt >> file3.txt => contents of file1.txt and file2.txt will be appended to the
contents of file3.txt

13. wc counts lines, words, characters


$ wc -l file1.txt => counts number of lines from the file file1.txt
$ wc -w file1.txt => counts number of words from the file file1.txt
$ wc -c file.txt => counts number of characters from the file file1.txt
$ wc -lc file1.txt => counts number of lines and characters from the file file1.txt

14. $ sort file1.txt => It will sort the contents of file1.txt alphabetically (line wise)
$ sort file1.txt, file2.txt => sort both the files different switches for sort command
[-f] -- ignores case
[-m] -- merges files that have already been sorted
[-n] -- sorts in numeric order
[-r] -- reverse order
[-u] -- unique output

You might also like