Saves all the "cut" hacks
Lightweight alternative with case Show Sample Output
"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. Show Sample Output
even shorter (infix) version. Show Sample Output
The same with colors
Choosing your year and month. You only need the gnu date command and bash. desiredDay of the week is (1..7); 1 is Monday.
If you want desiredDay of week (0..6); 0 is Sunday
desiredDay=6; year=2012; month=5; n=0; while [ $(date -d "$year-$((month+1))-1 - $n day" "+%w") -ne $desiredDay ]; do n=$((n+1)); done; date -d "$year-$((month+1))-1 - $n day" "+%x"
Show Sample Output
Format of the response: [-]HH:mm Show Sample Output
On CentOS at least, date returns a boolean for the common date string formats, including YYYY-MM-DD. In the sample output, you can see various invalid dates returning 0 whereas a simple regex check would return 1 for the invalid dates. -d, --date=STRING display time described by STRING, not `now' The version of date on OS X does not appear to have this same option. Show Sample Output
On the Mac, the 'ls' function can sort based on month/day/time, but seems to lack ability to filter on the Year field (#9 among the long listed fields). The sorted list continuously increases the 'START' year for the most recently accessed set of files. The final month printed will be the highest month that appeared in that START year. The command does its magic on the current directory, and suitably discards all entries that are themselves directories. If you expect files dating prior to 2002, change the START year accordingly.
Back up /etc directory with a name based on the current date and the hostname of the machine, then chown the file for the current user for use.
Useful if localhost is a small machine running BusyBox, which uses a slightly unusual format to set the date. Remotehost can be pretty much any Linux machine, including one running BusyBox. Uses UTC for portability.
This can be easier to look at in ls output. Not as clean as +%Y%m%dT%H%M%S, but quicker to write. Show Sample Output
Calculate the date of Sysadmin day (last Friday of July) of any given year Show Sample Output
Calculate Sysadmin day of any given year using 2 `date`. Code based on http://stackoverflow.com/a/5656859/196133 Show Sample Output
This function will find the modification time in unix_time of the given file, then calculate the number of minutes from now to then and then find all files modified in that range. Show Sample Output
perl version of "Wait for file to stop changing" When "FileName" has not been changed for last 10 seconds, then print "DONE" "10" in "(stat)[10]" means ctime. One have other options like atime, mtime and others. http://perldoc.perl.org/functions/stat.html
When run on an existing file, alters it's creation date.
Great for backup / restore scripts. May want to remove the %M/%S to group backups by hour. If using a script, set a variable earlier with the date command, then reference that variable. Otherwise, time will keep on rolling ;-) declare -rx script_start_time="$(date '+./%Y/%m/%d/%H/%M/%S')" mkdir -p "$script_start_time" Show Sample Output
minimal oneliner to keep track of time Show Sample Output
IMPORTANT: You need Windows PowerShell to run this command - in your Windows Command Prompt, type
powershell
Uses sajb to start a PowerShell background job that pings an IP host every 10 seconds.
Any changes in the host's Up/Down state is time-stamped and logged to a file.
Date/time stamps are logged in two formats: Unix and human-readable.
A while(1) loop repeats the test every 10 seconds by using the sleep command.
See the Sample Output for more detail.
I use this command to log Up/Down events of my Motorola SB6141 cable modem (192.168.100.1).
To end the logging, close the PowerShell window or use the "exit" command.
Show Sample Output
echo 'Current hour' hour=$(date +%H) if [ $hour -gt 9 -a $hour -lt 23 ]; then echo -n '*'; else echo -n '#'; fi; echo ' '$hour; echo 'Test around the clock:' for hour in {0..23} {0..23}; do if [ $hour -gt 9 -a $hour -lt 23 ]; then echo -n '*'; else echo -n '#'; fi; echo ' '$hour; done echo 'If you need to depend on UTC, just add `-u` flag to `date` command' 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: