Linux Commands
Linux Commands
15. cd --------------------------- Go to
16. cd .. ------------------------ Go to previously directory.
17. cd ../../ -------------------- Go back twice.
18. touch ------------------------ To create a file. {EX- touch a.js}
19. cat -------------------------- To view what is inside in a file. {EX- cat a.js}
20. cat > a.txt ------------------ To write something in a file. ctrl + D to save
and exit. ctrl + C to exit.
21. cat >> a.txt ----------------- To write more details to the existing file which
was cat > a.txt
35. chmod 664 foldername --------------- This will give to ugo group like first
place 6 is for user(u) second 6 is for group(g) & third 4 is for other(o).
Now here 6 = 4+2 mean 4 is for read and 2 is for write so user(u) will have read &
write permissions.
Now here 6 = 4+2 mean 4 is for read and 2 is for write so group(g) will also have
read & write permissions.
Now here 4 which is for read and 2 is for write so other(o) will have only write
permissions
Now if we want to give all the permissions then the number will be 7(4+2+1;
summetion of all) for all the cases like - chmod 777 foldername
42. grep "one" filename ------------------ Where "one" has been used in the file.
43. grep "one" filename | wc -l ---------- How many times "one" has been used in
the file.
44. grep -c "one" filename --------------- How many times "one" has been used in
the file.
45. grep -h "one" filename --------------- Where "one" has been used in the file.
(case sensitive)
46. grep -hi "one" filename -------------- where "one" has been used in the file.
(not case sensitive)
47. grep -hir "one" directoryname -------- Where "one" has been used in the folder.
48. grep -hin "one" filename ------------- Where "one" has been used in the file
inc line numbers. (not case sensitive)
49. grep -hinw "one" filename ------------ Where "one" has been used inside a word
also individually. {colone, one, One} (case sensitive)
50. grep -o "one" filename --------------- Only gives us the matched part.
51. grep -w "one" filename --------------- Where "one" has been used in the file.
52. history ------------------------------ To view all the command that i've used.
53. bash filename ------------------------ This will straightforward execute a Bash
script, regardless of the script's execution permissions.
54. grep "ERROR" filename ---------------- Will view all the error messages in that
file.
55. grep -v "INFO" filename -------------- Will give all the info of the file.
56. grep -A 5 ERROR filename ------------- To view rows after the occurance of
ERROR text in a file
56. grep -B 5 ERROR filename ------------- To view rows before the occurance of
ERROR text in a file
56. grep -C 5 ERROR filename ------------- To view rows before and after the
occurance of ERROR text in a file.
57. sed -n '/ERROR/ p' filename ------------------ To print lines with ERROR text.
58. sed 's/ERROR/CRITICAL' filename -------------- Replace ERROR with CRITICAL in
the file.
59. sed -ibackup 's/ERROR/CRITICAL/' filename ---- Create a backup of the file.
60. sed '3 s/CRITICAL/VERYCRITICAL/' filename ---- Replace CRITICAL with
VERYCRITICAL in line number 3.
60. sed '3,5 s/ERROR/CRITICAL/' filename --------- Replace CRITICAL with
VERYCRITICAL in line number 3 to line number 5.
60. sed -n '3,/ERROR/ p' filename ---------------- This is used to selectively
print a portion of a file, starting from a specific line (line 3 in this case) and
continuing until a line containing a specific pattern (in this case, "ERROR") is
encountered.