Get 'ack' now at http://betterthangrep.com/
Usage:
watch ls -l
Basic but usable replacement for the "watch" command for those systems which don't have it (e.g. the Solaris I'm trapped on).
Type Ctrl+V to escape the following Ctrl+L which clears the screen. It will be displayed as "^L".
You can use this in shell scripts to show which commands are actually run. Just prepend every "critical line" with "v˽". $TMP=/tmp echo "Let me create a directory for you" v mkdir $TMP/new In scripts this can be more useful than "set -x", because that can be very verbose with variable assignments etc. Another nice use is if you prepend every "critical" command with "v", then you can test your script by commenting out the actual execution. Show Sample Output
If you use new features of a certain Bash version in your shell script, make sure that it actually runs with the required version.
This is useful when watching a log file that does not contain timestamps itself. If the file already has content when starting the command, the first lines will have the "wrong" timestamp when the command was started and not when the lines were originally written.
Reads 4 bytes from the random device and formats them as unsigned integer between 0 and 2^32-1. Show Sample Output
Set a bookmark as normal shell variable
p=/cumbersome/path/to/project
To go there
to p
This saves one "$" and is faster to type ;-) The variable is still useful as such:
vim $p/<TAB>
will expand the variable (at least in bash) and show a list of files to edit.
If setting the bookmarks is too much typing you could add another function
bm() { eval $1=$(pwd); }
then bookmark the current directory with
bm p
The given example collects output of the tail command: Whenever a line is emitted, further lines are collected, until no more output comes for one second. This group of lines is then sent as notification to the user.
You can test the example with
logger "First group"; sleep 1; logger "Second"; logger "group"
Usage:
sftp-cp * | sftp user@host:/dir
This is useful if there is a process on the remote machine waiting for files in an incoming directory. This way it won't see half-transmitted files if it ignores hidden files.
This got a bit complicated, because I had to introduce an additional dot at the end that has to be removed again later.
Using perl you can search for patterns spanning several lines, a thing that grep can't do. Append the list of files to above command or pipe a file through it, just as with regular grep. If you add the 's' modifier to the regex, the dot '.' also matches line endings, useful if you don't known how many lines you need are between parts of your pattern. Change '*' to '*?' to make it greedy, that is match only as few characters as possible. See also http://www.commandlinefu.com/commands/view/1764/display-a-block-of-text-with-awk to do a similar thing with awk. Edit: The undef has to be put in a begin-block, or a match in the first line would not be found.
Useful if a different user cannot access some directory and you want to know which directory on the way misses the x bit. Show Sample Output
List packages and their disk usage in decreasing order. This uses the "Installed-Size" from the package metadata. It may differ from the actual used space, because e.g. data files (think of databases) or log files may take additional space. Show Sample Output
Use 'mmv' for mass renames. The globbing syntax is intuitive.
'top' has fancy layout modes where you can have several windows with different things displayed. You can configure a layout and then save it with 'W'. It will then be restored every time you run top.
E.g. to have two colored windows, one sorted by CPU usage, the other by memory usage, run top
top
then press the keys
<A> <z> <a> <-> <a> <z> <a> <-> <a>
and then as you don?t want to repeat this the next time:
<W>
I never can remember the syntax of awk. You can give a different -d option to cut to separate by e.g. commas. Also this allows to do more things with the generated SQL, e.g. to redirect it into different files. Show Sample Output
commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.
Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.
» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10
Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):
Subscribe to the feed for: