Project

General

Profile

Miscellaneous » History » Version 27

Anonymous, 09/28/2024 09:38 AM
updating note

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