msc: stuff like pocket lint
MSC is my collection of missing shell commands
- stuff where I
feel comfortable when it's at my fingertips on a Unix commandline, and
where I feel very naked when I don't have it! Have you ever been asked
by a customer to take care of a Unix system, and then you log in,
and.. aarrgh - the commandline just won't behave how it should? Well,
: a set of "missing commands" that are very easily
installed on new systems and very handy to have.
As with most stuff on my site: feel free to use MSC. It's
distributed without cost, and without warranty - use at your own risk.
Licensing GPLV3 applies: if you re-distribute it, you must do so in
source format, and with the license intact. Finally - if you have good
additions, you're of course free to put them in, but I'd appreciate a
How to get it
What does it do
Here's a quick description of what's in the MSC package. The following
list shows, in no particular order, the commands that you normally
type (and not the setup-commands like shown in the listing above).
msc Shows what commands are in the package (just gives a
l and d Quicks for "ls" and "ls -Fla".
lx ext and dx ext: Quicks for "ls by extension",
e.g. lx c does "ls *.c".
rx ext Removes by extension, as in rx o a ("rm *.o *.a")
- and --: cd one-up or two-up.
xd ulb: This is a nifty one. Fast directory-changer, by
initials. E.g., xd ulb will take you to
/usr/local/bin, xd ulsct will take you to
/usr/local/src/crossroaads/trunk (if those destinations exist, of
course). When more than one possibility is available, you get a
choice where you want to go.
tarc archive dir/, tart archive, tarx
archive: Shorthands to create/list/extract a compressed tar
archive. Depending on the archive name, the compression is
selected; the name must end in .tar (no compression), .tar.gz or
.tgz (gzip), .tar.bz2 or .tbz2 (bzip2).
path prefix [prefix...]: For all prefixes, checks if
prefix/bin or prefix/sbin exists and adds it to the PATH. The new
PATH setting is echoed; uses as eval $(path /opt/mystuff
/opt/otherstuff). In this case PATH would be extended with
/opt/mystuff/bin/, /opt/mystuff/sbin/ etc.
ps1: Prints a nice bash prompt, use as eval $(ps1).
x or x user, or x user@host: Starts an xterm.
When the user is given (or user@host) then an SSH connection is
made to the given credentials.
xoff or xon: Turns of X by temporary deleting the
DISPLAY variable, or by re-enabling it.
his myprog: Shows the history of your commands
where myprog occurred. Just his shows the entire
history (as far as captured by Bash).
e file and ew file: Starts the system editor. When
possible, e is asynchronous (returns the prompt); ew
ep: Lets you edit your Bash profile and afterwords reloads
it. For example, you can enter ep, add an alias to your
profile, exit the editor - and pronto, it's loaded. User's
profiles are expected as "~/.bashrc", root's profile is expected
as "/etc/bashrc" or "/etc/bash.bashrc".
cpf file(s) directory is a "copy-forward", files are only
copied when they don't yet exist in the destination directory, or
when they are more recent. New files aren't overwritten by old
ones. I use this on Unixes where the "cp" command doesn't support
the flag "-n" (yes, these are still around!)
ftail file(s): Like tail -f, for Unixes that don't
have GNU tail.
ip shows the configured IP addresses (from ifconfig).
ruler: displays a 80-column ruler, or use -w WIDTH
for other widths.
less file, perldoc subject, man subject: Like
the normal less or perldoc or man, but when X
is available, the command runs in a separate xterm window.
m: Like make, but you get normal and error output
piped into less. Another quickie command.
psg command (as in "ps|grep"): Examines the ps list
and shows the matching command(s).
while1 and while5 run commands each 1 or 5
seconds. They are just shortcuts to while [ true ] ; do
commands; sleep 5; done.
while0 is just a while [true] without
- beep just beeps 5 times. I use it to get an alert after a
long-running command ends, as in: long-running-command; beep
ascii shows the ASCII table.
localtime NSEC and gmtime NSEC converts a
seconds-since-epoch count to the system localtime or to UTC.
timet shows the number of seconds since start-of-epoch.
- ds is a case-insensitive find that
avoids .svn, CVS etc.. Use as e.g. ds file,
which will match myfile.o, MyOtherFile.c and so on.
- loglimit is for those situations where you don't have
e.g. Apache's logrotate and you need to limit the growth of
log files. Use as for example: mycommand | loglimit /tmp/mylog
10000 5. This will limit the size of /tmp/mylog to
10.000 bytes, and it will leave up to 5 historical versions
(/tmp/mylog.1 up to /tmp/mylog.5).
b64dec and b64enc: Encodes or decodes all
command line strings. If no arguments are given, processes
"stdin" (as in: b64enc 'Hello World' | b64dec)
hex file(s) hexdumps the contents of the file(s). Use file
"-" to dump stdin.
d2u file(s) and u2d file(s): Standard DOS to Unix or
Unix to DOS file conversion.
tolower file renames the named files to lowercase.
tac is the reverse of cat for systems that lack it.
It prints either stdin or a named file line by line in
rsyncdir localdir user@remotehost:remotedir
calls rsync over ssh for syncing of directories.
r: Shorthand to become root (via sudo or ssh). When
optional arguments are given, then they are run under root
h: Without arguments, starts editing the hosts file. With
arguments, greps the hosts file for host/ip combo's.
Full "usage" information
Here's what msc reports when you run it without any arguments:
These are the Missing Shell Commands V1.33
Copyright (c) Karel Kubat <firstname.lastname@example.org>. Visit http://www.kubat.nl/ for
For installation into BINDIR (default: /usr/local/bin/), type:
msc install [BINDIR]
For bootstrapping (loading of aliases, functions), type:
msc bootstrap [BINDIR] > /tmp/$$; . /tmp/$$; rm /tmp/$$
Available (symlinked) commands:
l, d short, long directory listing
lt, dt short, long listing by date
lx, dx short, long directory listing by extension, e.g. dx c (lists *.c)
rx remove files by extension, e.g. rx o a (removes *.o *.a)
up1, up2 cd 1 or 2 up, use as: eval `up1` and: eval `up2`
to set up the aliases - and --, run the bootstrap or:
gd goto-directory, use as: eval `gd /new/directo/ry`
to set this up as a bash function, run the boostrap or:
gd_function > /tmp/$$; . /tmp/$$; rm -f /tmp/$$
xd fast cd, use as: eval `xd ulb` (ulb is short for
/usr/local/bin or whatever matches)
to set this up as a plain xd bash command, run the boostrap or:
xd_function > /tmp/$$; . /tmp/$$; rm -f /tmp/$$
tarc create tar archive, supported: .tar, .tar.gz, .tgz, .tar.bz2, .tbz2
tart list tar archive
tarx extract tar archive
path set shell path, use as: eval `path d1 d2 d3`, sets standard dirs
and adds to the path d1,d1/bin,d1/sbin and so on
ps1 set bash prompt, use as: eval `ps1`
x start xterm, use as: x user@host, default: thisuser, @localhost
xoff turn off X ($DISPLAY), use as: eval `xoff`
xon turn on X ($DISPLAY), use as: eval `xon`
to set up xon and xoff as aliases, run the boostrap or:
his show shell history (use his STRING to limit)
to set this up, run the boostrap or:
his_function > /tmp/$$; . /tmp/$$; rm -f /tmp/$$
e, ew start editor (async or wait mode)
ep edit and reload bash profile, use as: eval `ep`
to set up ep as a bash command, run the boostrap or:
cpf copy-forward, if you don't have cp -n
ftail like tail -f, if you don't have it
ip shows IP addresses
ruler displays a 80-column ruler, or use ruler -w WIDTH for other nrs.
less less-pager in a new window
man man display in a new window
m make, with stdout/stderr to less
perldoc Perl documentation in a new window
psg like 'ps ax' but looks for certain commands
while1 run commands every 1 second (or 5 sec with while5, or without delay
with while0), use as: while1 cmd1 cmd2 cmd3
beep sound the alarm
ascii shows the ASCII table
localtime converts seconds-since-epoch to local time
gmtime converts seconds-since-epoch to UTC (gm) time
timet shows seconds-since-epoch
ds case-insensitive find, avoids .svn, CVS etc.
loglimit pipe that writes limited logs, use as:
cmd | loglimit FILE SIZE HISTORYFILES
b64enc encode into base64 format (either cmdline arguments or stdin)
b64dec decode from base64 format (either cmdline arguments or stdin)
hex hexdumps a file (use - for stdin)
crypt standard Unix crypt function
d2u,u2d dos2unix or unix2dos file conversions
tolower file renaming to lower case
tac reversed cat, dumps file line by line in reversed order
rsyncdir rsync over ssh to sync local and remote dir
r sudo to root, optional arguments are a command to root
h with arguments, search for in /etc/hosts; else, edit the file