Command Line Utilities in Linux
LS: This command is used for listing contents inside a directory
It can be called by
ls
directly or with flags like:ls -l
Display All Information About Files/Directoriesls -t
Open Last Edited Filels -1
One File in Each Linels -h
Display File Size in Human Readable FormatCAT: This command reads each file parameter in sequence and writes it to standard output.
It can be called by
cat <fileName>
directly or with flags like:cat -n
Number All Output Linescat -b
Number Nonempty Output Linescat -s
Suppress Repeated Empty Output LinesBAT:
bat
is acat
clone with Syntax Highlighting and Git Integration.To Install Bat on Linux system (with Ubuntu), run command
sudo apt install bat
.It can be called by
batcat
(in Ubuntu). To check its version run commandbatcat --version
.It can be called by
batcat <fileName>
directlyMKDIR: This command is used for creating a new directory.
It can be called by
mkdir <directoryName>
directly or with flags like:mkdir -v
Print a message for each created directoryCD: This command is used for changing the current directory.
It can be called by
cd <directoryName>
directly to change the directory to the specified directory.cd ..
(..
as an argument) can be used to change the directory to the parent directory.cd
(without any argument) can be used to change the directory to the home directory.TOUCH: This command is used for creating a new file.
touch <fileName>
ECHO: This command is used for printing a line of text/string that are passed as an argument.
echo "This is ECHO command."
It can also be used to write text to a file by using
>
(Rewrite) or>>
(Append) operator.echo "This is a new file." | cat > newFile.txt
writes the text “This is a new file.” to the newFile.txt file.echo "This rewrites the file." | cat > newFile.txt
rewrites the newFile.txt file with the text “This rewrites the file.”echo "This appends a new line in the file." | cat >> newFile.txt
appends the text “This appends a new line in the file.” to the newFile.txt file.RM: This command is used for deleting a file or directory.
It can be called by
rm <fileName>
directly or with flags like:rm -v
Print a Message for Each Removed Filerm -i
Prompt Before Every Removalrm -f
Ignore Nonexistent Files and Arguments and Remove Them Forcefullyrm -d
Remove Empty Directoriesrm -r
Remove Directories and Their Contents Recursivelyrm -rf
Remove Directories and Their Contents Recursively and ForcefullyMV: This command is used for moving a file or directory to another location.
It can be called by
mv fileName destinationDirectory
directly or with flags like:mv -v
Print a Message for Each Moved Filemv -i
Prompt Before Overwritingmv -f
Ignore Nonexistent Files and Arguments and Move Them Forcefullymv -n
Do Not Overwrite an Existing Filemv -r
Move Directories and Their Contents Recursivelymv fileName newFileName
rename a file/directoryCP: This command is used for copying a file or directory to another location.
It can be called by
cp fileName destinationDirectory
directly or with flags like:cp -v
Print a Message for Each Copied Filecp -i
Prompt Before Overwritingcp -f
Ignore Nonexistent Files and Arguments and Copy Them Forcefullycp -n
Do Not Overwrite an Existing Filecp -r
Copy Directories and Their Contents RecursivelyTREE: This command is used for displaying the directory structure in a tree format.
To Install Tree on Linux system (with Ubuntu), run command
sudo apt install tree
.It can be called by
tree
(in Ubuntu). To check its version run commandtree --version
.It can be called by
tree
directly or with flags like:tree -a
Display All Files and Directoriestree -d
Display Directories Onlytree -L <level>
Display Directory Structure to a Specified Leveltree -f
Display Full Path for Each Filetree -i
Do Not Print Indent Linestree -v
SOrt Files and Directories Alphanumerically by Versiontree -t
Sort Files and Directories by Last Modified Timetree -h
Print the Size of Each File in a Human Readable Formattree -Q
Quote Each File Name with Double QuotesFIND: This command is used for finding files and directories in a directory hierarchy.
It can be called by
find <directoryName>
directly or with flags like:find -name <fileName>
Find a File by Namefind -iname <fileName>
Find a File by Name (Case Insensitive)find -type <fileType>
Find a File by Typefind -empty
Find an Empty File or Directory