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)}; }
Return the creation date of a file on ext2, 3, 4 filesystems, because stat command won't show it. Useful on ubuntu, debian, and else Show Sample Output
This loop will finish if a file hasn't changed in the last 10 seconds. . It checks the file's modification timestamp against the clock. If 10 seconds have elapsed without any change to the file, then the loop ends. . This script will give a false positive if there's a 10 second delay between updates, e.g. due to network congestion . How does it work? 'date +%s' gives the current time in seconds 'stat -c %Y' gives the file's last modification time in seconds '$(( ))' is bash's way of doing maths '[ X -lt 10 ]' tests the result is Less Than 10 otherwise sleep for 1 second and repeat . Note: Clever as this script is, inotify is smarter. Show Sample Output
A wrapper around ssh to automatically provide logging and session handling.
This function runs ssh, which runs screen, which runs script.
.
The logs and the screen session are stored on the server.
This means you can leave a session running and re-attach to it later, or from another machine.
.
.
Requirements:
* Log sessions on a remote server
* Transparent - nothing extra to type
* No installation - nothing to copy to the server beforehand
.
Features:
* Function wrapper delegating to ssh
- so nothing to remember
- uses .ssh/config as expected
- passes your command line option to ssh
* Self-contained: no scripts to install on the server
* Uses screen(1), so is:
- detachable
- re-attachable
- shareable
* Records session using script(1)
* Configurable log file location, which may contain variables or whitespace
L="$HOME" # local variable
L="\$HOME" # server variable
L="some space"
.
Limitations:
* Log dir/file may not contain '~' (which would require eval on the server)
.
.
The sessions are named by the local user connecting to the server.
Therefore if you detach and re-run the same command you will reconnect to your original session.
If you want to connect/share another's session simply run:
USER=bob ssh root@server
.
The command above is stripped down to an absolute minimum.
A fully expanded and annotated version is available as a Gist (git pastebin):
https://gist.github.com/flatcap/3c42326abeb1197ee714
.
If you want to add timing info to script, change the command to:
ssh(){ L="\$HOME/logs/$(date +%F_%H:%M)-$USER";/usr/bin/ssh -t "$@" "mkdir -p \"${L%/*}\";screen -xRRS $USER script --timing=\"$L-timing\" -f \"$L\"";}
Show Sample Output
Do you ever want to know which day of week was your birhday! Now you can check that with this command, just set your birh date at the beginning (My bday in the example) and the dates will be revealed. ;) Show Sample Output
Friday is the 5th day of the week, monday is the 1st. Output may be affected by locale. Show Sample Output
A quick and simple way of outputting the start and end date of a certificate, you can simply use 'openssl x509 -in xxxxxx.crt -noout -enddate' to output the end date (ex. notAfter=Feb 01 11:30:32 2009 GMT) and with the date command you format the output to an ISO format. For the start date use the switch -startdate and for end date use -enddate. Show Sample Output
In a folder with many files and folders, you want to move all files where the date is >= the file olderFilesNameToMove and
Exactly the same number of characters, exactly the same results, but with bc Show Sample Output
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. Show Sample Output
Work out last months numerical value. Show Sample Output
cryptic version Show Sample Output
This command will show the current GMT time using HTTP. This might be useful if you just want to know what's the current human-readable and accurate-enough time, without changing the system time, using a simple command that would work regardless of the availability of NTP. Note: To get a quicker and more accurate response, replace google.com with your local NTP server. Also can be used as an alternative to the "htpdate" program: http://www.commandlinefu.com/commands/view/668/set-your-computers-clock-using-http-and-htp-http-time-protocol-when-ntpsntp-is-not-available Show Sample Output
Get the time since epoch. Useful when working with commands and logs which use this format.
If your locale has Monday as the first day of the week, like mine in the UK, change the two $7 into $6 Show Sample Output
Often you run a command, but afterwards you're not quite sure what it did.
By adding this prefix/suffix around [COMMAND], you can list any files that were modified.
.
Take a nanosecond timestamp: YYYY-MM-DD HH:MM:SS.NNNNNNNNN
date "+%F %T.%N"
.
Find any files that have been modified since that timestamp:
find . -newermt "$D"
.
This command currently only searches below the current directory.
If you want to look elsewhere change the find parameter, e.g.
find /var/log . -newermt "$D"
Show Sample Output
Print out your age in days in binary. Today's my binary birthday, I'm 2^14 days old :-) . This command does bash arithmatic $(( )) on two dates: Today: $(date +%s) Date of birth: $(date +%s -d YYYY-MM-DD) The dates are expressed as the number of seconds since the Unix epoch (Jan 1970), so we devide the difference by 86400 (seconds per day). . Finally we pipe "obase=2; DAYS-OLD" into bc to convert to binary. (obase == output base) Show Sample Output
Only shows files with actual changes to text (excluding whitespace). Useful if you've messed up permissions or transferred in files from windows or something like that, so that you can get a list of changed files, and clean up the rest.
A shell function using perl to easily convert Unix-time to text. Put in in your ~/.bashrc or equivalent. Tested on Linux / Solaris Bourne, bash and zsh. using perl 5.6 and higher. (Does not require GNU date like some other commands) Show Sample Output
If you don't have netcat, you can use curl.
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: