Linux- Basic commands
Status check of instance
0/2 → hardware issues
1/2 → software issues
2/2 → all okay
Prompt :
[ec2-user@ip-172-31-81-230 ~]$
1. ec2-user → username → dynamic
2. @ → separation symbol
3. hostname → aws → private IP → static
4. ~(home directory of user)→ tild sign → present working directory
5. represent type of user → $ (local user) , #(root user)
Types of user in Linux
1. root user
2. local user
3. super-user
4. system user
Commands
su - root / sudo -i → switch user to root
pwd → to show present working directory
clear → to clear terminal
whoami → display username
logout → to exit from current terminal
Linux- Basic commands 1
which <command_name> → which pwd → it shows path of the command file
forward slash → represent Directory
/ec2-user/data/
/home → 2 dir(/ , home)
/home/ec2-user/ → 3(/, home, ec2-user)
Basic commands
touch → to create files
echo → to print strings
mkdir → to create a directory
rm → to remove files
cd → to change directory
man → manual pages of commands
cat → to read files
ls → to list files in present working directory
rmdir/ rm -r → to remove directory
rmdir -p <full_path> → to remove full parental directory
rm -r <dir_name> → to remove full parental directory
rm -rf → remove files and directory forcefully
Copy + paste → cp
/ → home → ec2-user → shared
|
terminal.txt
syntax : cp <source-path-of-file> <destination-dir>
1. cp terminal.txt shared/ → copy files at destination directory
Linux- Basic commands 2
2. cp fruits.txt shared/fruits1.txt → rename file while copying at destination
3. cp *.txt txt/ → copy all files ends with .txt
4. cp -r txt/ shared/ → to copy directory
cut + paste → mv
syntax : mv <source-path-of-file> <destination-dir>
1. mv ls.txt aws/ → to move files at destination directory
2. mv <old_file_name> <new_file_name> → to rename files/dir
3. mv /home/ec2-user/aws/ /home/ec2-user/cpp/ → to move compete dir with
it’s content (mention full path)
file filter operations
1. grep → to filter
- ls -ltr | grep "shared"
- cat cp.txt | grep "recursive"
1. locate → to search files
- sudo updatedb
-locate fruits.txt
Editors
1. vi → vim
2. nano
3. gedit
Vim editor
1. command mode → insert mode → press “i”
2. insert mode → command mode → press “ ecs”
3. visual mode
save + exit → :wq (w-write changes, q -quite)
without save + exit → :q!
Linux- Basic commands 3
command mode
shift + g → jump from top to bottom
gg → jump from bottom to top
/word → to search word from top to bottom, press n for next
?word→ to search word from bottom to top, press n for next
:%s/old_word/new_word : replace the word
u → undo files
ctr + r → redo file
x → delete the character where cursor is present
r → replace single character
dd → to delete the line
:e! → to undo all the changes
v → to enter into visual mode → select data
shift + v and right arrow → to select single character
y → copy selected text
p → to paste the line below the cursor is present
shift + p → to paste the line above the cursor is present
cut + paste → (dd , p)
copy + paste → (y , p)
press 15 + dd
:set nu → set number
:set nonu → to remove number
:100
File hierarchy
/ → top-level directory/ main directory/ root-level directory
/bin → contains all the commands → local user
/sbin → contains all the commands → root user
Linux- Basic commands 4
/home → home directory of local user
/root → home directory of root user
/etc → all configuration file
/dev → device related files
/lib → 32 bit archi
/lib64 → 64 bit archi
/boot → booting files
/mnt → partition mount files
/sys → system related files
/usr/ → user related files
/srv → service related files
/var → log, mail, cron
/tmp → deleted files
/opt → optional files
/proc → all ps files
/run → all running files
/media → detachable devices files
Linux- Basic commands 5