Sunday, December 21, 2014
   
Text Size
Login

Unix Date Format Specifiers

I could just remember to search wikipedia for "Date (Unix)" or search my site for "Unix". This was easier.

Source: Wikipedia: Date (Unix)

Format specifiers (format string starts with +)
Specifier Description Values/Example
Day
%a weekday, abbreviated Mon
%A weekday, full Monday
%d day of the month (dd), zero padded 04
%e day of the month (dd) 4
%j day of year, zero padded 001-366
%u day of week starting with Monday (1), i.e. mtwtfss 1
%w day of week starting with Sunday (0), i.e. smtwtfs 1
Week
%U week number Sunday as first day of week 01–53
%W week number Monday as first day of week 01–53
%V week of the year 01–53
Month
%m mm month 07
%h Mon Jul
%b Mon, locale's abbreviated Jul
%B locale's full month, variable length July
Year
%y yy two digit year 00–99
%Y ccyy year 2011
%g 2-digit year corresponding to the %V week number
%G 4-digit year corresponding to the %V week number
Century
%C cc century 00–99
Date
%D mm/dd/yy 07/4/11
%x locale's date representation (mm/dd/yy) 07/4/2011
%F %Y-%m-%d 2011-07-4
Hours
%l (Lowercase L) hour (12 hour clock) 1
%I (Uppercase I) hour (12 hour clock) zero padded 01
%k hour (24 hour clock) 13
%H hour (24 hour clock) zero padded 13
%p locale's upper case AM or PM (blank in many locales) PM
%P locale's lower case am or pm pm
Minutes
%M MM minutes 20
Seconds
%s seconds since 00:00:00 1970-01-01 UTC (Unix epoch) 1309785651
%S SS second 00–60
(The 60 is necessary to accommodate a leap second)
%N nanoseconds 000000000–999999999
Time
%r hours, minutes, seconds (12-hour clock) 01:20:51 PM
%R hours, minutes (24 hour clock) hh:mm e.g. 13:20
%T hours, minutes, seconds (24-hour clock) 13:20:51
%X locale's time representation (%H:%M:%S)
Date and Time
%c locale's date and time Sat Nov 04 12:02:33 EST 1989
Time zone
%z -zzzz RFC-822 style numeric timezone -0500
%Z time zone (e.g., EDT) nothing if no time zone is determinable EST

List all cron jobs for all users

