Skip to content

Instantly share code, notes, and snippets.

@westfly
Created September 3, 2020 03:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save westfly/312cc7eacddff28e18d530355d9fac28 to your computer and use it in GitHub Desktop.
Save westfly/312cc7eacddff28e18d530355d9fac28 to your computer and use it in GitHub Desktop.
utils_inshell.sh
#!/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