OS Practical
OS Practical
PWD command
• Syntax : $pwd
1. mkdir command
• mkdir –version
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.
• cd ..
• cd ~
3. rmdir command
To remove a directory in the current directory & not the current directory itself.
• 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:
• Here we will remove LINUX, INFO, and DETAIL directories through the
following command:
• 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:
• Let’s now delete the LINUX, INFO, and DETAIL directories and display the message after their successful removal:
• 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*
• ls is a Linux shell command that lists directory contents of files and directories. It
provides valuable information about files, directories, and their attributes.
• 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.
-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.
• [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:
• 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:
• 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:
• This command combines the content of file1.txt and file2.txt into a new file
named merged_file.txt.