Created
September 3, 2020 03:00
-
-
Save westfly/312cc7eacddff28e18d530355d9fac28 to your computer and use it in GitHub Desktop.
utils_inshell.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
function FileName() | |
{ | |
if [[ $# -eq 1 ]]; then | |
local filename=`basename $1` | |
echo ${filename%%.*} | |
fi | |
} | |
function FileExtension() | |
{ | |
if [[ $# -eq 1 ]]; then | |
local filename=`basename $1` | |
echo ${filename##*.} | |
fi | |
} | |
function FileBaseName() | |
{ | |
if [[ $# -eq 1 ]]; then | |
echo `basename $1` | |
fi | |
} | |
function DateString() | |
{ | |
if [[ $# -eq 1 ]]; then | |
local day=$1 | |
echo `date -d "$day day" +%F` | |
fi | |
} | |
function GetCurrentUnixTime() | |
{ | |
date +%s | |
} | |
function GetUnixTimeFromString() | |
{ | |
#day date +%F | |
local day=$1 | |
local timer=$2 | |
date +%s -d "$day $timer" | |
} | |
function GetTimeFromUnixTime() | |
{ | |
local time_stamp=$1 | |
date -d @$time_stamp | |
} | |
function GetFileSize() | |
{ | |
local file=$1 | |
if [[ -f $file ]]; then | |
local filesize=`ls -l $file| | |
awk '{print $5}'` | |
fi | |
echo $filesize | |
} | |
function GetFileTimeStamp() { | |
local file=$1 | |
local time_stamp=`ls $file |awk 'NF>5{print $6,$7}'` | |
date +%s -d "$time_stamp" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment