INTRODUCTION TO BASH | 10 MOST USEFUL COMMANDS FOR BASH | NOOB CODE PRO

INTRODUCTION TO BASH:

Bash is simply a command-line interface. A command-line interface or command-line is a program you type instructions into that your operating system executes.

You can use Bash in Linux by simply opening a program called Terminal.


You can now type commands in this window and it will be executed. The commands that are used in Bash are similar to Python functions and just like functions you can pass parameters to these commands while executing them.

10 USEFUL BASH COMMANDS:

  1. cd: This command is used to change directory of the current bash shell. For example: cd / will change the directory to root and cd /home/ will change the directory to the home folder in root. ‘cd’ followed by two periods (..) makes the shell go back one folder/directory. For example, if the shell was in /home/noobcodepro/, ‘cd ..’ will make the shell go back to home.

  1. mkdir: This will create a new folder in the Current Working Directory(CWD) i.e. the directory the shell is currently operating in. For example, ‘mkdir NCP’ will create a new folder named ‘NCP’ in the current directory.

  1. echo: This is basically the print() function of Bash. ‘echo’ is used to print something in the command-line. For example, ‘echo Hello, World!’ will print ‘Hello, World!’.

  1. export: This is used to initialize a variable. For example, ‘export x = 10’ will initialize a variable ‘x’ with the value ’10’ stored in it. You can then print the variable using the command ‘echo $x’. The Dollar sign ($) is used when printing a variable.

  2. pwd: This will simply print the current working directory. PWD stands for Print Working Directory.

  3. history: This will show you the history of commands you have executed. Needless to say, this is very useful as you can look at all the commands you have executed so far and plan your next commands accordingly. You can also scroll through your recent commands by simply using Up and Down arrow keys on your keyboard.

  1. python: This command starts our beloved Python. It starts a python shell which can be used to execute Python commands. You can exit the Python shell by using the ‘exit()’ command.

  1. touch: This creates a new file in the current working directory. For example, ‘touch hi’ creates a file named ‘hi’. 



If you use a period (.) before the filename, a hidden file will be created, ‘touch .hi’ will create a hidden file named ‘hi’. You can view the hidden files using ‘ls -a’. This will show all the files including the hidden files and folders.



  1. rm and rmdir: ‘rm’ removes a file from cwd. For example, ‘rm hi’ removes the file ‘hi’ and ‘rm .hi’ removes the hidden file ‘hi’. Similarly, ‘rmdir’ removes a folder from cwd. ‘rmdir NCP’ will remove the ‘NCP’ folder.

  1. ls: This will list all the files and folders in the current directory. This is probably the most important command in Linux. As mentioned earlier, you can use ‘ls -a’ to view all files and folders including the hidden files and folders.

CONCLUSION:

These are just 10 of the infinite commands you can execute in Bash. You can control your entire Linux OS just by knowing Bash. It is extremely useful for people who use Linux servers on a regular basis as these commands can increase your efficiency ten-folds. You can also make yourself familiar with Linux and Bash if you want to learn hacking ;)

Which one of these commands was the most useful to you? Do you know some other amazing commands for Linux users? Share your thoughts in the comments below!

Leave us a like if you found this article helpful and do share it with some Linux Lovers ;) 

Want to join a community of programmers? Join Noob Code Pro’s Official Telegram Group and learn from other programmers’ experiences and share your own experiences with them. Programmers of all levels and languages are welcome, feel free to invite your programming buddies as well. A community works better with people in it :D

See you next week with a new lesson to share with you, until then….

           HAVE AN AWESOME DAY !!!


Post a Comment

0 Comments