PCA1 Unix
PCA1 Unix
and Management
LABORATORY
REPORT
Paper Name- Unix and Shell Programming Lab
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)
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
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