About Bash: You need To know!!!

Bash:

Bash is a comand(only commands) line interpreter(line by line execution) language that let's interact with Operating system.

It allows you to make directory,edit files ,copy many more.

Bash is commonly associated with Linux systems. Bash (Bourne Again SHell) is the default shell for many Linux distributions. Bash is not limited to only linux, it is also available for various unix-like sytems including MacOs, BSD etc. In Windows through a software called WSL(Windows Subsystem for Linux) can be accessed.


Why Bash or any other command line Interface?

  • Efficiency and Speed:

Working with CLI is faster and more efficient as compared to GUI(Graphical user interface). Within a few strokes/commands we can navigate, create, edit files or folders very quickly.

  • Scripting and Automation:

One of my favourite usecase is that through writing SCRIPT we can automate various repetative tasks and complex various workflows. By creating a script file wwe can use it multiple times by just one Command.

  • Resource Efficiency:

CLI tools generally use fewer system resources than their GUI counterparts. This can be important in resource-constrained environments or when working on servers.

  • Scriptable Operations:

CLI tools are inherently scriptable, allowing us to write many commands at one single file and execute all at one go.

  • Portability:

Scripts written in Bash can be used across all other various unix-systems, allowing to create consistent solution across many Platforms.

  • Text-Based Output:

CLI tools often provide text-based output, making it easier to parse, manipulate, and integrate with other tools. This is beneficial for tasks such as data processing and system monitoring.


Some basic bash commands:

  1. ls command: The ls (list) command is used to list directories or files.
  • We can also use ls -a to view hidden files as well.

  • ls .extension to get all files, folders with that extension ex: ls *.txt

  • ls startingletter* gives all files, folders starrting with name specified. ex: ls new*;

      ls 
      ls -a
      ls *.json
      ls name*
    
  1. cd command: This allowsto change directory i.e., moving from one directory to another
  • cd foldername enters to specified folder name.

  • additionally we can also move inside nested folder in single command cd foldername/foldername2

  • to move back one folder ie., to parent directory cd ..

      cd foldername/filename
      cd ..
    
  1. pwd: This command gives us information about current working directory.
pwd
  1. m command: mv stands to move, it litreallt is used to move a file/folder inside another folder. mv project.txt NewFoldername

mv oldfile newFileName to renamea file or folder

mv new.txt directoryTobeMoved
mv new.txt new2
  1. rm command: used to delete file/folder

rm specificDirectory this deletes specific folfder

rm -i remove all files in directory

rm -i
  1. cp : similar to mv command here a copy is created.

cp oldFilename nrwFine

cp new.txt Project
  1. mdir command: This is useful when it comes to creating new directories in the file system.
  • mkdir newFolderName creates new folder

  • we can also create nested folders too mkdir project/users/customer

mkdir Project
  1. touch command: this command is used to create a new empty file.

touch newProject.txt creates new file named newProject

touch Project.txt
  1. Cat command: cat is a very commonly used command that allows users to read concatenate or write file contents to the standard output.
cat file.txt
  1. grep command: grep is used to find a word/string in set of files.

grep "string" filenName

  • grep -c "string" filename : gives number of line where "string" is present inside file

  • grep -h "string" filename : gives no of occurance inside file

  • grep -hir "string" : word inside entire directory

  • grep -hin "string": line no's inside directory where string occurs

grep "price" users.txt
  1. vim command: This command is bit difficult to use. It is used to edit an existing file. Here are sequence of steps to follow.
  • vim filename.txt to enter inside a file

  • the interface now looks smntg like this

  • ⚠️then no key works until we press i here i represnts: insert mode

  • now can we make some changes inside file: here I have written "The new File This is vim command in use"

  • to exit we need to press: esc : q !

  • to save and exit we need to enter esc : w q !


  • replit is online browser that allows to code and compile link

  • also webminal provides environment and free tutorial to get good at bash


Thanks for reading.!!!

What is your favourite command??

Connect me on X

Did you find this article valuable?

Support Shrivatsa's Blog by becoming a sponsor. Any amount is appreciated!