Project

General

Profile

Miscellaneous » History » Version 25

Anonymous, 09/07/2024 11:17 AM
adding dropping

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