Skip to content

Instantly share code, notes, and snippets.

@debabrata100
Last active April 20, 2024 07:51
Show Gist options
  • Save debabrata100/52bf694895254d44d3a3d7370d7e94df to your computer and use it in GitHub Desktop.
Save debabrata100/52bf694895254d44d3a3d7370d7e94df to your computer and use it in GitHub Desktop.
Bash commands
- $ echo
- $ say “Hi There”
- $ date
- $ cal
- $ whoami
- $ pwd
- $ ls-a (List all hidden files)
- $ ls -l
- $ drwxr-xr-x 6 debnayak wheel 192 Nov 26 2021 Applications
- [d][rwx][r-x][r-x]
- d - directory
- rwd-read, write execute by debnayak
- r-x: read, no write, execute by group wheel
- r-x: read, no write, execute by everyone else
- $ ls Desktop -la
- $ file sometext.tsx
- $ cd (Take to home)
- $ open file/folder
- $ open . (Open present working directory)
- $ touch filename.ext (create one / modify date of existing one
- $ xdc-open filename (Ubuntu)
- $ mv filename new filename(Rename a file)
- $ mv fileName Target-Folder(move to Target Folder)
- $ mv Target-Folder/fileName . (Move back)
- $ nano filename (Edit a file and write on the terminal)
- Ctrl + x Y Enter (To save edited file)
- $ cat file.txt (displays content)
- $ cp filename.txt Target-Folder
- $ rm filename.txt
- $ Star
- $ mv *.txt NewFolder
- $ mv NewFolder/*.txt .
- $ rm NewFolder/*
- $ cp 1* NewFolder
- $ ls -R
- $ rm -R A-Folder
- $ cp -R A-foler B-folder
- $ mv A-folder B-foler(Move A-folder to B-folder)
- $mv B-folder/B-foler/ . (Move back)
- $ rm -R *data (Removed folder where name container data)
- $ echo “Some text” > 1.txt (Single redirect)
- $ echo “Hello” > 1.txt (Replace existing text with new text)
- $ echo “Second Line” >> 1.txt (Add to next line)
- $ ls -l > 2.txt (Create a new file 2.txt with result of ls -l)
- $ cat 1.txt 2.txt > 3.txt (Concatenate 1.txt and 2.txt into 3.txt)
- $ls S* (List all start with S
- PIPE
- $ ls -l | tail -3 | sort | less
- $ cat 1.txt | sort | tail -10 > 2.txt
- $ find
- $ find FoderName/ -name *.txt
- $ find FolderName/ -type f
- $ find FolderName/ -type d
- $ grep
- $ grep so 1.txt // search text "so" in 1.txt
- $ grep -i so 1.txt // i for case-insentive search
- $ ls -R | grep .txt
- $ ls | grep -v t (Everything except t)
- $ ls | grep -v "\.png$" (Exclude .png files)
- $ AWK
- $ awk ‘{print}’ 2.txt
- $ awk ‘{print $1}’ 2.txt
- $ awk ‘{print $(NF-1)}’ 2.txt
- $ awk 'NR==1;NR==3 {print $0}' 2.txt
- $ awk 'NR==1,NR==3 {print $0}' 2.txt
- $ awk '/Deb/ {print }' 2.txt
- $ awk '/Deb|Gunjan/ {print }' 2.txt
- $ awk '/1/ {print }' 2.txt
- $ awk '$4~/1/ {print }' 2.txt
- $ awk '$4~/1/ {print $1,$4}' 2.txt
- $ awk '$1==$2 {print $1,$4}' 2.txt
- $ awk ' {print $1, length($1)}' 2.txt
- $ awk 'NR==2 {print $1, length($1)}' 2.txt
- Sudo
- $ sudo bash
- $ sudo chown debnayak 1.txt
- $ sudo chgrp _guest 1.txt
- chmod
- $ chmod u=rwx 1.txt
- $ chmod g=r 1.txt
- $ chmod o=w 1.txt
- $ chmod +x 1.txt
- $ chmod -x 1.txt
- $ chmod -w 1.txt
- $ ownership of folder
- $sudo mkdir closet
- $ sudo mkdir closet/one
- $ sudo mkdir closet/two
- $sudo chown -R debnayak closet
- Variables
- $ myvar = 100
- $ echo $myvar
- $ myvar = “ls -l”
- $ $myvar
- $ echo $PATH
- $ d = $(pwd) / d=`pwd`
- $ echo $d
- $ cd $d
- Read
- $ read myvar
- $ read -p “type ur name: “ name
- $echo $name
- $ read -sp “Type ur password “ pass
- $echo $pass
- $ unset v1 v2
- Arithmetic
- $ echo $(( 10+10))
- $ echo $(( 10**2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment