Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

LAB 02

Summary

Items Description
Course Title Operating System
Lab Title Introduction to Basic Shell commands
Duration 3 Hours
Operating System Linux Operating System
/Tool/Language
Objective To get familiar with the basic Linux commands.

Introduction to Basic Shell Commands

Command: cat
“cat" is short for concatenate. This command is used to create, view and concatenate files.

Example:
o cat>file1
This command creates the file, enter the contents into it and to save the content, press Ctrl+D.

o cat file1
This command shows the content of the file.

o cat file1 file2 > file3


This command combines the contents of the first two files into the third file.

Command: pwd
"pwd" stands for print working directory. It displays your current position in the UNIX/LINUX
file system.

Example:
o pwd
It is simply used to report your current working directory.

Command: ls
"ls" stands for list. It is used to list information about files and directories.

Example:
o ls
It provides a very basic listing of the files in your current working directory. Filenames beginning
with a decimal are considered hidden files, and they are not shown.

o ls -al
This command provides a long listing of information about all files in the current directory.
This is probably the most used version of the ls command.

Command: mv
The "mv" command is used to move and rename files.

Examples:
o mv Lab OSLab
This command renames the file "Lab" to the new name "OSLab".

o mv Chapter1 garbage
This command renames the file "Chapter1" to the new name "garbage". (Notice that if "garbage"
is a directory, "Chapter1" would be moved into that directory).

Command: rm
The "rm" command is used to remove files and directories.

Examples:
o rm OSLab
This command deletes the file named "OSLab" (assuming you have permission to delete this file).

o rm Chapter1 Chapter2
This command deletes the files named "Chapter1", "Chapter2"

o rm -r OSLab1
This command will delete the OSLab1(Assume that OSLab1 is a directory).

o rm in*
This command deletes all files in the current directory whose filename begins with the characters
"in".

o rm *.txt
This command deletes all files in the current directory whose filename ends with the characters
".txt".

o rm -r Labs
This command deletes the directory named "Labs”. This directory, and all of its' contents, are
erased from the disk, including any sub-directories and files.

Command: cp
The "cp" command is used to copy files and directories. When using the cp command, you must
always specify both the source and destination of the file(s) to be copied.

Examples:
o cp /home/Lab1 /home/OSLabs
This command copies the "Lab1" file in "/home" to the directory named "/home/OSLabs".

Command: mkdir
The "mkdir" command is used to create new directories (sub-directories).

Examples:
o mkdir Lab
This command creates a new directory named "Lab" in your current directory. (This example
assumes that you have the proper permissions to create a new sub-directory in your current
working directory.)

o mkdir memos letters


This command creates two new sub-directories (memos, letters) in the current directory.

o mkdir /home/labb
This command creates a new directory named "labb" in the directory "/home".

Command: rmdir
The "rm" command is used to remove files and directories. (Warning - be very careful when
removing files and directories!)

Examples:
o rm Lab
This command deletes the file named "Lab" (assuming you have permission to delete this file).

o rm Lab1 Lab2
This command deletes the files named "Lab1","Lab2".

o rm -i Lab1 Lab2
This command prompt you before deleting any of the three files specified. The -i option stands for
inquire. You must answer y (for yes) for each file you really want to delete. This can be a safer
way to delete files.

o rm *.txt
This command deletes all files in the current directory whose filename ends with the characters
".txt".

o rm in*
This command deletes all files in the current directory whose filename begins with the characters
"in".
o rm -r labb
This command deletes the directory named "labb". This directory, and all of its' contents, are
erased from the disk, including any sub-directories and files.

Command: cd, chdir


"cd" stands for change directory. It is the primary command for moving around the file system.

Examples:
o cd /home
This command moves you to the "/home" directory. "/home" becomes your current working
directory.

o cd /h*
Moves you to the "/home" directory - if this is the only directory matching this wildcard pattern.

o cd
Issuing the "cd" command without any arguments moves you to your home directory.

Command: clear
“Clear” is used to clear the full screen of text, perhaps garbage on the terminal.

Examples:
o clear
This command clears all text on the terminal.
Operating Systems
LAB TASKS
Lab 02

Lab Title: Introduction to Basic Shell commands

Lab Tasks:

 Verify that you are in your home directory.

 Make the directory lABS using the following command. List the files in the current directory
to verify that the directory LABS has been made correctly.

 Change directories to LABS. Create the file named file1.

 List the contents of the file file1 to the screen.

 Make a copy of the file file1 under the name file2.

 Verify that the files file1and file2 both exist.

 List the contents of both file1 and file2 to the monitor screen.

 Then delete the file file1.

 Clear the window.

 Rename file2 to thefile.

 Copy thefile to your home directory.

 Removethefile from the current directory.

 Copy thefile from your home directory to the current directory.

 Change directories to your home directory.

 Remove thefile from your home directory and from directory LABS. Verify thefile is removed
from the directory LABS.

 Remove the directory LABS from your home directory with the following command.

 Verify that thefile and LABS are gonefrom your home directory.

You might also like