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

Lab 3

This document discusses Linux commands for manipulating files and directories. It covers the ls, pwd, cd, touch, cat, cp, mv, rm, man and tree commands and provides examples of using each command. It also discusses wildcards that can be used with commands to select multiple files.

Uploaded by

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

Lab 3

This document discusses Linux commands for manipulating files and directories. It covers the ls, pwd, cd, touch, cat, cp, mv, rm, man and tree commands and provides examples of using each command. It also discusses wildcards that can be used with commands to select multiple files.

Uploaded by

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

MANIPULATING FILES

Lab-03

Lab Instructor:

Student Name

Student Roll #

Department

Year/Section
LAB 02 (Manipulating Files and directories)
Manipulating Files
This lesson will introduce you to the following commands:
CNTRL + ALT + T (to open terminal of Ubuntu)

 ls- list directories


 ls - l- detail information of directories
 ls - la= hidden files also shows
 pwd= sows present working directory
 cd.. = levelup directory by 1
 cd = take back to home directory
 cd directory name= go to specific directory (cd mean change directory)
 touch filename = to create an empty file
 cat > filename = create a file with some data (after creating on next line it will demand
data for file)
 cat filename = to check data in file
 cat >> filename = edit a file in terminal (it will be edited for data)
 cp - copy files and directories
 mv - move or rename files and directories
 rm - remove files and directories
 mkdir directoryname - create single directorie
 mkdir dir1 dir2 dir3…. = create multiple directories

These commands are among the most frequently used Linux
commands. Wildcards
Before I begin with our commands, I want to talk about a shell feature
that makes these
Commands so powerful. Since the shell uses filenames so much, it
provides special characters
to help you rapidly specify groups of filenames. These special
characters are called wildcards.
Wildcards allow you to select filenames based on patterns of
characters. The table below lists
the wildcards and what they select:

Summary of wildcards and their meanings


Wildcard Meaning
* Matches any characters
? Matches any single character
Matches any character that is a member of the set characters. The set of
characters may also be expressed as a POSIX character class such as one of the
following:
POSIX Character Classes
[:alnum:] Alphanumeric characters
[characters]
[:alpha:] Alphabetic characters
[:digit:] Numerals
[:upper:] Uppercase alphabetic characters
[:lower:] Lowercase alphabetic characters

[!characters] Matches any character that is not a member of the set characters
Using wildcards, it is possible to construct very sophisticated selection criteria for filenames.
Here are some examples of patterns and what they match:

Examples of wildcard matching


Pattern Matches
* All filenames

g* All filenames that begin with the character "g"


b*.txt All filenames that begin with the character "b" and end with the characters ".txt"
Any filename that begins with the characters "Data" followed by exactly 3 more
Data???
Characters
[abc]* Any filename that begins with "a" or "b" or "c" followed by any other characters
Any filename that begins with an uppercase letter. This is an example of a
[[:upper:]]*
character class.
*[![:lower:]] Any filename that does not end with a lowercase letter.

You can use wildcards with any command that accepts filename arguments.

Useful examples of cp and its options include:

Examples of the cp command


Command Results
Copies the contents of file1 into file2. If file2 does not exist, it is
cp file1 file2
created; otherwise, file2 is silently overwritten with the contents of file1.

cp -i file1 Like above however, since the "-i" (interactive) option is specified, if file2 exists,
file2 the user is prompted before it is overwritten with the contents of file1.
cp file1 dir1 Copy the contents of file1 (into a file named file1) inside of directory dir1.
cp -R dir1 Copy the contents of the directory dir1. If directory dir2 does not exist, it is
dir2 created. Otherwise, it creates a directory named dir1 within directory dir2.
mv
The mv command moves or renames files and directories depending on how it is used. It will
either move one or more files to a different directory, or it will rename a file or directory.

Examples of mv and its options include:

Examples of the mv command


Command Results
If file2 does not exist, then file1 is renamed file2. If file2 exists, its contents
mv file1 file2
are silently replaced with the contents of file1.
Like above however, since the “-i" (interactive) option is specified,
mv -i file1 file2 if file2 exists, the user is prompted before it is overwritten with the contents
of file1.
mv file1 file2 The files file1, file2, file3 are moved to directory dir1. If dir1 does not
file3 dir1 exist, mv will exit with an error.
If dir2 does not exist, then dir1 is renamed dir2. If dir2 exists, the
mv dir1 dir2
directory dir1 is moved within directory dir2.

rm
The rm command removes (deletes) files and directories.

Examples of rm and its options include:

Examples of the rm command


Command Results
rm file1 file2 Delete file1 and file2.
rm -i file1 Like above however, since the "-i" (interactive) option is specified, the user is
file
2 prompted before each file is deleted.
rm -r dir1
Directories dir1 and dir2 are deleted along with all of their contents.
dir2
Man command:
The man command is used to format and display the man pages. The man pages are a user
manual that is by default built into most Linux distributions (i.e., versions) and most other Unix-
like operating systems during installation.
Tree Command:
The TREE command displays a graphical representation of the directory tree using standard or
extended ASCII characters. For example, to display the directory structure on drive C:

touch
Changes file timestamps. It is also an easy way to create empty files. The touch command is
the easiest way to create new, empty files. It is also used to change the timestamps (i.e., dates
and times of the most recent access and modification) on existing files and directories.

man touch:

touch file_name(s).

Touch –a Last access time.

Touch –d date and time.

Touch –d ‘6 may 2016 20:30’ file 1.

Touch –m Modification time.

Cat command:
Cat command is used to create, display and combine two files.

Assignment No 5

1. Write the output and detail of above basic commands with example, after
practically performance.
2. Select tree commands from tree manual and run individually? Write output of
following here.
3. Select ‘touch’ commands from touch manual and run individually? Write output of
above here.
4. Select ‘cat’ commands from touch manual and run individually? Write output of
above here.
5. Explore different Command’s manuals perform practically and write output here.
6. Practically perform all above operations on windows operating system and write
steps and output of performance here.

You might also like