-
Notifications
You must be signed in to change notification settings - Fork 2
/
Commandlines.txt
610 lines (497 loc) · 20.4 KB
/
Commandlines.txt
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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
Create file
-----------------------------------------------------------------------
touch <file>.<ext>
-----------------------------------------------------------------------
Quickly view content of file
-----------------------------------------------------------------------
# read all to terminal
cat <OPTION> <FILE>
# read all then display page by page -> slow for large file
more <OPTION> <FILE>
# read on-the-fly -> fast even for large file
less <OPTION> <FILE>
-----------------------------------------------------------------------
Create directory
-----------------------------------------------------------------------
mkdir -p <path>/<target dir>
-p: self-create parent dir if not existed
-----------------------------------------------------------------------
Remove directory
-----------------------------------------------------------------------
rm -rf <target dir>
-r: recursive
-f: forced
-----------------------------------------------------------------------
Move to directory
-----------------------------------------------------------------------
cd <target dir>
# Move to home
cd
or
cd ~
# Move out
cd ..
# Move back to previous dir
cd -
-----------------------------------------------------------------------
Copy all
-----------------------------------------------------------------------
# Copy all but change owner to current one (forced + recursive)
cp -fr [source] [dest]
or
# Copy all & keep everything as-is (ex: owner, permission...)
cp -a
-----------------------------------------------------------------------
Edit text file
-----------------------------------------------------------------------
sudo vi <file> //if user doesn't have file editing permissions
# For inserting
Press i //Do required editing
# For exiting
Press Esc
:wq //for exiting and saving
:q! //for exiting without saving
-----------------------------------------------------------------------
All about access permission
-----------------------------------------------------------------------
# View access permission:
ls -l --> view long list of contents
# Format:
-rwx---rwx -> divided into 4 parts:
_ -: file(-) or dir(d) or link(l)
_ rwx: owner permissions - read(r) or write(w) or executable(x) or non(-)
_ ---: group
_ rwx: other users
# Change access permission:
_ for owner: chmod <add(+) or remove(-)><w/r/x> <file/dir>
_ for group: chmod g+wrx <file/dir>
_ for others: chmod o+r <file/dir>
_ for all: chmod ugo/a+rx <file/dir>
# Extra: replace <+/-><w/r/x> by below numeric code
0 = ---
1 = --x
2 = -w-
3 = -wx
4 = r--
5 = r-x
6 = rw-
7 = rwx
-> ex: chmod 777 <file/dir> => give wrx permission for all users
# Change owner/group of file/dir:
_ change group: chgrp <group> <file/dir>
_ change owner: chown <user> <file/dir>
_ change both: chown <user>:<group> <file/dir>
# References:
https://help.ubuntu.com/community/FilePermissions
https://www.pluralsight.com/blog/it-ops/linux-file-permissions
-----------------------------------------------------------------------
Make file executable
-----------------------------------------------------------------------
chmod +x <file>
-----------------------------------------------------------------------
Switch between virtual console (tty)
-----------------------------------------------------------------------
sudo chvt x (x = 1 to 6)
# to check tty# & which user is logging in it
who
-----------------------------------------------------------------------
Kill X server = Stop lightdm/gdm/kdm
-----------------------------------------------------------------------
# To stop:
sudo service gdm stop (or use lightdm or kdm instead)
or
sudo systemctl stop gdm
# To start/restart:
sudo service gdm start/restart
or
sudo systemctl start/restart gdm
or
startx
-----------------------------------------------------------------------
To solve error with Nouveau
-----------------------------------------------------------------------
sudo update-initramfs -u
-----------------------------------------------------------------------
Install dkms and build-essential
-----------------------------------------------------------------------
sudo apt-get install build-essential dkms
# Unnecessary for newly installed OS
-----------------------------------------------------------------------
Check for opengl version
-----------------------------------------------------------------------
sudo apt install mesa-utils
glxinfo |
"OpenGL version"
glxinfo | grep '^direct rendering:'
-----------------------------------------------------------------------
Check for installed dkms kernel module
-----------------------------------------------------------------------
dkms status
-----------------------------------------------------------------------
All about gcc
-----------------------------------------------------------------------
Install:
sudo apt-get install gcc-8 g++-8
Having gcc redirected automatically to gcc-8:
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 800 --slave /usr/bin/g++ g++ /usr/bin/g++-8
Set default:
sudo update-alternatives --config gcc
-----------------------------------------------------------------------
Ctrl+C: To stop current jobs (put it to background process)
top: View running processes
htop: Better tool to view running processes
ps -A: list of running processes
jobs: view suspended jobs
Check for gcc version which is used to compile linux kernel
-----------------------------------------------------------------------
cat /proc/version
-----------------------------------------------------------------------
Add PPA launchpad driver
-----------------------------------------------------------------------
sudo add-apt-repository ppa:graphics-drivers/ppa
Remove:
sudo add-apt-repository --remove ppa:graphics-drivers/ppa
-----------------------------------------------------------------------
Check for openCV version
-----------------------------------------------------------------------
pkg-config --modversion opencv
or
/usr/bin/opencv_version
-----------------------------------------------------------------------
Check for ROS version
-----------------------------------------------------------------------
rosversion -d
-----------------------------------------------------------------------
Check for cuda version
-----------------------------------------------------------------------
cat /usr/local/cuda/version.txt
-----------------------------------------------------------------------
Check for nvidia driver version
-----------------------------------------------------------------------
cat /proc/driver/nvidia/version
-----------------------------------------------------------------------
Check for cuda compiler version
-----------------------------------------------------------------------
nvcc --version
-----------------------------------------------------------------------
Check for Python version
-----------------------------------------------------------------------
List installed python:
ls /usr/bin/python*
View version:
For python2:
$ /usr/bin/python -V
OR
/usr/bin/python --version
For python3:
$ /usr/bin/python3 -V
OR
/usr/bin/python3 --version
-----------------------------------------------------------------------
Check for connected camera
-----------------------------------------------------------------------
ls -ltrh /dev/video*
-----------------------------------------------------------------------
Check for USB dev
-----------------------------------------------------------------------
lsusb
or
ls -l /dev | grep ttyUSB ->> used to detect Arduino
-----------------------------------------------------------------------
Add user to group
-----------------------------------------------------------------------
sudo usermod -a -G [group] [user]
then logout & login again for the permission to take effect
-----------------------------------------------------------------------
Check for connected devices with open port 22
-----------------------------------------------------------------------
sudo nmap -sS -p 22 192.168.0.0/24
_ /24: first 24 bits are masked (192.168.0) = subnet 255.255.255.0
_ /16: first 16 bits are masked (192.168) = subnet 255.255.0.0
_ the rest (unmasked) bits is host
-----------------------------------------------------------------------
Check for open port of target devices
-----------------------------------------------------------------------
sudo nmap -sS 192.168.x.x
-----------------------------------------------------------------------
Sync time between different machines
-----------------------------------------------------------------------
Check time different:
ntpdate -q [client ip]
Restart chrony:
service chrony restart
Tracking:
chronyc tracking
View sources list:
chronyc sources -v
Check client list:
sudo chronyc clients
Other:
systemctl enable chronyd.service
systemctl start chronyd.service
-----------------------------------------------------------------------
View system time
-----------------------------------------------------------------------
timedatectl
-----------------------------------------------------------------------
Fix arduino shortcut
-----------------------------------------------------------------------
sudo chown YourUserName /path/to/icon/arduino-arduinoide.desktop
-----------------------------------------------------------------------
Seach for files/dir
-----------------------------------------------------------------------
find <in where>
-type [bcdpfls]: type of target
f: a regular file
d: directory
l: symbolic link
c: character devices
b: block devices
p: named pipe (FIFO)
s: socket
-name <name>: name include <name>
-----------------------------------------------------------------------
List disks/sectors info
-----------------------------------------------------------------------
sudo lsblk -o NAME,FSTYPE,SIZE,MOUNTPOINT,LABEL
sudo fdisk -l </dev/sda>
-----------------------------------------------------------------------
Mount partitions
-----------------------------------------------------------------------
sudo mount /dev/sdb1 /media/SSD
additinal options:
-o rw,norecovery
-----------------------------------------------------------------------
View cmd attached to alias
-----------------------------------------------------------------------
type [alias]
or
alias ->> display all active alias
-----------------------------------------------------------------------
Scan for serial connection
-----------------------------------------------------------------------
dmesg | egrep --color 'serial|ttyS'
-----------------------------------------------------------------------
Bring up wireless devices
-----------------------------------------------------------------------
sudo ifconfig wlan0 up
-----------------------------------------------------------------------
Add network drive/directory
-----------------------------------------------------------------------
sftp://[email protected]/media/nvidia/SSD
-----------------------------------------------------------------------
Install .deb pkg in terminal
-----------------------------------------------------------------------
sudo dpkg --install <pkg.deb>
or
sudo dpkg -i <pkg.deb>
-----------------------------------------------------------------------
Backup disk
-----------------------------------------------------------------------
sudo dd if=/dev/sdb of=~/SDCardBackup.img
-----------------------------------------------------------------------
Change to root user
-----------------------------------------------------------------------
sudo -i
-----------------------------------------------------------------------
Check file system consistency
-----------------------------------------------------------------------
dosfsck /dev/sdb
-----------------------------------------------------------------------
View mainboard info
-----------------------------------------------------------------------
sudo dmidecode -t baseboard
or
sudo dmidecode -t 2
-----------------------------------------------------------------------
Search for apt package
-----------------------------------------------------------------------
apt-cache search <pkg name>*
or
apt-cache policy <pkg name>*
-----------------------------------------------------------------------
Get author description about cmd in terminal
-----------------------------------------------------------------------
man <cmd>
Ex: man sudo
-----------------------------------------------------------------------
Get estimate file space usage
-----------------------------------------------------------------------
du <option> <files>
Ex: du -hd1
-d, –max-depth=N : print total for directory only if it is N or fewer levels below command line argument
-h, –human-readable : print sizes in human readable format
-----------------------------------------------------------------------
pipe output from "this" to input of "that"
-----------------------------------------------------------------------
Use "|"
Ex: du -hd1 | sort -rh | head -10
~ du_stdout =>> sort->sort_stdout =>> head->head_stdout
-----------------------------------------------------------------------
Modify screen resolution
-----------------------------------------------------------------------
Show list of monitors and their connectivity:
xrandr --listmonitors
or
xrandr -> show all connectivities & their available settings
Scale output res by 1.2
xrandr --output eDP-1-1 --transform 1.2,0,0,0,1.2,0,0,0,1
-----------------------------------------------------------------------
Get data from/to server
-----------------------------------------------------------------------
curl <options> <link to server contents>
-----------------------------------------------------------------------
Create symlink
-----------------------------------------------------------------------
ln -s <target/source path> <dest path>
-----------------------------------------------------------------------
View max pipe buffer size
-----------------------------------------------------------------------
cat /proc/sys/fs/pipe-max-size
-----------------------------------------------------------------------
Determine current version of kernel
-----------------------------------------------------------------------
uname -a
uname -r
-----------------------------------------------------------------------
Install the headers for the running kernel
-----------------------------------------------------------------------
sudo apt-get install linux-headers-$(uname -r)
-----------------------------------------------------------------------
View graphic interfaces or check for its error
-----------------------------------------------------------------------
lspci -k | grep VGA
sudo lshw -c video
sudo lshw -C display
lspci |grep -i nvidia
dmesg | grep NVRM
lspci -v -s $(lspci | grep ' VGA ' | cut -d" " -f 1)
-----------------------------------------------------------------------
Get online dir/files
-----------------------------------------------------------------------
wget -r -np -R "index.html*" -P <link to saved dir> <link to taget dir/file>
params:
-P <link to saved dir> or --directory-prefix=<link to saved dir>: save content to target dir
-np or --no-parent: Not recursively download content in parent dir
-R or --reject "index.html*": Reject any file like <that>
-r or --recursive: recursive retreiving
-nH or --no-host-directories: Disable generation of host-prefixed directories
--cut-dirs=<number>: Ignore number directory components (top down)
-l <depth> or --level=depth: Specify recursion maximum depth level depth
-----------------------------------------------------------------------
Compress files/folder
-----------------------------------------------------------------------
# using zip
zip <output name> <files>
zip -r <output name> <folder>
# Using tar
tar -czvf <output name>.tar.gz <files/folder 1> <files/folder 2>
-----------------------------------------------------------------------
Extract compressed file
-----------------------------------------------------------------------
# Extract single file:
tar -xvzf <file>
unzip <file>
# Extract multiple file:
cat *.tar.gz | tar zxvf - -i
unzip \*
# Extract to target dir
unzip <file> -d <target dir>
tar -xvJf <file> -C <target dir>
-----------------------------------------------------------------------
Filter out output list
-----------------------------------------------------------------------
add { | grep <target name>} after command
or
grep -e <target1> -e <target2> -e <target3> for multiple targets
-----------------------------------------------------------------------
Create initial ramdisk images for preloading modules (initrd)
-----------------------------------------------------------------------
dracut
-----------------------------------------------------------------------
Generate ramdisk (initframfs)
-----------------------------------------------------------------------
dracut /boot/initramfs-$(uname -r).img $(uname -r)
-----------------------------------------------------------------------
Rebuild grub
-----------------------------------------------------------------------
sudo grub-mkconfig -o <Output file>[/boot/efi/EFI/centos/grub.cfg]
-----------------------------------------------------------------------
Control all services
-----------------------------------------------------------------------
use systemctl or service
View stats/stop/start/restart/enable/dissable:
sudo systemctl <options> <svc>
-----------------------------------------------------------------------
View users info
-----------------------------------------------------------------------
w
who
users
-----------------------------------------------------------------------
View listening port
-----------------------------------------------------------------------
ss -tulp
netstat -tulpn
-----------------------------------------------------------------------
Fix/Check broken dd image
-----------------------------------------------------------------------
fsck -y /<absolute path to img file>
or
fsck.ext4/exfat/msdos...
-----------------------------------------------------------------------
View deb source repo
-----------------------------------------------------------------------
nano /etc/apt/sources.list
or
ls /etc/apt/sources.list.d/
-----------------------------------------------------------------------
View info (ssid, MAC...) of wireless device
-----------------------------------------------------------------------
iw <dev name (ex: wlan0)> info
-----------------------------------------------------------------------
Log out all current user sessions
-----------------------------------------------------------------------
loginctl terminate-user <User Name>
-----------------------------------------------------------------------
Check for wayland or x11 session is being used
-----------------------------------------------------------------------
loginctl show-session $(loginctl | grep $(whoami) | awk '{print $1}') -p Type
-----------------------------------------------------------------------
Record output to log file
-----------------------------------------------------------------------
<cmd> 2>&1 | tee <log_file>.log
-----------------------------------------------------------------------
View pkgs installing history
-----------------------------------------------------------------------
# View all
grep " install " /var/log/dpkg.log
# View recent installs
awk '$3~/^install$/ {print $4;}' /var/log/dpkg.log
$ View install cmd only (exclude dependencies)
grep " install " /var/log/apt/history.log
-----------------------------------------------------------------------
xargs usages - Repeat cmd with multiple inputs
-----------------------------------------------------------------------
# Move multiple files to other place (in case mv not works: Argument list too long)
ls | xargs mv -t <dest>
# Repeat cmd (ex: <app> <argv 1> <argv 2>
ls | xargs -l <app> <argv 1>
-----------------------------------------------------------------------
List all pci devices
-----------------------------------------------------------------------
lspci -vv
-----------------------------------------------------------------------
Add & remove user
-----------------------------------------------------------------------
sudo adduser <username>
sudo deluser --remove-home <username>
-----------------------------------------------------------------------
View hw specs
-----------------------------------------------------------------------
sudo lshw -short
-----------------------------------------------------------------------
Fully reset git repo
-----------------------------------------------------------------------
git reset --hard && git clean -ffdx
-----------------------------------------------------------------------