Lab 2 OS Commands in Linux
Lab 2 OS Commands in Linux
Lab 2 OS Commands in Linux
LAB#2
Command: cat
“cat” is short for concatenate. This command is used to create, view and concatenate files.
Example:
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:
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.
Command: mv
The “mv” command is used to move and rename files.
Examples:
o mv Lab OS Lab
This command renames the file “Lab” to the new name “ OSLab”
o mv OSLab garbage
This command renames the file “OSLAB1” to the new name “garbage”.
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 OSLab1 OSLab2
This command deletes the files named “Chapter1”, “Chapter2”and “Chapter3”.
AFTER COMMAND:
o rm -i OSLab1 OSLab2
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 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
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/OSLab”
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 /home/labb
This command creates a new directory named “lab” in the directory “/home”
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.
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.