Skip to content

Commit 4b0a056

Browse files
LINUX COMMAND
1 parent 703cab6 commit 4b0a056

1 file changed

Lines changed: 137 additions & 0 deletions

File tree

LINUX/Basic_Command

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
## LINUX COMMAND
2+
3+
##DIRECTORY
4+
5+
sudo - super user do
6+
---
7+
pwd --> displays present working directory
8+
---
9+
mkdir (directory name) --> This command create a directory
10+
---
11+
cd (directory/folder where you want to navigate) -->This command change directory.
12+
---
13+
ls --> lists contents of current directory
14+
---
15+
ls -l --> list contents of current directory with detailed output
16+
---
17+
ll --> list contents of current directory with detailed output
18+
---
19+
cd <folder>
20+
---
21+
cd .. --> to come out of a directory
22+
---
23+
rm -r testdir --> to remove a directory
24+
---
25+
~ --> Home directory
26+
---
27+
mkdir -p folder/subfolder/subfolder2 --> create parent and child directory
28+
29+
---
30+
---
31+
32+
##FILE
33+
34+
touch test.txt(file name) --> creates a empty file
35+
---
36+
ls -l --> lists the contents in current directory
37+
---
38+
echo Print Output
39+
40+
echo "This is a text" > test.txt
41+
---
42+
cat test.txt --> writes the content of file into terminal & exits
43+
---
44+
more test.txt --> writes the content of file on terminal page by page ( to move to next page need to hit space bar on keyboard )
45+
---
46+
less test.txt --> open the file on terminal & can be read line by line (use arrows to scroll up & down)
47+
48+
To comeout need to press 'q' on the key board
49+
---
50+
vi test.txt --> Visual Editor
51+
-This opens the file in read only mode
52+
-To edit the file, press 'i' on keyboard for INSERT mode & then you can write anything
53+
-once the text is entered, press 'ESC' on keyboard to return back on readonly mode
54+
-press ':wq' on keyboard -- to save & come out of the file
55+
-press ':q' on keyboard -- to come out of the file without saving
56+
-press ':wq!' on keyboard -- to save forcefully & come out of the file
57+
-press ':q!' on keyboard -- to come out of the file forcefully without saving
58+
---
59+
rm test.txt --> To remove a file
60+
---
61+
COPY/RENAME/MOVE/OPERATION
62+
63+
While performing these operations, we can always use absolute paths or relative paths accrodingly.
64+
These commands expects source & dest values
65+
66+
cp A.txt B.txt --> makes a copy of A.txt names it to B.txt in current directory
67+
68+
cp /home/A.txt /tmp/A.txt --> make a copy of A.txt to /tmp
69+
70+
cp -r testdir/ newdir/ --> makes a copy of testdir & names it to newdir in current dirctory
71+
72+
cp -r /home/testdir /tmp/testdir --> makes a copy of testdir to /tmp
73+
74+
mv A.txt new.txt ---> renames A.txt to new.txt in current path
75+
76+
mv A.txt /tmp ---> moves to A.txt to /tmp
77+
78+
mv testdir newdir --> renames testdir to newdir in crrent path
79+
80+
mv newdir /tmp ---> moves newdir to /tmp path
81+
82+
---
83+
84+
##PERMISSION
85+
86+
Observe the output of ls:
87+
88+
drwxrwxr-x 2 manifoldailearning manifoldailearning 4096 Nov 7 23:38 testdir
89+
-rw-rw-r-- 1 manifoldailearning manifoldailearning 126 Nov 7 23:37 abc.txt
90+
-rw-rw-r-- 1 manifoldailearning manifoldailearning 126 Nov 7 23:38 one.txt
91+
92+
drwxrwxr-x or -rw-rw-r-- --> Read/Write/Execute Permission for a file or a directory in linux
93+
94+
(1st value)manifoldailearning --> owner of the file/directory
95+
(2nd value)manifoldailearning --> group who owns file/directory
96+
97+
---
98+
99+
How to update the owner & group for a file/dir -
100+
101+
chown ( change owner ) is the command to update the owners of dir/file
102+
note: note that you need to have previliges to update the permissions for a file/directory
103+
104+
Syntax: chown owner:group filename/dirname
105+
106+
---
107+
108+
How to update the read,write & execute permissions for a file/dir
109+
110+
How to decode the Read/Write/Execute Permission terminology:
111+
112+
-/d ---> denotes if it is a file or directory ( - means file / d means directory )
113+
rwx ---> means read,write & execute permissions for super user ( root )
114+
rw- ---> means read,write permissions for the owner of the file ( ex: manifoldailearning as above )
115+
r-- ---> means read only permissions for others ( whoever login to the machine )
116+
117+
118+
r --> Permission to read the file.
119+
w --> Permission to write (or delete) the file.
120+
x --> Permission to execute the file, or, in the case of a directory, search it.
121+
122+
chmod ( change mode ) is the command to update the read/write/execute permissions for a file/directory
123+
r = 4, w = 2, x = 1
124+
125+
- | rwx | rwx | rwx
126+
- | 421 | 421 | 421
127+
128+
To update the permissions we can sum 421
129+
If super user needs to have read,write & exeute give 7
130+
If the owner need to read & write give 6
131+
If other need to have only read give 4
132+
133+
134+
chmod 777 file/dir -- rwx for root, rwx for owner, rwx for others
135+
chmod 764 file/dir -- rwx for root, rw for owner, r for others
136+
chmod 755 fire/dir -- rwx for root, rw for owner, rw for others
137+
v

0 commit comments

Comments
 (0)