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