0% found this document useful (0 votes)
2 views

Lecture 2(LAB)

This document outlines the second lab for the Operating Systems course, covering essential Unix commands such as cat, cp, mv, and rm. It includes instructions for creating, viewing, appending, and concatenating files, as well as managing directories. Additionally, it mentions hidden files and provides examples for each command discussed.

Uploaded by

Sumaiya
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Lecture 2(LAB)

This document outlines the second lab for the Operating Systems course, covering essential Unix commands such as cat, cp, mv, and rm. It includes instructions for creating, viewing, appending, and concatenating files, as well as managing directories. Additionally, it mentions hidden files and provides examples for each command discussed.

Uploaded by

Sumaiya
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 14

LAB 2

Course Code: CSC 2209 Course Title: Operating Systems

Dept. of Computer Science


Faculty of Science and Technology

Lecturer No: 02 Week No: 02 Semester: Fall 20-21


Lecturer: Syeda Anika Tasnim
[email protected]
Lecture Outline

1. cat Command
2. Hidden Files
3. Showing Contents of a File
4. How to Append Files
5. How to Concatenate Files
6. cp Command
7. mv Command
8. rm Command
cat command
 cat > test.txt

This is a test.

I like Unix operating systems.


 To save the changes press CTRL-d i.e. press and hold CTRL and
press d. Create another text file called bar.txt as follows:
Exercise

In dir1, create a text file called


‘file1.txt’, with the text: this is
my first text file
Hidden Files
 The special . and .. directories don’t show up when you do ls, they
are hidden files
 Similarly we have hidden files
Simple rule: files whose names start with . are considered ‘hidden’
Make ls display all files, even the hidden ones, by giving it the -a
(all) option:
$ ls -a
. .. .bashrc .profile report.doc
 Hidden files are often used for configuration files
 Usually found in a user’s home directory
 You can still read hidden files — they just don’t get listed by ls by
default
cat command to show content of
a file
 It's used to print the contents of a file to the screen(stdout
more precisely), really useful when you want to have a quick
look on contents of a file.
 As example, use cat a_text_file to get the inside contents of
that file in your screen.
cat command to append
 Use the (>>) operator to append the contents of file1.txt to
file2.txt :

 cat file1.txt >> file2.txt


Create, View and Append file
 To create a file
Syntax: $ cat>filename
Example: $ cat>ex1
 To view the content of the file
Syntax: $ cat filename
Example: $ cat ex1
 To append some details with the existing details in the file
Syntax: $ cat>>filename
Example: $ cat>>ex1
Concatenate multiple files
 To concatenate multiple files
Syntax: $ cat file1 file2 > file3
Example: $ cat computer compiler>world
cp command
 cp , You can copy files and directories with this command.
Typical usage is like cp file_a file_1_copy or cp directory_a
dir_a_copy
 Syntax: $ cp source destination
Example: $ cp ex1 ex2
 Also don't forget to use proper path when you're coping
something to different location.
mv command
 The mv command is used to move or rename directories and
files.
 To rename a file use mv old_name new_name
Syntax: $ mv oldfile newfile
Example: $ mv ex1 ex3
rm command
 The rm command is used to remove files or directory.

 To delete a file
Syntax: $ rm filename
Example: $ rm ex1
 To delete all files
Syntax: $ rm *
 rm -r /tmp/backup to remove everything that folder.
 Of course you've to be careful before removing anything.
Create, change and remove a
directory
 To create a directory
Syntax: $ mkdir dirname
 To change the name of the directory
Syntax: $ cd dirname
 To remove the directory
Syntax: $ rmdir dirname
Example: $ rmdir flower
 To delete all directories The -p option can delete
directory and its subdirectories/sub-folders:
Syntax: $ rmdir -p dir1/dir2/dir3
Books
 Unix Shell Programming
 Written by Yashavant P. Kanetkar

You might also like