Project

General

Profile

Miscellaneous » History » Version 8

Anonymous, 06/25/2022 03:46 PM
correcting wiki syntax

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