commandlinefu.com is the place to record those command-line gems that you return to again and again.
Delete that bloated snippets file you've been using and share your personal repository with the world. 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.
If you have a new feature suggestion or find a bug, please get in touch via http://commandlinefu.uservoice.com/
You can sign-in using OpenID credentials, or register a traditional username and password.
First-time OpenID users will be automatically assigned a username which can be changed after signing in.
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:
Countdown clock - Counts down from $MIN minutes to zero.
I let the date command do the maths.
This version doesn't use seq.
Shows a simple clock in the console
-t param removes the watch header
Ctrl-c to exit
* Replace USERNAME with the desired svn username
* Replace the first YYYY-MM-DD with the date you want to get the log (this starts at the midnight event that starts this date)
* Replace the second YYYY-MM-DD with the date after you want to get the log (this will end the log scan on midnight of the previous day)
Example, if I want the log for December 10, 2010, I would put {2010-12-10}:{2010-12-11}
"infix" version in bash (4.x+)
Remove -v to make it silent.
BTW: The OP forgot to use "cat" and "nmap" ;-) I had a good laugh though.
This backup function preserve the file suffix allowing zsh suffix aliases and desktop default actions to work with the backup file too.
1. you don't need to prepend the year with 20 - just use Y instead of y
2. you may want to make your function a bit more secure:
buf () { cp ${1?filename not specified}{,$(date +%Y%m%d_%H%M%S)}; }
displays current time in "binary clock" format
(loosely) inspired by: http://www.thinkgeek.com/homeoffice/lights/59e0/
"Decoding":
8421
.... - 1st hour digit: 0
*..* - 2nd hour digit: 9 (8+1)
.*.. - 1st minutes digit: 4
*..* - 2nd minutes digit: 9 (8+1)
Prompt-command version:
PROMPT_COMMAND='echo "10 i 2 o $(date +"%H%M"|cut -b 1,2,3,4 --output-delimiter=" ") f"|dc|tac|xargs printf "%04d\n"|tr "01" ".*"'
Should be a bit more portable since echo -e/n and date's -Ins are not.
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.
Increase the modification date for the files selected with the find command.
This script compares the modification date of /var/lib/dpkg/info/${package}.list and all the files mentioned there.
It could be wrong on noatime partitions.
Here is non-oneliner:
#!/bin/sh
package=$1;
list=/var/lib/dpkg/info/${package}.list;
inst=$(stat "$list" -c %X);
cat $list |
(
while read file; do
if [ -f "$file" ]; then
acc=$(stat "$file" -c %X);
if [ $inst -lt $acc ]; then
echo used $file
exit 0
fi;
fi;
done
exit 1
)
The "date' command has options to easily format the date, day, month, time, etc. But what if you want a relative date or time. Like, I wanted yesterday's date in a particular format. You may want the exact date of "2 months ago" or "-3 days" nicely formatted. For that, you can use this command. The --date option takes fuzzy parameters like the ones mentioned in the previous sentence.
Exactly the same number of characters, exactly the same results, but with bc
This command prints the Date (Not time) from 3 days ago (72 hours ago).
This works on systems without GNU date (MacOSX , Solaris, FreeBSD).
In a folder with many files and folders, you want to move all files where the date is >= the file olderFilesNameToMove and
Change HH:MM with your target time.
This is for a Debian/Ubuntu GNU system. You need bash (package bash), date (package coreutils) and toilet (package toilet). Install with:
# apt-get install bash coreutils toilet toilet-fonts