-
Notifications
You must be signed in to change notification settings - Fork 0
/
Linux CLI
255 lines (187 loc) · 4.7 KB
/
Linux CLI
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
Directory:
--------------------
Show directories contents:
ls
List all .PNG files:
ls *.png
Remove all .PNG files:
rm *.png
Create single/multiple directory:
mkdir "Directory1" "Directory2" "Directory3"
Create Directory and sub-directorys:
mkdir -p "parent/child/grandchild"
Create a directory absolute path:
mkdir "Path""Directory1"
Copy a directory:
cp -R "Source1" "Destination1"
Files:
--------------------
Find a file :(Use locate you use a database searching method)
find -iname "*.txt"
-Find a file with the extension ".text" and then prompt each file to be removed. removing "-i" will remove the prompt.
find -iname "*.txt" -exec rm -i {} \;
Find files modified within the last 7 days.:
find -mtime -7
Copy file(s) to a destination:
cp "Source1" "Source2" "Source3" "Destination1"/
rename a file:
mv "Filename1" "NewFilename1"
Move files to a location:
mv "Source1" "Source2" "Source3" "/Destination1"
Remove file(s):
rm "file1" "file2"
or
rm "location/file1" "location/file2"
Add the following to ask before delete or to delete directories.
-i, Ask for confirmation
-r, Delete directories
Head:
head -n 5 wordlist.txt
Tail:(View the last 5:
tail -n 5 wordlist.txt
Header(Hex)
xxd file
or
od -bc {filename} | head
Header(Binary)
xxd -b file
or
od -bc {filename} | tail
Create a tar file:
add the variable
v-verbose
z-compress as .gz extension
tar -c archive.tar
Test a tar file:
tar -t archive.tar
creates an archive including any files starting with file and specific file anotherfile.txt:
tar -cvf archive.tar file?.txt dir? anotherfile.txt
Permissions:
--------------------
-Add Read/Write and Execute permissions.
chmod u+rwx "file"
-Remove Read/Write and Execute permissions.
chmod go-w [file_name]
Processes:
--------------------
List of processes
ps aux
List and search for a process name
ps aux | grep "process name"
Stop a running process by process ID
kill -9 "5161"
Download:
--------------------
download file from location
wget "IP/hostname/website"
CRON Job
--------------------
List Cron scheduled jobs
crontab -l
Edit Cron scheduled job
crontab -e
Cron Scheduled job sample:
# * * * * * <command to execute>
# | | | | |
# | | | | day of the week (0–6) (Sunday to Saturday;
# | | | month (1–12) 7 is also Sunday on some systems)
# | | day of the month (1–31)
# | hour (0–23)
# minute (0–59)
Runs a bash script at the Date/Time specififed
i.e 45 23 * * 6 /home/oracle/scripts/export_dump.sh
Create a script
sudo nano /usr/local/bin/Hello_FOSSLinux.sh
Copy the following to the file
"
#!/bin/bash
echo "Hello, FOSSLinux!"
"
input sudo chmod +x /usr/local/bin/Hello_FOSSLinux.sh to make the script executable
sudo nano /etc/systemd/system/FOSSLinux.service to edit file
"
[Unit]
Description=FOSSLinux Service
[Service]
ExecStart=/usr/local/bin/Hello_FOSSLinux.sh
[Install]
WantedBy=multi-user.target
"
[Unit]
Description=FOSSLinux Service
[Service]
ExecStart=/usr/local/bin/Hello_FOSSLinux.sh
[Install]
WantedBy=multi-user.target to reload
systemctl start FOSSLinux
systemctl enable FOSSLinux
System Info:
--------------------
Show hostname
hostname
Show IP
hostname -I
Filesystem info:
df -h
File Info:
df -h "file"
Mount:
--------------------
Syntax
mount -t [type] [device] [dir]
e.g.
Mount Filesystem:
sudo mount /dev/sdb1 /mnt/media
Mount USB:
Mount CD-ROM:
mount -t iso9660 -o ro /dev/cdrom /mnt
Mount ISO:
sudo mount /image.iso /media/iso-file -o loop
mkdir /media/usb-drive:
Step 1 - fdisk -l
Step 2 - sudo mount /dev/sdb1 /media/usb-drive
Unmount:
umount [dir/Device/]
Manually Mount Share:
Step 1 - Create a mount location
i.e sudo mkdir "/var/backups"
Step 2 - Moun the share
sudo mount -t nfs 10.10.0.10:/backups "/var/backups"
Ato Mount share:
Step 1 - Create a mount location
i.e sudo mkdir "/var/backups"
Step 2 - Open file to edit
sudo nano /etc/fstab
Step 3 - Add the lines:
mount /var/backups
mount 10.10.0.10:/backups
On reboot the share will be remounted
Remove Mount:
umount 10.10.0.10:/backups
umount /var/backups
or
remove lines from sudo nano /etc/fstab
Networking:
--------------------
Display IP:
ip address
display stats:
ip -s link
Turn off network interface:
sudo ip link set dev enp0s3 down
Turn on network interface:
sudo ip link set dev enp0s3 up
View routing:
ip route
Add a route:
sudo ip route add "10.0.3.0/24" via "10.0.2.1"
Delete a route:
sudo ip route delete "10.0.3.0/24" via "10.0.2.1"
scp, send a file:(add -r for recursive)
scp file.txt xxx.xxx.xx.xxx:/location
receive a file:(add -r for recursive)
scp xxx.xxx.xxx.xxx.xx:/source location/file.txt destination/
scp, send a file:(add -r for recursive)
scp file.txt [email protected]:/location
receive a file:(add -r for recursive)
scp [email protected]:/source location/file.txt destination/