10 Commonly use command in Shell/Bash Scripting

Below listed 10 commands will help you with shell scripting.

1. cat :

This command will show all the file content.
This can be used to read content of zip files too only by adding required prefix to "cat" command.

Example: You want to read content of file1.txt and  file2.zip.

>> cat file1.txt

>> zcat file2.zip

2. cd :

This command will change directory.
This can also be used to return back to home directory.

Example: If you want to go to  directory1. Once you reach directory one you can just type cd and it will take back to home directory.

>> cd /directory1

3. mkdir :

This command creates new directory.

Example: You want to create new directory name D1.

>> mkdir D1

4. cp/mv : 

Command cp/mv will create copy of file to another directory. However, when we use mv it will delete the original file.

Example: You want to copy file1 to location /new while only move file2 to location /new.

>> cp file1 /new

>> mv file2 /new

5. rm :

This will remove/delete file and directory.

Example: You want to remove file1.

>> rm file1

6. grep:

This command will help to search specific word in file.
Please click on below link to find more about grep command.
Example: You want to search echo in file1

>> cat file1 | grep "echo"

7. ls:

This command will get the list of available file & directory in a folder.

8. tail :

This command is used to print the last/recent lines from the file. N is the user input which states number of lines and need to be provided along with command.

Example - You want to see recent/last 5 lines of new created file1.

>> tail -5 file1.

9. less :

This command allows user to only view the file. "shift+G" to read last line and "G" to read first line of the opened file.

10. chmod :

This command is used to modify the access/permission of a user

No comments:

Post a Comment