#!/bin/bash #.Y / 70 83 / / / / 105 / / / / / / ;A4_QUER.Y #.YT 3 2 0 0 3 3 1 / / / #.H!a!0:linux//io/f_/THIS!0.!c # # begin : Wed Oct 31 10:00:00 CEST 2007 # # changes : * Mon Aug 08 17:28:00 CEST 2011: # use "readlink" for f_ToAbsolutePath and f_ToFinalTarget. # --> Version 0.0.1: The modification lies between # <@0x05bf_0.0.1>- and -tags. # # * Sun Dec 23 14:05:00 CEST 2012: # added "f_SortAndUnify()". # --> Version 0.0.2 # # copyright : (C) 2009 by Thomas Bruecker =: tbrue # email : public0x05bf@bluewin.ch # version : 0.0.2 # # f_ THIS : file-functions # ++++++++++++++++++++++++ # # MyHash("linux//io/f_/THIS") = 0x0943 # # * for every function: # * if returned result is not commented, the function returns 0 on no-error. SCRIPTS=root/bin . /$SCRIPTS/math/THIS . /$SCRIPTS/string_/THIS f_ToAbsolutePath() # <@0x05bf_0.0.1> # $1 : file-path . # * convert to an absolute path. # * print result to stdout. # * the absolute path is canonicalized according to "'info coreutils', # 'readlink invocation'". { local Result0x0943 # validate existence o last path-component: find "$1" -maxdepth 0 > /dev/null 2> /dev/null Result0x0943=$? if [ ! "$Result0x0943" = "0" ]; then return $Result0x0943; fi # else # use "readlink -f" because it is also available in "coreutils-4.5.3"; the # existence of the last path-component has already been checked above. readlink -f "$1" return # return result of readlink. # } f_QMkDir() # ?MkDir # $1 : folder-path . # * make folder $1 if it does not exist. { if [ ! -d "$1" ]; then # folder does not exist. mkdir -p "$1" return # return result of mkdir . fi # else return 0 # nothing done, no error. } f_ToFinalTarget() # $1 : file . # * if file is a symbolic link, dereference it until you get a file that is # not a link. # * print result to stdout. { # <@0x05bf_0.0.1> f_ToAbsolutePath "$1" # "f_ToAbsolutePath" does it. return # return result of # f_ToAbsolutePath. # } f_MAP_() { local Command0x943 . /$SCRIPTS/io/f_/map_/THIS Command0x943=f_map_$1 shift 1 $Command0x943 "$@" return # return result of previous # command. } f_PathToName() # $1 : file-path . # * remove any leading directories from path; print result to stdout. { local AbsolutePath0x943 # canonize path: AbsolutePath0x943="$( f_ToAbsolutePath $1 )" /bin/basename "$AbsolutePath0x943" return } f_SIZE() # $1 in { b,... } : unit, $2: file-name. { local FinalTarget0x0943 Result0x0943 Size0x0943 FinalTarget0x0943=$(f_ToFinalTarget $2) Result0x0943=$? if [ ! "$Result0x0943" = "0" ]; then return $Result0x0943; fi # else Size0x0943=$( find $FinalTarget0x0943 -printf "%s\n" ) Result0x0943=$? if [ ! "$Result0x0943" = "0" ]; then return $Result0x0943; fi # else mathToUnit $1 U $Size0x0943 # U: 1 byte is rounded up. if [ $? -eq 2 ]; then # invalid unit. math_toUnitError "$0 --> f_size" "" FILE-NAME return 1 fi # else return 0 } f_SortAndUnify() { # $1 : file. # * sort file by lines and delete duplicate lines. local File TempFile File="$1" # create temporary this-file: TempFile="$(mktemp /tmp/SortAndUnify.tmp.XXXXXX)" # sort and delete duplicate lines: sort "$File" | uniq > "$TempFile" cat "$TempFile" > "$File" rm -f "$TempFile" } f_TimeTD() # $1 : file. # * print files modifcation-time as "hh:mm:ss mm/dd/yy" result to stdout. { find $1 -printf "%TT %TD\n" return }