Amazing little script I found on Stack Overflow. Wasn't really my solution as after 2 hours, realised that the customer had been looking at the wrong server. But this script showed me where the cron job we intended was located.


  1.  #!/bin/bash 
  2.   
  3.  # System-wide crontab file and cron job directory. Change these for your system. 
  4.  CRONTAB='/etc/crontab' 
  5.  CRONDIR='/etc/cron.d' 
  6.   
  7.  # Single tab character. Annoyingly necessary. 
  8.  tab=$(echo -en "\t") 
  9.   
  10.  # Given a stream of crontab lines, exclude non-cron job lines, replace 
  11.  # whitespace characters with a single space, and remove any spaces from the 
  12.  # beginning of each line. 
  13.  function clean_cron_lines() { 
  14.      while read line ; do 
  15.          echo "${line}" | 
  16.              egrep --invert-match '^($|s*#|s*[[:alnum:]_]+=)' | 
  17.              sed --regexp-extended "s/\s+/ /g" | 
  18.              sed --regexp-extended "s/^ //" 
  19.      done; 
  20.  } 
  21.   
  22.  # Given a stream of cleaned crontab lines, echo any that don't include the 
  23.  # run-parts command, and for those that do, show each job file in the run-parts 
  24.  # directory as if it were scheduled explicitly. 
  25.  function lookup_run_parts() { 
  26.      while read line ; do 
  27.          match=$(echo "${line}" | egrep -o 'run-parts (-{1,2}S+ )*S+'
  28.   
  29.          if [[ -z "${match}" ]] ; then 
  30.              echo "${line}" 
  31.          else 
  32.              cron_fields=$(echo "${line}" | cut -f1-6 -d' '
  33.              cron_job_dir=$(echo  "${match}" | awk '{print }'
  34.   
  35.              if [[ -d "${cron_job_dir}" ]] ; then 
  36.                  for cron_job_file in "${cron_job_dir}"/* ; do  # */  
  37.                      [[ -f "${cron_job_file}" ]] && echo "${cron_fields} ${cron_job_file}" 
  38.                  done 
  39.              fi 
  40.          fi 
  41.      done; 
  42.  } 
  43.   
  44.  # Temporary file for crontab lines. 
  45.  temp=$(mktemp) || exit 1 
  46.   
  47.  # Add all of the jobs from the system-wide crontab file. 
  48.  cat "${CRONTAB}" | clean_cron_lines | lookup_run_parts >"${temp}"  
  49.   
  50.  # Add all of the jobs from the system-wide cron directory. 
  51.  cat "${CRONDIR}"/* | clean_cron_lines >>"${temp}"  # */  
  52.   
  53.  # Add each user's crontab (if it exists). Insert the user's name between the 
  54.  # five time fields and the command. 
  55.  while read user ; do 
  56.      crontab -l -u "${user}" 2>/dev/null | 
  57.          clean_cron_lines | 
  58.          sed --regexp-extended "s/^((\S+ +){5})(.+)$/\1${user} \3/" >>"${temp}" 
  59.  done < <(cut --fields=1 --delimiter=: /etc/passwd) 
  60.   
  61.  # Output the collected crontab lines. Replace the single spaces between the 
  62.  # fields with tab characters, sort the lines by hour and minute, insert the 
  63.  # header line, and format the results as a table. 
  64.  cat "${temp}" | 
  65.      sed --regexp-extended "s/^(\S+) +(\S+) +(\S+) +(\S+) +(\S+) +(\S+) +(.*)$/\1\t\2\t\3\t\4\t\5\t\6\t\7/" | 
  66.      sort --numeric-sort --field-separator="${tab}" --key=2,1 | 
  67.      sed "1i\mi\th\td\tm\tw\tuser\tcommand" | 
  68.      column -s"${tab}" -t 
  69.   
  70.  rm --force "${temp}" 

Changing the appearance of PUTTY

 I've added this article because I didn't know before and now I do...  Hopefully I won't forget but may do so I'll be able to look here and this should help.

 

How to run a .RUN file

 I've been told of two ways of running a downloaded .RUN file.

Note: Bear in mind that the following is all case-sensitive.

Through the terminal server

  1. Download the .RUN file to your desktop
  2. Open a terminal by going to Application > Accessories > Terminal
  3. Type 'CD Desktop' to go to your desktop folder
  4. Type 'LS' just to check the .RUN file is in this one
  5. Type 'sudo sh nameoffile.run'

Through the Gnome GUI

  1. Right-click on the file you downloaded
  2. Select 'Properties'
  3. Select the 'Permissions' tab
  4. Tick the 'Execute' checkbox

Conclusion

The solution using the terminal worked for me but the second one using Gnome didn't.

Ubuntu as a media server


  1.  1. If someone wants to use Ubuntu as a home media pc connected to a 
  2.  tv, there is the problem of overscan; consumer tv's crop off the 
  3.  border around the image. How does Ubuntu intend to officially solve 
  4.  this? Right now LinuxMCE has it's own method for doing this so the 
  5.  LMCE UI is never cropped off, but when the user switches back to 
  6.  Ubuntu's gnome desktop, the top nav bar is cut off if he's using a 
  7.  normal tv and not a pc monitor. I'd like to have 1 screen adjustment 
  8.  tool that correctly adjusts both the lmce desktop and the main ubuntu 
  9.  desktop, so even when using the Ubuntu desktop on a TV, the top nav 
  10.  isn't cropped.  Any ideas? 

Latest Posts

  • Basic Android App using Google Maps and Current Location

    • Wed 17-Dec-14
      Is that how it's spelt? setContentVie( "View". If not try going to build and "clean project". Also ...
      Joel L.  
    • Tue 16-Dec-14
      I have problem in "cannot resolved R" " setContentVie(R .layout.activit y_maps);" :cry: How to solve ...
      LucasR
  • Migrate Joomla! 1.5.x to 2.5.x+

    • Thu 18-Dec-14
      Interesting report LLiSEIL! I'll definitely have to review it when Joomla 3.5 comes out. Error 1: is ...
      Joel L.  
    • Tue 16-Dec-14
      * Categories: - duplicates, I suppose from the multiple times I launched the script. - love the notes ...
      LLiSEIL  
    • Tue 16-Dec-14
      SQL ERror 3 > -- Step 2) Import articles from J15 and insert as articles in J30 INSERT INTO `newbase_j25`.d ...
      LLiSEIL