OS Practical

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 18

Operating System Lab

PWD command

• 1.Present Working Directory Command :

• To print the complete path of the current working directory.

• Syntax : $pwd
1. mkdir command

• To create or make a new directory in a current directory .

• Syntax : $mkdir <directory name>


Options Description

Displays help-related information for the mkdir command and


–help exits. Use this option to get assistance on how to use the
command and its various features.

Displays the version number and additional information about


the license for mkdir, providing details about the software
–version version installed. Use this option to check the installed mkdir
version.

Enables verbose mode, displaying a message for every


-v or –verbose directory created. When used with the [directories] argument,
it shows the names of the directories being created.

Sets file modes or permissions for the created directories. The


syntax follows that of the chmod command. Use this option to
-m specify permissions, such as read, write, and execute, for the
new directories.
• mkdir --help

• mkdir –version

• mkdir -v [directories]: display message for every created directory

• mkdir -m a=rwx [directories]

This option is used to set the file modes, i.e. permissions, etc. for the created
directories. The syntax of the mode is the same as the chmod command.
2. cd command
• CD Command stands for the full-form Change Directory.

• The CD Command is considered one of the most used Linux Commands globally.

• The CD Command is the only source to change your directory or folder from the
Linux Terminal.

• The CD Command can take an argument or folder name to directly move inside there.

• The CD . The command is used to know about the current directory.

• The CD – Command is used to back to your last working directory.


To change or move the directory to the mentioned directory .

• Syntax : $cd <directory name.

• cd ..

• cd ~
3. rmdir command

To remove a directory in the current directory & not the current directory itself.

• Syntax : $rmdir <directory name>

• The rmdir command is useful when you want to remove the empty directories
from the filesystem in Linux. This command lets you specify the terminal
to remove a particular directory right from the terminal.

• rmdir --help
• Let’s start the examples with a section with the simple rmdir command to remove
multiple directories, and here is the basic syntax:

• rmdir mydir1 mydir2 mydir3 .....

• Here we will remove LINUX, INFO, and DETAIL directories through the
following command:

• rmdir LINUX INFO DETAIL


• Example 2: The -p Option

• You can use the -p option with the rmdir command to delete a directory, including
all the subdirectories:

• rmdir -p mydir1/mydir2/mydir3/...../mydirN

• For example, we will delete the LINUX directory, including all its all ancestors,
through the following command:

• rmdir -p LINUX/mydir1/mydir2/mydir3
• Example 3: The -v Option

• If you want the terminal to display the message after removing the directory, you can use the -v option with the rmdir
command:

• rmdir -v dir1 dir2 dir3

• Let’s now delete the LINUX, INFO, and DETAIL directories and display the message after their successful removal:

• rmdir -v LINUX INFO DETAIL

• rmdir: removing directory, 'LINUX'

• rmdir: removing directory, 'INFO'

• rmdir: removing directory, 'DETAIL'


• Example 4: Remove Multiple Directories With the Same Expression

• You can delete multiple directories if they have the same expressions by using the * in the rmdir command.
For example, let’s remove all those directories which contain LINUX in their name:

• ls

• LINUX1

• LINUX2

• LINUX3

• rmdir -v LINUX*

• rmdir: removing directory, 'LINUX1'

• rmdir: removing directory, 'LINUX2'

• rmdir: removing directory, 'LINUX3'


4. ls command

• ls is a Linux shell command that lists directory contents of files and directories. It
provides valuable information about files, directories, and their attributes.

• Syntax of `ls` command in Linux

• ls [option] [file/directory]
Options Description

-l known as a long format that displays detailed information about files and directories.

-a Represent all files Include hidden files and directories in the listing.

-t Sort files and directories by their last modification time, displaying the most recently modified ones first.

-r known as reverse order which is used to reverse the default order of listing.

-S Sort files and directories by their sizes, listing the largest ones first.

-R List files and directories recursively, including subdirectories.

-i known as inode which displays the index number (inode) of each file and directory.

-g known as group which displays the group ownership of files and directories instead of the owner.

-h Print file sizes in human-readable format (e.g., 1K, 234M, 2G).

-d List directories themselves, rather than their contents.


5. cat command

• Basic Syntax of `cat` Command

• The basic syntax of the ‘cat’ command is as follows:

• cat [OPTION] [FILE]

• [OPTION] : represents various command-line options.

• [FILE] : the name of the file(s) to be processed. Let’s explore some of the
common uses of ‘cat’ along with examples.
• How to View the Content of a Single File in Linux

• The most basic use of ‘cat’ is to display the contents of a file on the terminal. This
can be achieved by simply providing the filename as an argument:

• Syntax: cat filename


• How to Create a file and add content in Linux Using `cat` Command

• If you want to create a new file or overwrite an existing file with new content, you
can use ‘cat’ with the output redirection (`>`):

• Syntax:

• cat > newfile_name

• This will allow you to type text directly into the terminal, and when you press Ctrl
+ D, the entered text will be saved to new_file.txt.
• How to Copy the Contents of One File to Another File in Linux

• As the name suggests, ‘cat’ can concatenate multiple files into a single file.This example
illustrates how to copy the entire content of “file1” into “file2” using the cat command
along with redirection (>).

• Syntax:

• cat file1.txt file2.txt > merged_file.txt

• This command combines the content of file1.txt and file2.txt into a new file
named merged_file.txt.

You might also like