The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,778 other followers

Archive for the ‘*nix-tools’ Category

bash: converting numbers to human readable SI or IEC units

Posted by jpluimers on 2019/12/03

Many unix tools that report sizes in bytes can convert them to either IEC or SI readable formats.

For github.com/jpluimers/btrfs-du/blob/master/btrfs-du I wrote about last week, I also wanted that kind of behaviour. So I did some research and came up with the code and test cases below.

Note that depending on the bitness of your system, bash integer numeric values are limited in size; see [WayBack] What is the maximum value of a numeric bash shell variable? – Super User.

So I wrote a small bash script for that too, which needed also gave me the opportunity to show how a  perpetual while loop as explained by [WayBack] bash – “while :” vs. “while true” – Stack Overflow.

Two things that always bite me with these short scripts are expressions (done through [WayBack]Arithmetic Expansion) and comparisons (through[WayBack] Other Comparison Operators).

The IEC suffixes contain one extra i to indicate binary and – next to the ISO notation that were already ISO defined – made it into the ISO 80000 standard since 2008. Here is a comparison list from [WayBackBinary prefix – Wikipedia:

Prefixes for multiples of
bits (bit) or bytes (B)
Decimal
Value SI
1000 k kilo
10002 M mega
10003 G giga
10004 T tera
10005 P peta
10006 E exa
10007 Z zetta
10008 Y yotta
Binary
Value IEC JEDEC
1024 Ki kibi K kilo
10242 Mi mebi M mega
10243 Gi gibi G giga
10244 Ti tebi
10245 Pi pebi
10246 Ei exbi
10247 Zi zebi
10248 Yi yobi

Most tools nowadays default to binary IEC suffixes for byte sizes, though disk manufacturers still use SI suffixes because, well then they appear bigger but aren’t. Just for comparison, look at the numbers from [WayBack] File size – Wikipedia and [WayBack] IEC and SI Size Notations – AN!Wiki where I got the test cases from:

Read the rest of this entry »

Posted in *nix, *nix-tools, bash, bash, Development, Power User, Scripting, Software Development | Leave a Comment »

some links on bash and optional parameters

Posted by jpluimers on 2019/11/26

Hopefully I’ve been able to integrate some of the ideas in the links below in github.com/jpluimers/btrfs-du/blob/master/btrfs-du

One of the features I wanted there was to be able to add optional switches like --raw, --iec or --si to it similar to what as the btrfs qgroup show subcommand has.

It seems possible with bash, but it is not trivial, at least not for me as a non-frequent bash user, so here are some links to get me started:

In retrospect, other languages than bash might have been a better choice for a script like that (:

–jeroen

PS, some btrfs references:

Posted in *nix, *nix-tools, bash, bash, Development, Power User, Scripting, Software Development | Leave a Comment »

rpm – Suse: Restore Packages List from /var/adm/backup/rpmdb/Packages-20160323 .gz – Server Fault

Posted by jpluimers on 2019/11/25

In case I ever need to view the archived /var/adm/backup/rpmdb files again: [WayBack] rpm – Suse: Restore Packages List from /var/adm/backup/rpmdb/Packages-20160323 .gz – Server Fault

–jeroen

Posted in *nix, Power User, rpm | Leave a Comment »

xargs compressing lots of files using xz

Posted by jpluimers on 2019/11/20

One day, on a legacy Linux system, logrotate managed to skip some files in the middle of a sequence in /var/log.

Since I didn’t have time to sort out the cause (the system was being phased out), I used this to compress the rest of the log-files (dated in 2017):

sudo -u bash
pushd /var/log
ls | grep -vw xz | grep "\-20......$" | xargs -L 1 ls -alh

After that you can execute this in the same directory:

ls | grep -vw xz | grep "\-20......$" | xargs -L 1 time xz

It skips any xz files and includes only files in the year 2017.

I occasionally tracked progress with this:

ls -alh /var/log/ | grep -v xz | less

That got back a few gigabytes of disk space, just enough to help me migrate the system away.

–jeroen

Posted in *nix, *nix-tools, bash, logrotate, Power User | Leave a Comment »

20 Cool Command Line Tricks for Windows and macOS

Posted by jpluimers on 2019/11/08

After all these years in the field, I still learned new tricks from [WayBack20 Cool Command Line Tricks for Windows and macOS which I have rephrased:

Windows

1) View installed drivers: [WayBack] driverquery

2) Watch Star Wars in ASCII: [WayBacktelnet towel.blinkenlights.nl

3) Save folder trees to disk: tree (I had totally forgotten about this, probably because it leaves out a lot of directories and files)

5) Show your Wi-Fi password [WayBacknetsh wlan show profile SSID key=clear (replace SSID with your network name; use nets wlan show profile to view the network names)

7) Check your laptop’s battery health: [WayBack] powercfg /batteryreport which will be in ” and hit Enter to generate the report, then %HOMEPATH%\battery-report.html

8) View your Windows license key: wmic path softwarelicensingservice get OA3xOriginalProductKey [WayBack]

Mac OS X / macOS / however it is called now

1) Change the default screenshot type: [WayBackdefaults write com.apple.screencapture type JPG (you can also use JP2 (for JPEG2000), PDF, PNG, TIFF and others)

2) Get your Mac to speak to you: use say

3) Add a message to the login screen: sudo defaults write /Library/Preferences/com.apple.loginwindow LoginwindowText "your new text on the logon window" [WayBack]

4) Play Tetris and other classics: start emacs, then press Esc followed by X, type in tetris, pong, snake or solitaire (to exit emacs, press CtrlX followed by CtrlC). There are [WayBack] more emacs games.

5) Get a dictionary definition: run curl dict://dict.org/d:word (where word is what you are after) which uses the [WayBack] dict protocol

6) Keep macOS awake: [WayBack] caffeinate optionally followed by a -t## parameter where ## is the number of seconds to not sleep.

7) Show hidden files: defaults write com.apple.finder AppleShowAllFiles -bool TRUE; killall Finder or use this AppleShowAllFiles script which I had forgotten about writing in the first place.

10) Add Spaces to the Dock: defaults write com.apple.dock persistent-apps -array-add ‘{”tile-type”=”spacer-tile”;}’; killall Dock running the command as many times as you want spaces. To get rid of a space you’ve added, just drag them to the Trash.

–jeroen

via: [WayBack] 20 Cool Command Line Tricks for Windows and macOS http://flip.it/SvcQlu – Joe C. Hecht – Google+

Posted in *nix, *nix-tools, Apple, cURL, Power User | Leave a Comment »

 
%d bloggers like this: