unix-utilities
文件大小: unknow
源码售价: 5 个金币 积分规则     积分充值
资源说明:Various small Unix utilities for ~/bin
unix-utilities
==============

Various small Unix utilities for ~/bin

All of them have been written by me, except ~/bin/rename by Larry Wall
which I'm bundling with the rest for convenience since a lot of Unix boxes don't have it.

These are all meant to work on OSX. Most but not all will work on other Unix
distributions. If you have patches to make them work elsewhere, send them
via pull request or another convenient method.

Individual utilities
====================

annotate_sgf
------------

It uses Gnu Go debug mode to annotate your go game in SGF.
It will find a lot of tactical mistakes for most games by kyu players.

Usage:

    annotate_sgf 

Output saved to annotated- in the same directory as .

See: http://t-a-w.blogspot.com/2009/08/get-better-at-go-with-gnugo.html

colcut
------

Cuts long lines to specific number of characters for easy previewing.

    colcut 80 < file.xml

convert_to_png
--------------

Converts various image formats to PNG.
Mostly useful for mass conversion, for example when you have a directory
with 100 svg files dir/file-001.svg to dir/file-100.svg:

    convert_to_png dir/*.svg

will convert them all.

countdown
---------

Counts down time, then optionally runs a command.

    countdown 60
    countdown 60 open rickroll.mp3

dedup_files
-----------

Deletes duplicate files in huge directories by hash, with some optimization
to avoid unnecessary hashing.

Usage:

    dedup_files  <...

For example:

    dedup_files my_little_pony_wallpapers/

which will work pretty well even if you have 100GB of My Little Pony wallpapers.

Files in eariler directories on the list, or with earlier filenames have priority to remain.

diffschemas
-----------

Gives diff of mysql schemas.

Do dump mysql schema use:

    mysqldump -uuser -ppassword -h hostname --where 0=1 database >schema.sql

Then run:

    diffschemas schema_1.sql schema_2.sql

which will strip garbage like autoincrement counters and give you clean diff.

e
---

This utility has extremely short name since it's meant to be used as your primary
way to call text editor.

If you give it a path containing /, or file with such name exists in current directory,
it will call your editor on that file.

Otherwise - it will search your `$PATH` for this file, and execute your editor on it,
avoiding opening binaries, and other false positives.

This is extremely helpful if you have a ton of scripts you edit a lot.

These two commands achieve similar effect:

    mate `which foo`

    e foo

except `e` is shorter, doesn't force you to think about paths,
will expand all symlinks in name (avoiding issues like accidentally editing the
same file under different name in two editor window), and won't accidentally open binaries.

Editor it will use is `$E_EDITOR`, then `$EDITOR`, then TextMate if neither variable is specified.
`$E_EDITOR` variable is provided in case you want to set up them as:


    export E_EDITOR=mate
    export EDITOR="mate -w"

since git and other such tools require waiting flag.

flickr_find
-----------

Find Creative Commons licenced photos on flickr.

Usage example:

    flickr_find cute kittens

flickr_get
----------

Download best quality version of a photo from flickr and annotate it with proper file name.

Usage example:

    flickr_get http://www.flickr.com/photos/pagedooley/386303100/

which will be saved as `~/Downloads/naughty_cat_by_kevin_dooley_from_flickr_cc-by.jpg`

fix_permissions
---------------

Removes executable flag from files which shouldn't have it.
Useful for archives that went through a Windows system, zip archive,
or other system not aware of Unix executable flag.

It doesn't turn +x flag, only removes it if a file neither starts with #!,
nor is an executable according to `file` utility.

Usage:

    fix_permissions ~/Downloads

If no parameters are passed, it fixes permissions in current directory.


git_hash
--------

Hash contents of current git repository. It is useful when multiple branches
can have same contents.

Usage example:

    git_hash ~/repository
    git_hash # will hash current directory


gzip_stream
-----------

Pipe through it to gzip log without having infinitely long buffers.

Usage example:

    my_server | gzip_stream > log.gz

If you use regular gzip the last few hundred lines will be in memory indefinitely,
so you won't be able to see what's going on in `log.gz` without killing the server,
even if it happened yesterday. `gzip_stream` flushes every 5s (easily configurable),
sacrificing tiny amount of compression quality for huge amount of convenience.

See: http://t-a-w.blogspot.com/2010/07/synchronized-compressed-logging-unix.html

json_pp
-------

Pretty-prints jsons and sorts keys alphabetically. This is extremely useful
as `json_pp` included in OSX completely scrambles key order, so if you hope
for any kind of meaningful diff, that's not going to work.

Usage example:

    json_pp human_readable.json

kindle_sync
-----------

Sync your collection of ebooks with Kindle.
Handles common format conversions (epub->mobi) if you have calibre installed.

Usage example:

    kindle_sync --report  ~/Documents/Ebooks /media/Kindle/documents/Ebooks
    kindle_sync --sync    ~/Documents/Ebooks /media/Kindle/documents/Ebooks
    kindle_sync --cleanup ~/Documents/Ebooks /media/Kindle/documents/Ebooks
    kindle_sync --list    ~/Documents/Ebooks

lastfm_status
-------------

Find what your friends have been listening to recently.

Usage example:

    lastfm_status some_user

It requires `magic-xml` gem.

media_size
----------

Calculates total size of a media directory

Requires `exiftool` program. EXIF information it uses is not guaranteed to be correct.

Usage:

    media_size some_podcasts/
    media_size some_music_album/
    media_size some_movie/

`-t` option also prints totals:

    media_size -t some_movie/ another_movie/ third_movie/

`-e` option skips empty directories in output.

namenorm
--------

Safely normalizes file names replacing upper case characters and spaces with
lower case characters and underlines.

Usage:

    namenorm ~/Downloads/*


open_youtube
------------

For a file downloaded from youtube (with youtube ID encoded in name), open corresponding youtube URL.

Usage:

    open_youtube "Rick Astley - Never Gonna Give You Up-dQw4w9WgXcQ.mp4"

openmany
--------

Runs `open` command on multiple files, either as command line arguments,
or one-per-line in STDIN.

It uses OSX `open` command for OSX, or `xdg-open` on Linux.

You can also pass arguments to open, either by separating arguments from files by `--` or else everything starting from `-` is considered an argument.

Usage:

    openmany /dev/null
       progress -l sample.txt

randsample
--------

Randomly samples lines of STDIN. Count is 1 by default.

Usage:

    seq 1 20 | randsample 1

rbexe
-----

Creates executable script path with proper `#!` line and permissions.

Defaults to Ruby executable but supports a few other `#!`s.

Usage:

    rbexe file.rb
    rbexe --9 file.rb
    rbexe --pl file.pl

If file exists, it will only change its permissions without overwriting it,
so it's safe to use.

rename
------

Larry Wall's rename script, included in Debian-derived distribution, but not on any other Unix
I know of - which is literally criminal, since it's one of core Unix utilities.

If your distribution doesn't have it (or worse - has some total crap as `rename` script),
do yourself a service and install something more sensible, and in the meantime copy this
file to your `~/bin`.

rjq
---

Runs ruby code on JSON. A hybrid of `ruby -ple` and `jq`.

Data is in `$_` and whatever is in `$_` at the end gets pretty-printed as JSON.

Usage:

    curl -s 'https://dog.ceo/api/breeds/image/random' | rjq '$_=$_["message"]'

rot13
-----

ROT13 a file.

Usage (either form works):

    rot13  double_the_security.txt


sortby
------

Sort input through arbitrary Ruby expression. A lot more flexible than Unix `sort` utility.

Usage:

    sortby '$_.length' pokemon_by_oldest.txt

terminal_title
--------------

Changes title of current terminal window. Extremely useful if you have too many terminal titles.

Usage example:

    terminal_title 'Production server (do not accidentally killall -9)'; ssh production.server.example

It can also change backgrounds (in iTerm2)

    terminal_title -c 255,0,0 'Red terminal'
    terminal_title --color 0,0,255 'Blue terminal'

tfl_travel_time
---------------

Check TfL website for travel time between two places in London.
Does not handle disambiguations so you need to be fully specific (like "Victoria Underground Station" not just "Victoria")

Usage example:

    tfl_travel_time "Victoria Underground Station" "Liverpool Street Underground Station"

If the script doesn't get the answer, it opens the website (where you can disambiguate etc.)

toutf8
------

Autodetects input format, and converts UTF8 / UTF16LE / UTF16BE with and without BOM into UTF8 without BOM. This allows use with Unix utilities.

Usage example:

    toutf8 fileout.txt
    diff <(toutf8   
本源码包内暂不包含可直接显示的源代码文件,请下载源码包。