Project

General

Profile

Miscellaneous » History » Version 26

Anonymous, 09/24/2024 04:43 PM
adding dropping

1 1
h1. Miscellaneous
2
3 26
h2. Find all files matching regex pattern
4
5
All PNG images starting with 5 digits followed by a dash:
6
<pre>
7
$ find . -regextype posix-extended -regex "\./[[:digit:]]{5}-(.*).png
8
</pre>
9
10 25
h2. Change all file or directory permissions
11
12
<pre>
13
$ find . -type d -exec chmod 755 {} \;
14
$ find . -type f -exec chmod 644 {} \;
15
</pre>
16
17 24
h2. List Root Device
18
19
<pre>
20
$ findmnt -n -o SOURCE /
21
</pre>
22
23
h2. List Block Devices with Serial Numbers
24
25
<pre>
26
$ lsblk --nodeps -o name,serial 
27
</pre>
28
29 23
h2. Useful rsync Examples
30
31
* Synchronize directories (one way):
32
<pre>
33
$ rsync -auhrP --delete --info=del,name,stats2 "/mnt/phalanx/" "/storage"
34
</pre>
35
* Copy with progress:
36
<pre>
37
$ rsync -ahr --info=progress2 some_file.mp4 /storage/
38
</pre>
39
40
41 22
h2. Patch Youtube App using Revanced Manager (6/22/2024)
42
43
h3. Install Steps
44
45
* Delete Revanced app, Micro G, Revanced manager prior installation any of mentioned apps.
46
* Download *but not install* following:
47
** Micro G - https://github.com/ReVanced/GmsCore/releases/tag/v0.3.1.3.240913
48
** Revanced Manager - https://revanced.app/patches?s=Mic
49
** YT App version 19.16.39 (must be this version; revanced manager will warn if not): https://www.apkmirror.com/apk/google-inc/youtube/youtube-19-16-39-release/youtube-19-16-39-android-apk-download/
50
* Install Micro G.
51
* Next install Revanced Manager
52
* Open Revanced manager
53
** Go to Patches
54
** Select an app
55
** Bottom right corner choose Storage
56
** Find YT APK you downloaded, select patch on the bottom right corner
57
* Wait for patch and compile to finish, then choose install app
58
* Open it, check if its Vanced, restart the phone.
59
* If you have stock YT app, uninstall updates and disable it
60
61
Source: https://www.reddit.com/r/revancedapp/comments/1bq92r7/me_rn_trying_to_patch_youtube_revanced/
62
63 19
h2. Combine find and GNU parallel
64
65
Example:
66
<pre>
67
$ find . -name '*.jpg' | parallel convert -geometry 120 {} {.}_thumb.jpg
68 21
$ find . -name '*.png' | parallel --eta convert '{}' -quality 90 '{.}.jpg'
69
$ find . -name '*.png' -delete
70 19
</pre>
71
Note @{.}@ is the filename without the @.jpg@ portion.
72
73
* See: https://www.gnu.org/software/parallel/parallel_examples.html#example-compute-intensive-jobs-and-substitution
74
75 18
h2. Setup ttyd
76
77
* Download @ttyd@ and put it in @/opt/local/bin/ttyd@:
78
** https://github.com/tsl0922/ttyd/releases
79
* Create systemd service file @/etc/systemd/system/ttyd.service@: 
80
<pre>
81
[Unit]                                                                                                                                                                                           
82
Description=TTYD
83
After=syslog.target
84
After=network.target
85
 
86
[Service]
87
ExecStart=/opt/local/bin/ttyd -W -p 9772 login
88
Type=simple
89
Restart=always
90
User=root
91
Group=root
92
 
93
[Install]
94
WantedBy=multi-user.target
95
</pre>
96
** Start and enable service:
97
<pre>
98
$ sudo systemctl start ttyd && sudo systemctl enable ttyd
99
</pre>
100
* Setup apache configuration (add to existing)
101
<pre>
102
        ProxyRequests Off
103
        ProxyPreserveHost On
104
        RewriteEngine on
105
        RewriteCond %{HTTP:Upgrade} websocket [NC]
106
        RewriteCond %{HTTP:Connection} upgrade [NC]
107
        RewriteRule /terminal/?(.*) "ws://localhost:9772/$1" [P,L]
108
        ProxyPass /terminal http://localhost:9772/
109
        ProxyPassReverse /terminal http://localhost:9772/
110
</pre>
111
** Enable necessary apache modules:
112
<pre>
113
$ a2enmod proxy proxy_http proxy_wstunnel mod_rewrite
114
</pre>
115
116
117 17
h2. Increase tmux scrollback
118
119
<pre>
120
$ cd 
121
$ echo "set -g history-limit 9999999" >> ~/.tmux.conf
122
</pre>
123
124 16
h2. Setup VNC
125 15
126
On the server side:
127
# Install @x11vnc@:
128
<pre>
129
$ sudo apt install x11vnc net-tools
130
</pre>
131
# Set VNC password:
132
<pre>
133
$ x11vnc -storepasswd
134
</pre>
135
# Start VNC service from command line:
136
<pre>
137
$ sudo x11vnc -auth guess -forever -loop -noxdamage -repeat -rfbauth /home/dsorber/.vnc/passwd -rfbport 5900 -shared
138
</pre>
139
# To start at boot using systemd service create: @/etc/systemd/system/x11vnc.service@:
140
<pre>
141
[Unit]
142
Description=x11vnc remote desktop server
143
After=multi-user.target
144
145
[Service]
146
Type=simple
147
ExecStart=/usr/bin/x11vnc -auth guess -forever -loop -noxdamage -repeat -rfbauth /home/dsorber/.vnc/passwd -rfbport 5900 -shared
148
149
Restart=on-failure
150
151
[Install]
152
WantedBy=multi-user.target
153
</pre>
154
155
On the client side:
156
# Install @remmina@:
157
<pre>
158
$ sudo apt install remmina
159
</pre>
160
# Open @remmina@, select "VNC", and type in the server's IP address.
161
162
* Source: https://forums.linuxmint.com/viewtopic.php?t=369092
163
164 14
h2. sshuttle
165 15
166
Poor man's VPN:
167 14
168
<pre>
169
$ sshuttle --dns -NHr dsorber@phalanx.homelinuxserver.org:3268  192.168.0.0/16
170
</pre>
171
172 13
h2. Batch Convert PNG to JPG
173
174
NOTE: @convert@ comes from ImageMagick
175
<pre>
176
& ls -1 *.png | parallel --eta convert '{}' -quality 90 '{.}.jpg'
177
</pre>
178
179 12
h2. Crop Video with ffmpeg
180
181
<pre>
182
$ ffmpeg -i in.mp4 -filter:v "crop=out_w:out_h:x:y" out.mp4
183
</pre>
184
185
* @out_w@ is the width of the output rectangle
186
* @out_h@ is the height of the output rectangle
187
* @x@ and @y@ specify the top left corner of the output rectangle (coordinates start at (0,0) in the top left corner of the input) 
188
189
Test using @ffplay@:
190
<pre>
191
$ ffplay -i input -vf "crop=out_w:out_h:x:y"
192
</pre>
193
194 10
h2. Build Custom Windows ISOs
195
196
* https://uupdump.net/
197 11
* https://forums.mydigitallife.net/threads/kms_vl_all-smart-activation-script.79535/
198 10
199 9
h2. Script to Convert Local manpages to html
200
201
Note use @zcat@ if the manpages are compressed:
202
203
<pre>
204
#!/bin/bash
205
206
mkdir -p html
207
for file in *; do
208
        if [ -f $file ] && [ "${file: -3}" != ".sh" ]; then
209
                echo $file
210
                #echo "${file%.*}"
211
                pandoc --from man --to html < $file > html/${file%.*}.html
212
        fi
213
done
214
</pre>
215
216 6
h2. Display Total rsync Progress
217
218
<pre>
219 7
$ rsync -a --no-i-r --info=progress2 /path/to/src /path/to/dest/
220 6
</pre>
221
222
NOTE: @-v@ does not work with @--info=progress2@
223
224
Source: https://serverfault.com/a/441724/472586
225
226 5
h2. Slice Video File 
227
228
<pre>
229
$ ffmpeg -ss 00:01:00 -to 00:02:00  -i input.mp4 -c copy output.mp4
230
</pre>
231
232
Explanation of the command:
233
234
* -i: This specifies the input file. In that case, it is (input.mp4).
235
* -ss: Used with -i, this seeks in the input file (input.mp4) to position.
236
* 00:01:00: This is the time your trimmed video will start with.
237
* -to: This specifies duration from start (00:01:40) to end (00:02:12).
238
* 00:02:00: This is the time your trimmed video will end with.
239
* -c copy: This is an option to trim via stream copy. (NB: Very fast)
240
241 4
h2. Add new drive SW RAID5
242
243
# Format drive if needed (see below for steps).
244
# Add new drive to SW RAID:
245
<pre>
246
$ sudo mdadm --manage /dev/md0 --add /dev/sdd1
247
</pre>
248
# Grow array:
249
<pre>
250
$ sudo mdadm --grow --raid-devices=4 /dev/md0
251
</pre>
252
253
h2. Replace failed SW RAID drive
254
255
# If drive is brand new be sure to create a partition on it:
256
<pre>
257
sorber@file2:~$ sudo parted /dev/sdg
258
GNU Parted 3.3
259
Using /dev/sdg
260
Welcome to GNU Parted! Type 'help' to view a list of commands.
261
(parted) mklabel gpt
262
(parted) mkpart primary 2048s 100%                                        
263
(parted) print                                                            
264
Model: ATA ST2000DM008-2FR1 (scsi)
265
Disk /dev/sdg: 2000GB
266
Sector size (logical/physical): 512B/4096B
267
Partition Table: gpt
268
Disk Flags: 
269
270
Number  Start   End     Size    File system  Name     Flags
271
 1      1049kB  2000GB  2000GB               primary
272
273
(parted) quit
274
</pre>
275
# If needed, mark bad drive as failed:
276
<pre>
277
$ sudo mdadm --manage /dev/md0 --fail /dev/sdd
278
</pre>
279
# Add new drive to replace failed:
280
<pre>
281
$ sudo mdadm --manage /dev/md0 --add /dev/sdd1 /dev/sdg1
282
</pre>
283
# Improve rebuild speed slightly:
284
<pre>
285
$ sudo bash -c "echo 9999999 > /proc/sys/dev/raid/speed_limit_min"
286
$ sudo bash -c "echo 9999999 > /proc/sys/dev/raid/speed_limit_max"
287
</pre>
288
# Monitor rebuild:
289
<pre>
290
$ watch -n1 cat /proc/mdstat 
291
</pre>
292
293
h2. Get detailed drive information
294
295
<pre>
296
$ udevadm info --query=all --name=/dev/sda
297
</pre>
298
299 1
h2. Split flac with cue
300
301
<pre>
302
$ sudo apt install cuetools shntool
303
304
$ shnsplit -f file.cue -t %n-%t -o flac file.flac
305
</pre>
306
307
h2. Fix Chrome Display Glitches
308
309
Somewhere around Chrome 86 display glitches started happening on wake. Here is how to fix:
310
311 3
Enabling @enable-vulkan@ in @chrome://flags@ then restarting the browser fixed it. If that does not work, you can also try enabling `ignore-gpu-blacklist` as well.
312 1
313
h2. Setup SSH Public Key
314
315
# On host machine generate a key pair. This key can be reused for multiple remote machines so it's not really necessary to change the name unless multiple keys are generated, which is also not really needed.
316
<pre>
317
$ ssh-keygen -t rsa
318
</pre>
319 3
 *NOTE:* for NetBeans to use/recognize the ssh key you must use the old PEM format:
320 1
<pre>
321
$ ssh-keygen -m PEM -t rsa
322
</pre>
323
# Now use `ssh-copy-id` to copy the key to the remote machine (for example):
324
<pre>
325
$ ssh-copy-id -i ~/.ssh/phalanx_rsa.pub dsorber@phalanx
326
</pre>
327
328
h2. Read Windows Product Key from ACPI Firmware
329
330
Boot into Linux and run:
331
332
<pre>
333
$ sudo strings /sys/firmware/acpi/tables/MSDM
334
</pre>
335
336
h2. Windows 10 Install and SysPrep Instructions
337
338
Very good instructions: https://theitbros.com/sysprep-windows-10-machine-guide/
339
340
341
h2. Search and Replace on Binary Files
342
343
A good hex editor can do search and replace on binary files but sometimes that's not practical:
344
345
* BBE - https://sourceforge.net/projects/bbe-/
346
 BBE is a binary editor with SED-like syntax:
347
<pre>
348
$ bbe -e 's/\x0a\x0d\x0a/\x0d\x0a/' infile > outfile
349
</pre>
350
* binwalk - https://github.com/ReFirmLabs/binwalk
351
 binwalk can search for hex strings (and do many other things)
352
<pre>
353
$ binwalk -R "\x0a\x0d\x0a" infile
354
355
WARNING: Signature '0    string    \x0a\x0d\x0a    Raw signature (\x0a\x0d\x0a)' is a self-overlapping signature!
356
357
DECIMAL       HEXADECIMAL     DESCRIPTION
358
--------------------------------------------------------------------------------
359
242           0xF2            Raw signature (\x0a\x0d\x0a)
360
412           0x19C           Raw signature (\x0a\x0d\x0a)
361
580           0x244           Raw signature (\x0a\x0d\x0a)
362
749           0x2ED           Raw signature (\x0a\x0d\x0a)
363
. . .
364
</pre>
365
366
h2. Wake-on-LAN WOL
367
368
Must be enabled on interface; need MAC
369
<pre>
370
$ sudo apt install etherwake
371
$ sudo etherwake <target MAC> -i <outgoing interface>
372
373
$ sudo etherwake b4:2e:99:a5:1e:f0 -i enp30s0
374
</pre>
375
376
h2. Allocator Shim
377
378
From Chromium, this is really interesting
379
* https://chromium.googlesource.com/chromium/src/base/+/master/allocator/README.md
380
381
However it is not clear how to use it outside of Chromium.
382
383
h2. Update Geany
384
385
# Install prereq packages (this obviously only needs to be done once):
386
<pre>
387
$ sudo apt install libgtk-3-dev libgtkspell-dev libgtkspell3-3-dev
388
</pre>
389
# Set compile flags:
390
<pre>
391
$ export CFLAGS="-O3 -march=native" 
392
$ export CXXFLAGS=$CFLAGS
393
</pre>
394
# Build geany and set to install in /opt so it won't collide with the packaged version:
395
<pre>
396
$ tar xf geany-1.30.tar.bz2
397
$ cd geany-1.30/
398
$ ./configure --prefix=/opt/local --enable-gtk3
399
$ make -j20
400
$ sudo make install
401
</pre>
402
# Set PKG_CONFIG_PATH environment variable so we can build the plugins.
403
<pre>
404
$ export PKG_CONFIG_PATH=/opt/local/lib/pkgconfig/
405
</pre>
406
# Build geany-plugins:
407
<pre>
408
$ tar xf geany-plugins-1.30.tar.bz2 
409
$ cd geany-plugins-1.30/
410
$ ./configure --prefix=/opt/local --enable-gtk3
411
$ make -j20
412
$ sudo make install
413
</pre>
414
415
h2. Find and replace across multiple files
416
417
<pre>
418
$ find /home/www -type f -print0 | xargs -0 sed -i 's/subdomainA\.example\.com/subdomainB.example.com/g'
419
</pre>
420
421
h2. Useful IPMI commands
422
423
424
Power measurement on the SuperMicro (probably won't work on Dell chassis as they have some proprietary version of ipmi):
425
426
<pre>
427
sudo ipmitool -U ADMIN -P ADMIN -H 10.17.136.108 dcmi power reading
428
</pre>
429
430
Check power status (i.e. on/off) of chassis:
431
<pre>
432
sudo ipmitool -U ADMIN -P ADMIN -H 10.17.70.45 power status
433
sudo ipmitool -U ADMIN -P ADMIN -H 10.17.70.45 power off
434
</pre>
435
436
Get IPMI IP address (look for "IP Address"):
437
<pre>
438
sudo ipmitool lan print 
439
</pre>
440
441
h2. Full sshfs Connect Command
442
443
<pre>
444
sudo sshfs -o idmap=user -o uid=$(id -u) -o gid=$(id -g) -o allow_other -o follow_symlinks ryftuser@sm-X11DGQ:/home/ryftuser /mnt/sm-X11DGQ/
445
</pre>
446
447
h2. Side-by-side Color Diff
448
449
<pre>
450
$ sudo apt-get install colordiff
451
$ colordiff -y --suppress-common-lines data.txt /ryftone/data.txt
452
</pre>
453
454
h2. x86 ABI
455
456
* https://github.com/hjl-tools/x86-psABI/wiki/X86-psABI
457
458
h2. clang-format and clang-tidy
459
460
* http://www.labri.fr/perso/fleury/posts/programming/using-clang-tidy-and-clang-format.html
461
462
h2. Shared Library and Related Resources
463
464
* http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html
465
* https://blog.qt.io/blog/2011/10/28/rpath-and-runpath/
466
* http://www.bnikolic.co.uk/blog/linux-ld-debug.html
467
* http://insanecoding.blogspot.com/2012/07/creating-portable-linux-binaries.html
468
* https://stackoverflow.com/questions/4156055/static-linking-only-some-libraries
469
470
h2. Ubuntu: List Grub Entries
471
472
<pre>
473
gawk  'BEGIN {                                                                                                                       
474
  l=0                                                                                                                                
475
  menuindex= 0                                                                                                                       
476
  stack[t=0] = 0                                                                                                                     
477
}                                                                                                                                    
478
479
function push(x) { stack[t++] = x }                                                                                                  
480
481
function pop() { if (t > 0) { return stack[--t] } else { return "" }  }                                                              
482
483
{                                                                                                                                    
484
485
if( $0 ~ /.*menu.*{.*/ )                                                                                                             
486
{                                                                                                                                    
487
  push( $0 )                                                                                                                         
488
  l++;                                                                                                                               
489
490
} else if( $0 ~ /.*{.*/ )                                                                                                            
491
{                                                                                                                                    
492
  push( $0 )                                                                                                                         
493
494
} else if( $0 ~ /.*}.*/ )                                                                                                            
495
{                                                                                                                                    
496
  X = pop()                                                                                                                          
497
  if( X ~ /.*menu.*{.*/ )                                                                                                            
498
  {                                                                                                                                  
499
     l--;                                                                                                                            
500
     match( X, /^[^'\'']*'\''([^'\'']*)'\''.*$/, arr )                                                                               
501
502
     if( l == 0 )                                                                                                                    
503
     {                                                                                                                               
504
       print menuindex ": " arr[1]                                                                                                   
505
       menuindex++                                                                                                                   
506
       submenu=0                                                                                                                     
507
     } else                                                                                                                          
508
     {                                                                                                                               
509
       print "  " (menuindex-1) ">" submenu " " arr[1]                                                                               
510
       submenu++                                                                                                                     
511
     }                                                                                                                               
512
  }                                                                                                                                  
513
}                                                                                                                                    
514
515
}' /boot/grub/grub.cfg
516
</pre>
517
518
* https://askubuntu.com/a/941993/392271
519
520
521
h2.GCC Disable Unused Variable Warnings
522
523
<pre>
524
#pragma GCC diagnostic push
525
#pragma GCC diagnostic ignored "-Wunused-variable"
526
( your problematic library includes )
527
#pragma GCC diagnostic pop
528
</pre>
529
530
See: https://stackoverflow.com/a/22708539/73878
531
532
h2. Fix Steam after NVidia driver update
533
534
Since this has now bitten me twice... Steam requires the 32 bit version of the GL library.
535
536
<pre>
537
$ sudo apt install libnvidia-gl-418:i386
538
</pre>
539
540
h2. Restart Cinnamon from TTY
541
542
# Cinnamon freezes
543
# Switch tty. I usually go to tty6, `Ctrl+Alt+F6`
544
# If you need to login first, do so.
545
# Type `w` (yes, just the letter) and press enter. This commands does a lot of different things, but you need it to figure out the number of the display you are using. The display number is in the column FROM. Mine is `:0` (yes, including the colon).
546
# Assuming that cinnamon is already dead (which you would notice by the windows lacking titles and that you can't move different windows around, and perhaps even not being able to use the keyboard), you type `export DISPLAY=:0; cinnamon &`, and don't forget the colon. I add the ampersand (&) only not to keep that tty busy.
547
548
Sauce: https://askubuntu.com/a/198935/392271
549
550
h2. Ubuntu Set Specific Kernel to Boot
551
552
* Use this command to get a list of available options:
553
<pre>
554
$ grep -Ei 'submenu|menuentry ' /boot/grub/grub.cfg | sed -re "s/(.? )'([^']+)'.*/\1 \2/"
555
menuentry  Ubuntu
556
submenu  Advanced options for Ubuntu
557
    menuentry  Ubuntu, with Linux 4.4.0-34-generic
558
    menuentry  Ubuntu, with Linux 4.4.0-34-generic (upstart)
559
    menuentry  Ubuntu, with Linux 4.4.0-34-generic (recovery mode)
560
menuentry  System setup
561
</pre>
562
* Backup grub configuration, just in case:
563
<pre>
564
$ sudo cp /etc/default/grub /etc/default/grub.bak
565
</pre>
566
* Edit grub configuration and change `GRUB_DEFAULT` to something like this:
567
<pre>
568
$ sudo vim /etc/default/grub
569
570
GRUB_DEFAULT="Advanced options for Ubuntu>Ubuntu, with Linux 3.13.0-53-generic"
571
</pre>
572
* Update grub configuration
573
<pre>
574
$ sudo update-grub
575
</pre>
576
* See also: https://askubuntu.com/questions/216398/set-older-kernel-as-default-grub-entry
577
578
h2. Ubuntu Networking Resources
579
580
* https://blog.ubuntu.com/2017/12/01/ubuntu-bionic-netplan
581
* https://help.ubuntu.com/lts/serverguide/network-configuration.html.en
582
* https://netplan.io/
583
584
h2. Win10 Licensing Info
585
586
* https://www.windowscentral.com/how-change-product-key-windows-10
587
* https://www.tenforums.com/tutorials/49586-determine-if-windows-license-type-oem-retail-volume.html
588
* https://www.tenforums.com/windows-updates-activation/104569-win-10-activation-expiring-volume-license.html
589
590
h2. Python GTK Development Resources
591
592
* https://python-gtk-3-tutorial.readthedocs.io/en/latest/layout.html
593
* https://lazka.github.io/pgi-docs/Gtk-3.0/classes/Box.html#Gtk.Box.pack_start
594
* https://lazka.github.io/pgi-docs/Gtk-3.0/mapping.html
595
596
h2. cpufrequtils Governor Configuration
597
598
These instructions are intended for Ubuntu 16.04 and later (using systemd init).
599
600
* Check the available and currently set governors. Ubuntu has an โ€œondemandโ€ service that sets the governor to ondemand after boot.
601
<pre>
602
$ cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors
603
conservative ondemand userspace powersave performance schedutil
604
$ cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor 
605
ondemand
606
</pre>
607
608
* Configure cpufrequtils to set the governor to performance at boot
609
<pre>
610
$ echo 'GOVERNOR="performance"' | sudo tee /etc/default/cpufrequtils
611
GOVERNOR="performance"
612
</pre>
613
614
* Disable the automatic ondemand service. 
615
<pre>
616
$ sudo systemctl disable ondemand
617
</pre>
618
619
* Reboot.
620
621
* Now check that the governor is set to performance for every CPU:
622
<pre>
623
$ cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
624
performance
625
performance
626
performance
627
performance
628
โ€ฆ
629
performance
630
performance
631
performance
632
</pre>
633
634
* Check current CPU speeds:
635
<pre>
636
$ watch -n 1 bash -c 'cpufreq-info | grep "current CPU frequency"'
637
</pre>
638
639
h2. rsync via ssh example
640
641
<pre>
642
$ rsync --info=progress2 -ahz --compress-level=9 -e "ssh -i ~/ryft-pat-f1.pem" data/ ryftuser@18.205.65.5:/ryftone/regression/pubmed/data/
643
</pre>
644
645
h2. Read Performance using AIO
646
647
Use this fio command (run from temp directory on disk in question) to measure max disk read performance:
648
649
<pre>
650
$ fio --name TEST --eta-newline=5s --filename=fio-tempfile.dat --rw=read --size=10g --io_size=10g --blocksize=512k --ioengine=libaio --fsync=0 --iodepth=32 --direct=1 --numjobs=1 --runtime=300 --group_reporting
651
</pre>
652
653
Note that DIRECT_IO is required when using AIO. (see also: https://askubuntu.com/a/991311/392271)
654
655
h2. Remove Source Files While Creating Tarball
656
657
This is handy as it saves on disk space.
658
<pre>
659
$ tar --remove-files -cf pictures.tar Pictures/
660
</pre>
661
662
h2. Linux Find and Remove Files
663
664
Find and remove files (even with spaces in the path) using case insensitive matching for the wildcard:
665
<pre>
666
$ find . -type f -iname "*.jpg" -print0 | xargs -0 rm
667
</pre>
668
669
h2. Convert ASCII hex to binary
670
This problem seems to come up every so often. There is no need for a one-off solution:
671
672
<pre>
673
$ xxd -r -p input.txt output.bin
674
</pre>
675
676
https://stackoverflow.com/questions/7826526/transform-a-hex-info-to-binary-using-linux-command
677
678
h2. Well Said
679
680
https://developers.slashdot.org/comments.pl?sid=12326098&cid=56908942
681
682
h2. Hex Editor
683
684
I had been using [[https://hexinator.com/|Hexinator]] but I've had some minor issues with it. Today I tried [[https://www.wxhexeditor.org/home.php|wxHexEditor]] and I was pleasantly surprised.
685
686
Download from here: https://github.com/EUA/wxHexEditor
687
688
You'll need the latest version of libwxgtk<version>-dev package.
689
690
I had some minor issues with the build (which seems a somewhat bizarre arrangement...) modify the makefile to set `CC` and `CXX` directly, right about line 90.
691
692
Finally, to get it installed in the right place:
693
<pre>
694
sudo make install DESTDIR=/opt/local BINDIR=bin DATADIR=share
695
</pre>
696
697
h2. Preprocessor Fun
698
699
To invoke the preprocessor directly:
700
<pre>
701
gcc -E -DSOME_DEFINE=SOME_VALUE somefile.c 
702
</pre>
703
704
See also [[https://linux.die.net/man/1/unifdef|unifdef]]: "The unifdef utility acts on #if, #ifdef, #ifndef, #elif, #else, and #endif lines, and it understands only the commonly-used subset of the expression syntax for #if and #elif lines."
705
706
h2. Convert Oversampled .flac to 16 bit 44.1 khz .flac
707
708
<pre>
709
mkdir -p output && find . -type f -name "*.flac" | parallel -j16 "sox {} -b 16 -r 44100 output/{/.}.flac"
710
711
mkdir -p output && find . -type f -name "*.flac" | parallel -j16 "sox -v 0.98 {} -b 16 -r 44100 output/{/.}.flac"
712
</pre>
713
714
h2. Aligned C++ STL Types
715
716
<pre>
717
#include <vector>
718
#include <boost/align/aligned_allocator.hpp>
719
720
template <typename T>
721
using aligned_vector = std::vector<T, boost::alignment::aligned_allocator<T, 4096>>;
722
</pre>
723
724
h2. Command line convert .png to .jpg
725
726
<pre>
727
$ for x in *.png; do convert $x $(basename $x .png).jpg; done
728
</pre>
729
730
You can also add the "`-quality 90`" option if needed.
731
732
h2. Determine CPU Family Name
733
734
<pre>
735
$ gcc -march=native -Q --help=target|grep march
736
</pre>
737
738
h2. Convert .flac to .m4a (AAC)
739
740
Requires `ffmpeg` built with libfdk_aac:
741
742
<pre>
743
$ /opt/bin/ffmpeg -i input.flac -vn -c:a libfdk_aac -vbr 3 output.m4a
744
</pre>
745
746
All together using `find` and `parallel` for magic:
747
<pre>
748
$ find . -type f -name "*.flac" | parallel -j16 "/opt/bin/ffmpeg -i {} -vn -c:a libfdk_aac -vbr 4 {/.}.m4a"
749
</pre>
750
751
h2. PyGObject
752
753
This is the magic needed to have stuff happen quasi asynchronously using PyGObject (GTK+):
754
755
<pre>
756
# Yield to the main loop temporarily
757
while Gtk.events_pending():
758
    Gtk.main_iteration()
759
</pre>
760
761
h2. FUSE Code
762
763
 *https://pastebin.com/wavKntiu
764
765
h2. Use Windoze Schtuffs
766
767
 * https://support.microsoft.com/en-gb/help/17588/fix-problems-that-block-programs-from-being-installed-or-removed (gotta love how this requires a separate program)
768
 * [[http://landinghub.visualstudio.com/visual-cpp-build-tools|MSVC Tools]] - compiler (seems to be the rough equivalent of `build-essential`)
769
 * [[https://docs.microsoft.com/en-us/sysinternals/downloads/procmon|Process Monitor]] - useful debug tool
770
  * https://www.codeproject.com/Articles/560816/Troubleshooting-dependency-resolution-problems-usi - example for using Process Monitor
771
 * http://download.microsoft.com/download/7/2/E/72E0F986-D247-4289-B9DC-C4FB07374894/wdexpress_full.exe - (required by wingtk below)
772
 
773
* https://github.com/wingtk/gvsbuild - haven't tried this yet but looks amazing... 
774
775
h2. Build Handbrake Git Build
776
777
Steps for building Handbrake using AOCC:
778
779
<pre>
780
$ source /home/dsorber/Downloads/aocc/setenv_AOCC.sh
781
$ export CC=clang
782
$ export CXX=clang++
783
$ export CFLAGS="-g -O3 -mtune=native"
784
$ export CXXFLAGS=$CFLAGS
785
$ cd ~/Downloads/HandBrake/
786
$ rm -rf build/
787
$ ./configure --prefix=/opt --enable-x265 --enable-fdk-aac --gcc=/home/dsorber/Downloads/aocc/AOCC-1.1-Compiler/bin/clang
788
$ cd build
789
$ make -j17
790
$ sudo make install
791
</pre>
792
793
----
794
795
Regular build (18.04 and later):
796
<pre>
797
$ rm -rf build/
798
$ ./configure --prefix=/opt/local --enable-x265 --enable-fdk-aac
799
$ cd build
800
$ make -j17
801
$ sudo make install
802
</pre>
803
804
h2. Politically Correct Linux
805
806
* https://entertainment.slashdot.org/comments.pl?sid=11493671&cid=55759997
807
808
h2. This guy gets it
809
810
Regarding software purist ideology vs pragmatism
811
812
* https://linux.slashdot.org/comments.pl?sid=11156367&cid=55256437
813
814
h2. "Rotate" Video Playback via Metadata
815
816
<pre>
817
$ ffmpeg -i input.mp4 -c copy -metadata:s:v:0 rotate=90 output.mp4
818
</pre>
819
820
821
h2. Ubuntu Remove Old Kernels Oneliner
822
823
<pre>
824
$ sudo apt-get purge $(for tag in "linux-image" "linux-headers"; do dpkg-query -W -f'${Package}\n' "$tag-[0-9]*.[0-9]*.[0-9]*" | sort -V | awk 'index($0,c){exit} //' c=$(uname -r | cut -d- -f1,2); done)
825
</pre>
826
827
* [[https://askubuntu.com/questions/2793/how-do-i-remove-old-kernel-versions-to-clean-up-the-boot-menu/571360#571360|Sauce]]
828
829
h2. Remove New Lines (command line)
830
831
For a file:
832
<pre>
833
$ tr -d '\n' < yourfile.txt
834
</pre>
835
836
Or for output of a command (e.g.):
837
<pre>
838
$ find . -type f -name '*.txt' | tr -d '\n'
839
</pre>
840
841
h2. Convert from .mp4 to .mkv Container
842
843
Use `avconv` to convert container without re-encoding:
844
<pre>
845
$ sudo apt-get install libav-tools
846
847
$ avconv -i filme.mp4 -c copy filme.mkv
848
</pre>
849
850
h2. Remove String From Many File Names
851
852
On Ubuntu use Perl rename utility, e.g.:
853
854
<pre>
855
$ rename 's/ \(1920x1080\) \[WaifuKenny\]//' *.mp4
856
</pre>
857
858
h2. Change Default Text Editor
859
860
I always have to Google this...
861
862
<pre>
863
$ sudo update-alternatives --config editor
864
</pre>
865
866
h2. Linux View System RAM Speed
867
868
View RAM speed (actual) on Debian/Ubuntu/Mint:
869
870
<pre>
871
$ sudo lshw -short -C memory
872
H/W path                      Device      Class          Description
873
====================================================================
874
/0/0                                      memory         64KiB BIOS
875
/0/b                                      memory         32GiB System Memory
876
/0/b/0                                    memory         [empty]
877
/0/b/1                                    memory         16GiB DIMM Synchronous 2134 MHz (0.5 ns)
878
/0/b/2                                    memory         [empty]
879
/0/b/3                                    memory         16GiB DIMM Synchronous 2134 MHz (0.5 ns)
880
/0/d                                      memory         768KiB L1 cache
881
/0/e                                      memory         4MiB L2 cache
882
/0/f                                      memory         16MiB L3 cache
883
</pre>
884
885
h2. Linux Memory Schtuff
886
887
* [[https://github.com/jbert/exmap|exmap]]
888
* https://jameshunt.us/writings/smaps.html
889
* https://techtalk.intersec.com/2013/07/memory-part-2-understanding-process-memory/
890
* http://bmaurer.blogspot.com/2006/03/memory-usage-with-smaps.html
891
892
* https://github.com/torvalds/linux/blob/master/Documentation/filesystems/proc.txt
893
894
* From: http://stackoverflow.com/questions/24484481/entry-in-proc-meminfo
895
<pre>
896
  2. Active(file), Inactive(file) has file back-end which means its original file is in disk but to use it faster it was loaded on RAM.
897
</pre>
898
899
900
* From: http://unix.stackexchange.com/questions/56879/tracking-down-missing-memory-usage-in-linux
901
902
  The "memory used by a process" is not a clear cut concept in modern operating systems. What can be measured is the size of the address space of the process (SIZE) and resident set size (RSS, how many of the pages in the address space are currently in memory). Part of RSS is shared (most processes in memory share one copy of glibc, and so for assorted other shared libraries; several processes running the same executable share it, processes forked share read-only data and possibly a chunk of not-yet-modified read-write data with the parent). On the other hand, memory used for the process by the kernel isn't accounted for, like page tables, kernel buffers, and kernel stack. In the overall picture you have to account for the memory reserved for the graphics card, the kernel's use, and assorted "holes" reserved for DOS and other prehistoric systems (that isn't much, anyway).
903
904
  The only way of getting an overall picture is what the kernel reports as such. Adding up numbers with unknown overlaps and unknown left outs is a nice exercise in arithmetic, nothing more.
905
906
 * [[http://virtualthreads.blogspot.com/2006/02/understanding-memory-usage-on-linux.html|Understanding memory usage on Linux]]
907
908
 * https://linux-mm.org/LinuxMM
909
910
h2. Reinstall grub on UEFI System
911
912
Reinstalling grub on a UEFI system is slightly different than on a traditional legacy BIOS system:
913
914
<pre>
915
# Mount the primary drive root partition and the boot EFI partition
916
sudo mount /dev/sda# /mnt            # Mount root (/) partition
917
sudo mount /dev/sda# /mnt/boot       # Mount boot (/boot) partition (if separate from root partition; typically not)
918
919
sudo mkdir -p /mnt/boot/efi          # Create EFI partition mount point
920
sudo mount /dev/sda1 /mnt/boot/efi   # Mount EFI partition
921
922
# Mount your virtual filesystems:
923
for i in /dev /dev/pts /proc /sys /run; do sudo mount -B $i /mnt$i; done
924
925
# Chroot
926
sudo chroot /mnt
927
</pre>
928
929
Now, if you have networking you'll need DNS. If using `resolvconf` (for recent versions of Ubuntu):
930
931
# Edit ` /etc/resolvconf/resolv.conf.d/head` and add the following line (OpenDNS server).  Then save and exit:
932
<pre>
933
add nameserver 208.67.222.222
934
</pre>
935
# Next enable updates and update:
936
<pre>
937
sudo resolvconf --enable-updates
938
sudo resolvconf -u
939
</pre>
940
# Now you should have DNS. Test by pinging something.
941
942
Finally, back to fixing grub. Note that the grub install should run smoothly with no errors or warnings. If you see any something is probably wrong.
943
<pre>
944
apt-get install grub-efi-amd64  # Install grub EFI bootloader (this should be all you need to do)
945
946
947
# manual steps if you need them for some reason
948
grub-install --recheck --no-floppy --force /dev/sda1  # Install grub bootloader in EFI partition
949
950
#####
951
echo "configfile (hd0,gpt#)/boot/grub.cfg" > /boot/efi/ubuntu/grub.cfg # Tell grub to load grub.cfg from /boot
952
953
update-grub                          # Create grub menu list
954
#####
955
956
exit                                 # Exit chroot
957
</pre>
958
959
Reboot and you should be back in business.
960
961
h2. Convert flac to VBR mp3 using ffmpeg/lame
962
963
<pre>
964
for file in *.flac; do name=$(echo $file | sed "s/\.flac//g"); ffmpeg -i "$file" -codec:a libmp3lame -qscale:a 0 "$name".mp3; done
965
</pre>
966
967
h2. Create UEFI/legacy BIOS Bootable ISO
968
969
* http://askubuntu.com/questions/625286/how-to-create-uefi-bootable-iso
970
971
h2. Getting rEFInd to work on Mac OS 10.11
972
973
* http://mattjanik.ca/blog/2015/10/01/refind-on-el-capitan/
974
975
h2. Convert DTS 5.1 to FLAC
976
977
<pre>
978
sudo apt-get install libdca-utils ffmpeg sound-juicer gnome-terminal easytag vlc 
979
980
for file in *.wav; do name=$(echo $file | sed "s/\.wav//g"); dcadec -o wavall "$file" > "$name"_decoded.wav; ffmpeg -i "$name"_decoded.wav "$name".flac; rm -f "$file" "$name"_decoded.wav; done
981
</pre>
982
983
Source: http://ubuntuforums.org/archive/index.php/t-1849260.html
984
985
h2. Windows Utils
986
987
* http://windirstat.info/download.html
988
* https://www.raymond.cc/blog/safely-delete-unused-msi-and-mst-files-from-windows-installer-folder/
989
990
h2. SSH Security
991
992
https://stribika.github.io/2015/01/04/secure-secure-shell.html
993
994
h2. Windows 10
995
996
* http://ultimateoutsider.com/downloads/ - GWX Control Panel to disable GWX (Windows 10 update nagging)
997
* [[https://www.safer-networking.org/spybot-anti-beacon/|Spybot Anti-Beacon]] - Disable Micro$oft "telemetry" data gathering from Windows 10, 8.x, and 7
998
999
<pre>
1000
The newest version of the KB3035583 update includes a background process which scans the 
1001
system's Windows Registry twice a day to see if the values for the four aforementioned registry 
1002
inputs were manually edited to disable the upgrade prompt. If they were, the process will alter 
1003
the values, silently re-download the Windows 10 installation files (about 6 GB in total), and 
1004
prompt the user to upgrade.
1005
</pre>
1006
1007
1008
h2. gpg-agent
1009
1010
* http://www.infrastructureanywhere.com/documentation/additional/mirrors.html
1011
1012
These instructions are geared toward reprepro but should be useful in general for setting up `gpg-agent`.
1013
1014
1015
h2. Resolve DNS While VPN Connected
1016
1017
How to configure dnsmasq for DNS overrides while using a VPN connection: https://chawlasumit.wordpress.com/2014/06/15/linux-mint-openconnect-vpn-dns-issues/
1018
1019
h2. Pretty Print Python Traceback
1020
1021
<pre>#!python
1022
import traceback
1023
1024
 ...
1025
1026
try: 
1027
    with open('/dev/null', 'w') as void:
1028
        rc = not bool(subprocess.call('modprobe -r {:s}'.format(mod_name), 
1029
                                      shell=True, stdout=void, stderr=void))
1030
except Exception as e:
1031
    print_failure_status()
1032
    exc_type, exc_value, exc_traceback = sys.exc_info()
1033
    print('\n')
1034
    traceback.print_exception(exc_type, exc_value, exc_traceback)
1035
    print('\n')
1036
</pre>
1037
1038
h2. Generating Random Data Files for Testing
1039
1040
One approach is to use /dev/urandom (non-blocking pseudorandom device):
1041
<pre>
1042
$ dd if=/dev/urandom bs=32M count=32 of=data_1GB.bin
1043
</pre>
1044
Unfortunately /dev/urandom is a bit slow. However, you can alternatively use openssl to generate pseudorandom numbers a bit faster:
1045
<pre>
1046
 $ openssl rand 1073741824 > data_1GB.bin
1047
 $ for run in {1..30}; do echo $run; openssl rand 1073741824 >> data_30GB.bin; done
1048
</pre>
1049
1050
h2. Cloning HDDs
1051 8
1052 1
When configuring multiple chassis it is necessary to clone an HDD. There are all sorts of disk imaging tools out there but it's hard to beat the trusty dd command. The pv (pipe viewer) portion isn't strictly necessary but it prints out a very useful textual status bar. The back ticked blockdev command reports the size of the drive in bytes, which pv then uses to determine overall progress. The bs argument to dd should correspond to the cache size of the drive for optimum performance (32MB is a sane default for most drives these days).
1053
1054
To clone a single drive to another identical drive (assuming sda is the source and sdb is the destination):
1055
<pre>
1056
 $ sudo dd if=/dev/sda bs=32M | pv -s `sudo blockdev --getsize64 /dev/sda` | sudo dd of=/dev/sdb bs=32M
1057
</pre>
1058
To clone to multiple drives all at once (assuming sda is the source and sdb, sdc are destinations):
1059
<pre>
1060
 $ sudo dd if=/dev/sda bs=32M | pv -s `sudo blockdev --getsize64 /dev/sda` | tee >(sudo dd of=/dev/sdb bs=32M) | sudo dd of=/dev/sdc bs=32M
1061
</pre>
1062
It is entirely possible to clone more drives by adding additional `>(sudo dd of=/dev/sdX bs=32M)` arguments to the tee command. Note that tee outputs to stdout so it is necessary to pipe the output of tee to the final dd command as shown above. If you don't do this then tee will spew the raw contents of the source HDD to your screen, which will make the clone take forever and look especially ugly!
1063
1064
For some reason RedHat/CentOS do not have the pv command or even a package for it in their repos!!! Therefore, boot from a Debian-based OS in order to clone.
1065
1066
h2. Generating ISOs
1067
1068
<pre>
1069
 $ genisoimage -R -J -o <output.iso> <some directory>
1070
</pre>
1071
To deal with long file names:
1072
<pre>
1073
 $ genisoimage -R -J -l -D -joliet-long -o <output.iso> <some directory>
1074
</pre>
1075
1076 2
h2. BIOS/grub
1077 1
1078 2
* http://forums.linuxmint.com/viewtopic.php?f=46&t=119832
1079
* http://www.gnu.org/software/grub/manual/html_node/BIOS-installation.html
1080
* https://wiki.archlinux.org/index.php/GRUB2
1081
* http://unix.stackexchange.com/questions/28443/does-grub2-support-putting-boot-on-a-raid5-partition
1082 1
1083
h3. Creating a BIOS Boot Partition on a GPT system
1084
1085
<pre>
1086
$ sudo parted /dev/sda
1087
(parted) mkpart primary 0 1024k
1088
(parted) set 2 bios_grub on
1089
</pre>
1090
1091 2
h2. Actiontec Router
1092
1093
* http://transition.fcc.gov/oet/ea/fccid/
1094
* http://opensource.actiontec.com/mi424wref.html
1095 1
1096
h2. Temp
1097
1098
https://www.grumpyland.com/blog/183/installing-software-raid-on-centos-567-via-ssh/
1099
<pre>
1100
# swap is on /dev/md1
1101
/dev/md1 none            swap    sw              0       0
1102
1103
# storage is on /dev/md0
1104
/dev/md0        /storage        xfs     noatime,barrier=0 0 0
1105
//faramir/production/sw /sw     cifs    username=samba,password=w00tw00t!,file_mode=0666,dir_mode=0777  0       0
1106
</pre>
1107
1108
----
1109
[[../|Back home]]