- Navigating and Finding Files
- Shortcuts
- Creating Files & Directories
- MAN (Manual Pager) & Help
- Extras
- Command Line Tools
pwd= Tells the current working directory
-
ls= list all files in the current directory -
ls -a&ls -la= list files with extra info -
ls ./documents= lists all the files of the relative path [./is not necessary]
-
cd folder/sub_folder= can be used to go change current directory -
cd ..ORcd ../..= used to go up directories -
cd= moves to home directory -
D:= to change drive working on [for DOS/Windows] -
pushd PATH= changes to specified path and saves the current path -
popd= brings back to the saved path ofpushd
locate FILE_NAME= finds all the directories where the file is
-
ctrl+r: search all commands -
ctrl+a: cursor to beginning -
ctrl+e: cursor to end -
ctrl+lORclear: clear screen -
ctrl+c: to stop a command that keeps running -
killall firefox: kills a process -
ctrl+dORexit: exit the prompt
touch file_1.txt file_2.txt= creates empty filesecho "hello textfile" > file_2.txt= adds text and creates fileecho "hello again" >> file_2.txt= adds text to already created filemkdir folder_name folder_name_2= can create folder with thesemkdir -p folder/sub_folder= used to create directories
cp from_dir/file to_dir/file= copies files , works with files in the current directory if no dir specifiedmv old_file_name new_file_name= move command , when used in the same directory , deletes the old file and makes a new file with the new_file_name (Renaming)mv from_dir/file to_dir/file= here move command copies the from file and deletes it , pastes it in to dir
rm file_name= the file will be deletedrm *= remove all files in directoryrm file*= removes all the files in the directory starting with 'file'rm -r= this removes the directory (-r mean recursively ,i.e remove all files all subdirectory and the directory itself)rmdir DIR= removes directories that don't have anything in them
cat file_name= reads the file and prints it in terminalcat > file_name= creates a new file and saves the input text (ctrl+d to exit)cat >> file_name= takes input of text to store and add it to filecat file1 file2= prints contents of both filesmore file1= shows the huge text of file in steps , can exit anytime pressing q
manbrings all information about specific command on terminal- Example :
man bash,man git whatis COMMAND= lets us know what the command does (executables)help COMMAND= information of shell comands (ex. cd)
-
which command_name= checks if the command is there and where it is -
history= lists all the commands typed in -
watch free -h= watch , keeps on running a command every 2 seconds and free lists the space available in pc
history | less= opens history in less models -al / > lsout.txt= redirecting output of ls into a file
- output of
ls -lshows file permissions and users with file info - Groups - USER , GROUP , EVERYONE
- Permissions - r = read (4 bit) , w = write(2 bit) , x = execute(1 bit) , all = 8 bit
- adding the values will produce appropriate number for rights given
graph TB
subgraph ah[everyone]
at3[r] -.- ab3[4] --> a3[7]
at2[w] -.- ab2[2] --> a3[7]
at1[x] -.- ab1[1] --> a3[7]
style ah fill:pink
end
subgraph bh[group]
bt3[r] -.- bb3[4] --> b3[7]
bt2[w] -.- bb2[2] --> b3[7]
bt1[x] -.- bb1[1] --> b3[7]
style bh fill:lightblue,
end
subgraph ch[user]
ct3[r] -.- cb3[4] --> c3[7]
ct2[w] -.- cb2[2] --> c3[7]
ct1[x] -.- cb1[1] --> c3[7]
style ch fill:lightgreen
end
chmod 700 file1- makes the file read write exec only for userchmod 744 file1- makes the file rwx for user , and read for otherschmod 644 file1- user can rw and others only readchmod 755 file1- user can rwx and others can rxchmod 755 dir- mostly used for directories , rwx[USER] | rx[Group] | rx[Every]
less file1= opens the specific file
| Commands | Action |
|---|---|
Down arrow, Enter, e, or j |
Move forward one line. |
Up arrow,y or k |
Move backward one line. |
Space bar or f |
Move Forward one page. |
b |
Move Backward one page. |
/pattern |
Search forward for matching patterns. |
?pattern |
Search backward for matching patterns. |
n |
Repeat previous search. |
N |
Repeat previous search in reverse direction. |
g |
Go to the first line in the file. |
Ng |
Go to the N-th line in the file. |
G |
Go to the last line in the file. |
p |
Go to the beginning of the file. |
Np |
Go to N percent into file. |
v |
Open file in your Preferred CMD editor. |
h |
Display help. |
q |
Exit less. |
-
nano= create new file & open editor -
nano file1.php= open a specific file using nano -
Ctrl is represented as
^ -
Alt is represented as
M
| Commands | Actions |
|---|---|
Ctrl + O , ^O |
Save A File |
Alt + B , M-B |
Create a Backup |
| ^X | Exit file , with prompt |
| M-U | Undo an action |
| ^G | Get Help |
| Commands | Navigate Actions |
|---|---|
| ^F | Move one character forward |
| ^B | Move one character backward |
| ^Space | Move one word forward |
| M-Space | Move one work backward |
| ^P | Move to previous line |
| ^N | Move to next line |
| ^V | Move to next page |
| ^Y | Move to previous page |
| ^A | Move to Beginning of line |
| ^E | Move to End of line |
| Commands | Search Actions |
|---|---|
| ^W | To open Search prompt |
| ^T | To Search Line Number |
| M-W | Go to Next result |
| ^R | Replace Searched Text |
| Commands | Text Actions |
|---|---|
| M-6 | Cut Text / Line |
| ^K | Copy Text / Line |
| ^U | Paste Copied Data |
-
Changing mode from one to another
-
From command mode to insert mode type
a/A/i/I/o/O( see details below) -
From insert mode to command mode type
Esc(escape key)
-
a =Append text following current cursor position
-
A = Append text to the end of current line
-
i = Insert text before the current cursor position
-
I = Insert text at the beginning of the cursor line
-
o = Open up a new line following the current line and add text there
-
O = Open up a new line in front of the current line and add text there
-
h = Moves the cursor one character to the left
-
l = Moves the cursor one character to the right
-
k = Moves the cursor up one line
-
j = Moves the cursor down one line
-
nG or :n = Cursor goes to the specified (n) line (ex. 10G goes to line 10)
-
^F (CTRl F) = Forward screenful
-
^B = Backward screenful
-
^f = One page forward
-
^b = One page backward
-
^U = Up half screenful
-
^D = Down half screenful
-
$ = Move cursor to the end of current line
-
0 (zero) = Move cursor to the beginning of current line
-
w = Forward one word
-
b = Backward one word
-
:wq = Write file to disk and quit the editor
-
:q! = Quit (no warning)
-
:q = Quit (a warning is printed if a modified file has not been saved)
-
ZZ = Save workspace and quit the editor (same as :wq)
-
x = Delete character
-
dw = Delete word from cursor on
-
db = Delete word backward
-
dd = Delete line
-
d$ = Delete to end of line
-
d^ (d caret, not CTRL d) = Delete to beginning of line
-
yy = yank current line
-
y$ = yank to end of current line from cursor
-
yw = yank from cursor to end of current word
- p = paste below cursor
- P = paste above cursor
-
u = Undo last change
-
U = Restore line
-
J = Join next line down to the end of the current line
-
:w = Write workspace to original file
-
:W = file Write workspace to named file
-
:e = file Start editing a new file
-
:r = file Read contents of a file to the workspace
To create a page break, while in the insert mode, press the CTRL key
And l. ^L will appear in your text and will cause the printer to start
A new page.
TODO:
echo '' | wc -l