1.Bash and Terminal
Terminal
:
- Terminal is nothing but another interface to do things on your machine.
-
pwd
: present Working Directory$ pwd
-
cd
: Change Directory$ cd Desktop $ cd ../ $ cd Desktop/folders/ $ cd ../..
-
ls
: Listing all the files and folders in your current folder.$ ls
-
mkdir
: Create new folder$ mkdir projects
-
touch
: Create new empty file$ touch index.js
-
cat
: Prints contents of the file$ cat index.js $ cat test/index.js
-
vi
: Vim Editor$ vi index.text Press `i` for insert mode and write anything in your file Aman Maurya 2+ 2 hello world Esc + :q! to exit from Vim Editor without saving the file Esc + :wq! to exit from Vim Editor with saving the file
-
mv
: Move the file or folders$ mv index.js folder1 $ mv folder1 folder2
-
cp
: Copy the files or folders$ cp index.js folder1 $ cp -r folder1 folder2
-
clear
: Clear the terminal$ clear
-
nvm
: Node Version Manager - Using this you can install node. -
npm
: Node Package Manager$ npm install express $ npm install Zod
-
node
: Use to run file.```sh $ node index.js ```
Bash
Bash is Command Line Interepreter
language that lets you interact with your Operating System
.
-
pwd
(Print Working Directory): Display the current working directory$ pwd
-
ls
(List Fies): This command displays a list of files and directories in the current directories.$ ls $ ls -l $ ls -l folder1 $ ls -t $ ls -lt $ ls -R $ ls -lR $ ls -lRa $ ls -lr $ ls -s $ ls *.json $ ls Zoo* $ ls -lR | grep .json $ ls ..
-
cd
: Change Directory$ cd folder1 $ cd folder2/folder3 $ cd ../../
-
mkdir
(Make Directory): Command to create new directory/folder.<!-- Creating one folder/directory at a time --> $ mkdir frontend <!-- Creating multiple folder/directory at a time --> $ mkdir folder1 folder2 folder3 <!-- Creating Recursively folder/directory --> $ mkdir fullstack/frontend/scripts
-
touch
: Command to create new file.<!-- Creating one file at a time --> $ touch newFile.js <!-- Creating multiple file at a time --> $ touch file1 file2 file3 <!-- Creating Recursively file --> $ touch folder1/folder2/mewFile.txt
-
cat
(Concatenate): Command to display the contents of a file, insert and append contents to the file.<!-- Insert Data to File --> $ cat > newFile.js <!-- Append Data to File --> $ cat >> newFile.js <!-- Print Data of the File File --> $ cat newFile.js
-
mv
(Move File/Folder & Rename File/Folder): Command to move File or Folder one directory/folder to another directory/folder and it is also used to rename File or Folder.<!-- Moving File to Another Folder/Directory --> mv index.js frontend <!-- Moving Folder to Another Folder/Directory --> mv folder1 folder2 <!-- Renaming File --> mv index.js script.js <!-- Renaming Folder --> mv folder1 folder2
-
cp
(Copy File or Folder/Directory): Command to copy File or Folder into another Folder/Directory.<!-- Copy File to Another Folder/Directory --> cp index.js frontend <!-- Copy Folder to Another Folder/Directory --> cp -r folder1 frontend
-
rm
(Remove File or Folder/Directory): Command to Remove File or Folder/Directory.<!-- Remove File --> rm index.js <!-- Remove Empty Folder/Directory --> rmdir folderName <!-- Remove Empty Folder/Directory of Folder with Content --> rm -rf folderName
-
chmod
(Change File Permission): Modify the read, write and execute permission of a file.## There are three options for permission groups available to you in Linux. These are `users` (u): these permissions will apply to all users, and as a result, they present the greatest security risk and should be assigned with caution. `groups` (g): you can assign a group of users specific permissions, which will only impact users within the group. `owners` (o): these permissions will only apply to owners and will not affect other groups. ## There are three kinds of file permissions in Linux: `Read` (r): Allows a user or group to view a file. `Write` (w): Permits the user to write or modify a file or directory. `Execute` (x): A user or grup with execute permissions can execute a file or view a directory. $ `chmod ugo+rwx filename` to give read, write, and execute to everyone. $ `chmod -R ugo+rwx foldername` to give read, write, and execute to everyone. ## Changing Linux permissions in numeric code You may need to know how to change permissions in numeric code in Linux, so to do this you use numbers instead of “r”, “w”, or “x”. 0 = No Permission 1 = Execute 2 = Write 4 = Read => Permission numbers are: 0 = --- 1 = --x 2 = -w- 3 = -wx 4 = r- 5 = r-x 6 = rw- 7 = rwx => For example: `chmod 777 filename/foldername` will give read, write, and execute permissions for everyone. `chmod 700 filename/foldername` will give read, write, and execute permissions for the user only. `chmod 327 filename/foldername` will give write and execute (3) permission for the user, w (2) for the group, and read, write, and execute for the users.
<!-- For File --> <!-- Add execute permission for users --> $ chmod u+x index.js <!-- Add write and execute permission for groups --> $ chmod g+wx index.js <!-- Remove execute permission for users --> $ chmod u-x index.js <!-- Add read, write & execute permission for owners --> $ chmod o+rwx index.js <!-- Add read, write & execute permission for all(users, groups & owners) --> $ chmod ugo+rwx index.js $ chmod 777 index.js <!-- For Folder/Directory --> <!-- Add execute permission for users --> $ chmod -R u+x folderName <!-- Add write and execute permission for groups --> $ chmod -R g+wx folderName <!-- Remove execute permission for users --> $ chmod -R u-x folderName <!-- Add read, write & execute permission for owners --> $ chmod -R o+rwx folderName <!-- Add read, write & execute permission for all(users, groups & owners) --> $ chmod -R ugo+rwx folderName $ chmod -R 777 folderName
-
echo
: Display message on terminal.$ echo "Hello, World!" $ echo $PATH
-
head
: Show the content from top of the file.<!-- Bydefault show first 10 rows --> $ head index.js <!-- Show first 20 rows --> $ head -20 index.js
-
tail
: Show the content from bottom of the file.<!-- Bydefault show last 10 rows --> $ tail index.js <!-- Show last 20 rows --> $ tail -20 index.js
-
|
(Pipe Operator): Combine multiple command.command1 | command2
- Whatever output comes from command1 it flows to command2<!-- gives 5 rows after 15th rows - means shows lines 16 to 20 --> $ tail -n +15 index.js | head -5
-
wc
(Word Cound): Shows numbers of lines, words and characters.<!-- print numbers of lines, words and characters of index.js file --> $ wc index.js
-
grep
: Use for matching operations. Print those line which contains particular characters, words, sentences.<!-- print all line which contains character 'a' --> $ grep "a" index.js <!-- print all line which contains word 'Hello' --> $ grep "Hello" index.js <!-- print all line which contains sentence 'Hi, Everyone!!' --> $ grep "Hi, Everyone!!" index.js <!-- Print all lines which does not contains Aman --> $ grep -v "Aman" index.js <!-- Print before 5 lines, which line contains Aman --> $ grep -B 5 "Aman" data.txt <!-- Print after 5 lines, which line contains Aman --> $ grep -A 5 "Aman" data.txt <!-- Print before and after 5 lines, which line contains Aman --> $ grep -C 5 "Aman" data.txt <!-- print numbers of lines, words and characters of index.js file which contains word "Aman" --> $ grep "Aman" index.js | wc <!-- only occurence of a parthicular word --> $ grep "Aman" index.js | wc -l <!-- Print Occurence Count --> $ grep -c "Aman" index.js <!-- Print Matched Line --> $ grep -h "Aman" index.js <!-- ignore case --> $ grep -hi "Aman" index.js <!-- Print matched line data after ignoring case with line number --> $ grep -hin "Aman" index.js <!-- Print those line which contains word "Aman", but seperate --> $ grep -hinw "Aman" index.js <!-- Print only the matched Part --> $ grep -o "Aman" index.js <!-- For current directory --> $ grep -hir "Aman" index.js
-
history
: History of all command that you ran.$ history
-
Bash Scripting
: Using Bash Scripting we can Automate our work. It is a language.<!-- script.sh --> #!/bin/bash echo "Hello, World!!" mkdir automated_dir cd automated_dir && touch newFile.txt
-
bash
: Command to run bash scripting file.<!-- Run the script.sh file - first it will print "Hello, World", then it will create a folder autemated_dir and after that it will move to automated_dir folder and create newFile.txt inside that folder. --> $ bash script.sh
-
clear
: Clear the terminal$ clear
-
nvm
: Node Version Manager - Using this you can install node. -
npm
: Node Package Manager$ npm install express $ npm install jsonwebtoken
-
node fileName.js
: Use to run file.$ node index.js