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

Ubuntu Operating System Lab Lecture 2

This document provides an outline for a lecture on operating systems concepts including commands like cat, cp, mv, and rm. It discusses: 1. The cat command can be used to display and append contents of files. 2. Hidden files start with . and aren't shown by default in ls listings but can be displayed using ls -a. 3. The cp command is used to copy files and directories. The mv command renames or moves files and directories. The rm command removes files and directories. 4. Hands-on exercises are provided to create, view, append and concatenate files, copy files, rename and delete files and directories.

Uploaded by

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

Ubuntu Operating System Lab Lecture 2

This document provides an outline for a lecture on operating systems concepts including commands like cat, cp, mv, and rm. It discusses: 1. The cat command can be used to display and append contents of files. 2. Hidden files start with . and aren't shown by default in ls listings but can be displayed using ls -a. 3. The cp command is used to copy files and directories. The mv command renames or moves files and directories. The rm command removes files and directories. 4. Hands-on exercises are provided to create, view, append and concatenate files, copy files, rename and delete files and directories.

Uploaded by

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

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:


Lecturer: Name & email
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
q cat > test.txt

This is a test.

I like Unix operating systems.

q 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
q The special . and .. directories don’t show up when you do ls, they are
hidden files
q 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
q Hidden files are often used for configuration files
q Usually found in a user’s home directory
q You can still read hidden files — they just don’t get listed by ls by
default
cat command to show content of a file
q 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.

q As example, use cat a_text_file to get the inside contents of


that file in your screen.
cat command to append
q Use the (>>) operator to append the contents of file1.txt to
file2.txt :

q cat file1.txt >> file2.txt


Create, View and Append file
q To create a file
Syntax: $ cat>filename
Example: $ cat>ex1
q To view the content of the file
Syntax: $ cat filename
Example: $ cat ex1
q To append some details with the existing details in the file
Syntax: $ cat>>filename
Example: $ cat>>ex1
Concatenate multiple files

q To concatenate multiple files


Syntax: $ cat file1 file2 >> file3
Example: $ cat computer compiler >> world
cp command

q 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
q Syntax: $ cp source destination
Example: $ cp ex1 ex2
q Also don't forget to use proper path when you're coping
something to different location.
mv command
q The mv command is used to move or rename directories and
files.

q To rename a file use mv old_name new_name


Syntax: $ mv oldfile newfile
Example: $ mv ex1 ex3
rm command
q The rm command is used to remove files or directory.

q To delete a file
Syntax: $ rm filename
Example: $ rm ex1
q To delete all files
Syntax: $ rm *
q Rm –d dir_name (empty directory remove)

q rm -r /tmp/backup to remove everything that folder.


q Of course you've to be careful before removing anything.
Create, change and remove a directory
q To create a directory
Syntax: $ mkdir dirname

q To change the name of the directory (!!)


Syntax: $ cd dirname (!! mv old_name new_name)

q To remove the directory


Syntax: $ rmdir dirname
Example: $ rmdir flower

q To delete all directories The -p option can delete directory and


its subdirectories/sub-folders:
Syntax: $ rmdir -p dir1/dir2/dir3
In AIUB, create a text file called ‘file1.txt’, with the text:
“this is my first text file
Second line of my first text file”
Create another file name file2.txt with the text
“second file_yourname”
Copy file1.txt to file2.txt
Rename file2.txt to your_name.txt
Delete file2.txt
Delete your_name.txt
Delete AIUB
Books
q Unix Shell Programming
q Written by Yashavant P. Kanetkar

You might also like