LinuxBasicCommands
LinuxBasicCommands
By TechNow Tamil
Top 15 Commands
man mv
pwd rm
cd vi
ls grep
touch head
cat tail
mkdir history
cp
By TechNow Tamil
Objective
Get started with the Linux terminal & begin using terminal commands.
Primary goals
Here are a list of things you will learn in this tutorial:
▪ Search directories for files and search files for interesting patterns.
By TechNow Tamil
1. man
In Linux, the man command is used to display the documentation/user manual on just about any Linux
command that can be executed on the terminal. It includes the name of the bash command, its detailed
synopsis, a short description, existing versions of the command as well as authors of the bash command.
man ls
This command is used to display the documentation on the 'ls' command in
Linux.
By TechNow Tamil
2. pwd
The pwd command in Linux translates to "Print Working Directory" and is used to
display the path of the current working directory inside the terminal.
Syntax:
pwd --(Options)
The pwd command has two tags:
-L: It displays the symbolic version of the existing path.
-P: It displays the actual existing path, without symbolic links.
By TechNow Tamil
3. cd
The cd command in Linux expands to 'change directory' which gives a fair hint as to what the command
does. Yes, it is used to change the current working directory to a specified folder inside the terminal.
Syntax:
cd [Options] [Directory]
Example:
cd /var/log – Change Directory to /var/log
By TechNow Tamil
4. ls
The ls command in Linux is used to display a directory's files and folders.
This command is super useful if you want to explore the contents of a given directory inside the terminal
without navigating to the GUI folder.
Syntax:
ls [Options]
Example:
ls – Simply list contents available in current working directory
Syntax:
touch (file name)
Example:
touch test1.txt – Simply creates empty file on present directory
Syntax:
cat (Options) (file name)
Example:
cat file1.txt – Read contents of file1.txt
By TechNow Tamil
7. mkdir
The mkdir command in Linux is used to create new directories inside an existing working directory from the
terminal.
Syntax:
mkdir (Options) (directory name)
Example:
mkdir folder1 – Creates folder in present working directory
By TechNow Tamil
8. cp
The cp command in Linux translates to 'copy'. It is used to copy files/directories from one location to
another from inside the terminal.
Syntax:
cat (Options) (Source) (Destination)
Example:
cp file1.txt folder1/ – Copy file1.txt to the directory folder1.
By TechNow Tamil
9. mv
The mv command in Linux translates to 'move'. It performs two major functions in Linux.
• You can rename a file/directory using this command.
• You can easily move a file/directory from one location to another.
Syntax:
mv (Source) (Destination)
Example:
For Moving a file (or) folder:
mv file1.txt folder1/ – Moving file1.xt to the directory folder1. Same procedure for move a directory.
By TechNow Tamil
10. rm
The rm command in Linux helps you delete files and directories.
Syntax:
rm [Options] [file name]
Example:
rm file1.txt – Delete file1.txt from the present directory.
By TechNow Tamil
11. vi (or) vim
The vi command in Linux allows a user to edit any text content inside the
Vim text editor from the terminal.
Syntax:
vi (Options) (file name)
Example: vi file1.txt – Read contents of file1.txt
Here's a list of commonly used keyboard shortcuts used
inside the Vim editor in Linux:
i - Used to enter insert mode in Vim editor.
dd - Delete a line quickly. (Use the Esc key to exit out of insert mode)
yy - Copy a line/lines inside the editor.
p/P - Paste command
u - Undo command
Ctrl+r - Redo command
:wq - Save and quit Vim editor.
:q - Quit Vim editor without saving a file.
By TechNow Tamil
12. grep
The grep command in Linux searches through a specified file and prints all lines that match a given
pattern.
Syntax:
grep (Options) (SearchingPattern) (Directory name)
Example:
grep Hello file1.txt – Find Hello word inside the file1.txt file.
By TechNow Tamil
13. head
The head command in Linux prints the first N lines of a given file content. Yes, it's that simple.
Syntax:
head (Options) (File name)
Example:
head -n 2 file1.txt – Prints first 2 lines of the file.
By TechNow Tamil
14. tail
The tail command in Linux prints the last N lines of a given file content. Yes, it's that simple.
Syntax:
tail (Options) (File name)
Example:
tail -n 2 file1.txt – Prints Last 2 lines of the file.
By TechNow Tamil
15. history
The history command in Linux is used to view a history of all the commands previously executed inside the
bash terminal. The total number of executed commands will vary from one system to another.
Syntax:
history
Example:
history