-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLinux Upskill Challenge
167 lines (102 loc) · 5.57 KB
/
Linux Upskill Challenge
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
1. How to create a new user and a new password for that user?
sudo adduser <username> //to add a new user
or, sudo useradd <username>
ex: sudo adduser pragya
sudo passwd <username> //to create a new password for user
// Note: new user can't run 'sudo' commands with elevated privileges by default.
// Any such attempts are reported in log for administrative user to see.
// We could add Pragya to a group that is pre-defined, to able to use sudo to
// do anything as root - but we don't want to give such super power to Pragya, do we?
whoami //see which user I am currently
su - pragya //will switch to named Pragya
exit //will switch back to Pranav if you are in Pragya, else close the terminal.
logout //will switch back to Pranav
su - pranav //will swtich back to Pranav
su - //will switch to Root user
usermod -aG sudo pragya // Add the user (pragya) as an admin
usermod -aG wheel pragya // In fedora, "wheel" is the default group where admins are listed.
sudo deluser pragya sudo // Remove the user (pragya) from admin groups
sudo userdel pragya // Delete the user (pragya)
sudo userdel -r pragya // Wipes files and foler. Basically everything
``````````````````````````````````````````````````````````````````````````
2. How can two user copy their files?
sudo cp /home/pragya/Pictures/cat.png /home/pranav/Pictures
[To copy files between users, one need have sudo permission.]
``````````````````````````````````````````````````````````````````````
3.
less //read output serially
```````````````````````````````````````````````
4.
df //disk free commmand to know about disk state
``````````````````````````````````````````````````````````````````````
5. Couting
wc //word count
wc -l //count all lines
``````````````````````````````````````````````````````````
6.
ss -4 //socket status using ipv4
ss -6 //socket status using ipv6
````````````````````````````````````````````````````````````
7. Find file in particular directory
find /home/pranav -name Penuma.mp3
`````````````````````````````````````````````````````
8. Make a script executable
chmod +x /path/to/script.sh
```````````````````````````
9. Multiple Ways to jump back or go to previous directory
cd - // fastest way to jump previous directory. Its possible because cd command is looking at $OLDPWD value
cd ../.. // will go 2 directories back. [More (two-dots + Forward slash)] = more directories back
cd /path/of/directory // will go to particular directory
[This means, in bash we have: echo $OLDPWD ]
``````````````````````````````````````````````````````
10. Cat Scenario
cat > fileName.txt //will create the file name; else overide the existing file
cat >> fileName.txt //add new lines in existing file; else create a new file to write
cat << Pranav > File.txt //create a new file else overide file named "File.txt" where "Pranav" marks end of file
[Press "Ctrl + d" to save the file]
11. Echo Scenario
echo "linux.org" > website.txt // create new file or override exisiting file named "website.txt"
echo "regex.com" >> website.txt // will add new line in file named "websiet.txt"
# < redictor is used for standard input.
# 2> redictor is used for standard error.
Example:
ls /path/to/folder/which/do/not/exit 2> error.txt
[will include error occured in new or exisitng file named "error.txt"]
12. Move/copy files inside current directory without having to write full path
mv image.png ./Image
[Here we have to be inside a directory which has Image folder]
mv image.png ./Image/picture.png //move + rename the file inside current subdirectory
14. Move multiple files
mv this that.txt ./folder //move folder named "this", file named "that.txt" inside folder named "folder"
15. Create multiple directories one inside another in one shot
mkdir -p first/second/third //creates "first" folder & create "second" folder inside first folder & "thrid" folder inside second folder.
16. Basic vi nagivation while reading documentation/script/note through terminal
g ------>> jump to first line of terminal content
G ------>> move to end line of terminal content
/ ------>> search
q ------>> quit
==========================================================================================
17. Force a user to create a new password
passwd -e <username> //here e flag will expire the existing password.
[let say, the password of a user is leaked. Got to do something about it as an admin.]
17.1 Change the password of current user
passwd
==========================================================================================
18. Chmod the file | File Permissions
chmod u+x filename // allows file to be executed by anyone
chmod u-x filename // allows file to be executed by owner
chown pragya filename // change the owner of file to pragya
chgrp ladies filename // change the group of file to ladies
=========================================================================
19. SetUID on a file // SetUID is used to allow a file to run as the owner of the file.
sudo chmod u+s filename // ? what is the point of doing this?
[answer: Admin might want to allow its user to execute certain trusted file/program.]
20. GetUID on a file // GetUID is used to allow a file to run by a 'group of users'.
sudo chmod 4755 filename
[Let the user of particular group to be able to run the particular file/program.]
21. Sticky bit on a file
sudo chmod +t filename // 1755 can also be used instead of "+t".
[Let anyone to modify the file. But only admin or owner, delete the file.]
22. Give write access to the owner of the file
chmod o+w filename
[now user can read and also write on the file. But can't execute the file.]