0% found this document useful (0 votes)
9 views4 pages

Linux Cammands

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views4 pages

Linux Cammands

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

1.

pwd -> print working directory

2. mkdir -> to create directory

3. ls -> list cmd

4. cd -> to change directory

5. /home/dir1/dir2 -> abosolute path

6. parent directory -> ..

7. current directory -> .

8. cd .. -> go to parent directory

7. cd . -> shows current girectory

8. mv [source] [destintion] -> used to rename by move cammand

9. cat>>file_name.txt -> creating file and writing simultaneously , data will


append to previous data
use ctr t to go back in shell and save the file

10. mv file_name [source] [destination] -> to move the file


a. mv file.txt ../D1 (file from current directory will be moved to D1
directory which is in parent directory of current)
parent
current D1
11. cp [source] [destination] -> copy the file from source to destination
cp ../D1/f1.txt . (copy the file which in parent->D1->file to current
directory )

12. cp -r [source directory] [destination directory] -> copying entire file into
new directory recurrsively

13. rm file.txt -> it will delete a file from same directory


It is like a shift delete , we can't restore it again

14. rm -r D4 -> to delete whole directory recurrsively

15. rmdir D4 -> to delete empty directory

16. man [cmd] -> to get online manual help about the cammand

17. clear -> to clear the terminal window

18. which -> used to display path ofsystem executable

19. tar -> used to compress or extract files


cmd -> tar -czvf [file_name.tar.gz] [path_directory_file] ==> to compress
file gunzip format
cmd -> tar -xzvf [filr_name.tar.gz] ==> to extract file
gunzip format

20. pager cammand


a. more file_name -> used to see contents of file one screen at a time with
limited backword moment
b. less filr_name -> it provide more flexibility with backeword and foreword
moment in file

{ less is batter than more}

21. find -> used to find the ordinary file and directories
a. find [path] -type f -name [file_name.txt] ==> this is case sensitive
b. find [path] -type f -iname [file_name.txt] ==> this will ignore case i.e.
not case sensitive
c. find [path] -type f -iname [file_name.txt] -exec rm -f {}\; ==> find file
and remove it forcefully
d. find [path] -type f -name"*.txt" ==> to find multiple file
d. find [path] -type d -name [directory_name] ==> finding directory by name
-----------------------------------------------------------------------------------
----------------------------------------------
-----------------------------------------------------------------------------------
----------------------------------------------

22. Cammand Options


a. ls -l (long listing)
o/p = d rwx rwx r-x maven_user 20 june20
ftype | owner permission | group permission | other users
permission | owner | size in bytes | date of creation

b. ls -a (diaplay all hidden files)

c. rm -r ==> remove directory in recurrsive order

d. cp -r ==> copy all files in recurrsive order

-----------------------------------------------------------------------------------
----------------------------------------------
-----------------------------------------------------------------------------------
----------------------------------------------

21. File permission


r-w-e -> read , write , execute
u-g-o -> owner , group , other

a. Change file permission


chmod u+x file1.txt ==> give the permission owner to execute the file
chmod u-x file1.txt ==> to remove the access from owner to execute the
file

22. grep -> find a pattern occuring in file without opening the file
grep -nr ["word to search for"] [path]

23. redirect operator


ls -l > f1.log
it will log the data into f1.log file

24. Wirldcard character


* is used to match the zero or more character match

25. Change password


passwd

26. sed -> stream editor used to text substitution , insertion , and deletion
sed 's/[original_word]/[new_word]' [path_for_file] ==> substitute only 1st
occerance
sed 's/[original_word]/[new_word]/n' [path_for_file] ==> substitute nth
occurance
sed 's/[original_word]/[new_word]/g' [path_for_file] ==> to substitute all
occurance

sed 'n s/[original_word]/[new_word]/g' [path_for_file] ==> to substitute at


nth line
sed 'n,m s/[original_word]/[new_word]/g' [path_for_file] ==> to substiute
range of line

-----------------------------------------------------------------------------------
----------------------------------------------
-----------------------------------------------------------------------------------
----------------------------------------------
-------------------------------------------------- V I Editor
-------------------------------------------------------------------
-----------------------------------------------------------------------------------
----------------------------------------------
-----------------------------------------------------------------------------------
----------------------------------------------
-----------------------------------------------------------------------------------
----------------------------------------------
1. to create vi file
vi [file_name.txt]

3 modes of VI editor
a. cammand (can't be edited)
b. insert (press i to insert)
c. cmd line mode (press Esc and :)

2 versions of VI editor
a. Vim (vi improved)
b. Gvim (graphical vi mode)==> preferred

-----------------------------------------------------------------------------------
-------------------------------------------------------------------
cammand mode cammands
-----------------------------------------------------------------------------------
-------------------------------------------------------------------
1. to delete and cut the line
go to line
press Esc and dd

2. to delete n lines sequentially


Esc + ndd

3. copy single line


Esc + yy

4. to paste once
Esc + p

5. to copy n lines
Esc + n yy

6. to paste n times
Esc + n p
7. to undo the chnages
Esc + u

8. to undo last n changes


Esc + n u

9. to copy entire paragraph


Esc + first line of para + mm + last line of para + ym -> to copy
to paste p

-----------------------------------------------------------------------------------
-------------------------------------------------------------------
cammand Line mode cammands
-----------------------------------------------------------------------------------
-------------------------------------------------------------------

1. to save the contents


Esc : w

2. to save and exit


Esc :wq

3. to set line numbers


Esc : set number

4. to jump the cutsor to line no. n


Esc :n

5. to search a pattern
Esc/pattern

6. to search and replace pattern for all lines for 1st occurance
Esc:%s/[old_word]/[new_word]

7. to search and replace pattern for all lines and all the occurance
Esc:%s/[old_word]/[new_word]/g -> g for global

8. to search and replace pattern for all lines for all occurance ignoring the case
Esc:%s/[old_word]/[new_word]/gi

9. to search and replace pattern for line number n


Esc:ns/[old_word]/[new_word]/gi

10. to search and replace pattern for range of line m to n


Esc:m,ns/[old_word]/[new_word]/gi

You might also like