Hong의 모든 글

python 파일의 생성날짜 출력하기

데이터 파일이 생성된 날짜 또는 수정된 날짜를 알아내서 화면이나 웹페이지에 표시해주고 싶은 경우가 있습니다.

Python에서 파일의 생성 날짜를 알아내려면 os.p0ath.getctime() 을 사용하면 됩니다.

하지만 os.path.getctime()은 1382189138.419602 와 같이 정수에 날짜를 소수에 시분초를 표기하는 형식을 사용합니다.

os.path.getctime()

getctime으로 받은 숫자를 우리가 흔히 보는 문자열 형태의 시간 표기법을 사용하면 다음과 같이 하면 됩니다.

from datetime import datetime
datetime.fromtimestamp(1382189138.4196026).strftime('%Y-%m-%d %H:%M:%S')

합쳐서 하면 다음과 같습니다.

datetime.datetime.fromtimestamp(os.path.getctime(model_path)).strftime('%Y-%m-%d %H:%M:%S')

추가로 파일의 수정날짜는 os.path.getmtime() 함수를 사용하면 됩니다.

쉘스크립트 시작 날짜 끝 날짜로 날짜 목록 만들기 / shell script – get date list with begin date and end date

bash shell script로 시작날짜와 끝날짜의 목록으로 날짜목록을 만드는 코드입니다.

여러 날짜에 대해서 일별로 일괄처리를 할 때 자주 쓰는 코드입니다.

#!/usr/bin/env bash

begin_date="20210101"
end_date="20210201"

date_delta_days=$(( ($(date --date="$end_date" +%s) - $(date --date="$begin_date" +%s) )/(60*60*24) ))
for (( i=0; i<=date_delta_days; i++ )); do
    date_str=$(date --date="$begin_date +$i days" +%Y%m%d)
    echo "$date_str"
done

결과

20210101
20210102
20210103
20210104
20210105
20210106
20210107
20210108
20210109
20210110
20210111
20210112
20210113
20210114
20210115
20210116
20210117
20210118
20210119
20210120
20210121
20210122
20210123
20210124
20210125
20210126
20210127
20210128
20210129
20210130
20210131
20210201

git 오류 fatal: unable to connect to cache daemon: Permission denied

git pull 또는 push를 할 때 다음과 같은 오류가 나오는 경우가 있습니다.

fatal: unable to connect to cache daemon: Permission denied

sudo를 사용하거나 권한을 잘못 변경하고 git를 사용하다가 발생한 문제인데 ~/.cach/git/credential 디렉토리의 권한을 현재 사용자에게 소유권을 다시 넘겨주면 해결됩니다.

다음과 같이 합니다.

sudo chown $(whoami) ~/.cache/git/credential/

Go언어 문자열에서 앞 또는 뒤 문자열 제거하기

Trim이라고 하는 그것입니다.

문자열에서 앞 또는 뒷쪽의 특정 문자열을 제거하는 코드입니다.

// Go program to illustrate 
// how to trim a string
package main
  
import (
    "fmt"
    "strings"
)
  
// Main method
func main() {
  
    // Creating and initializing string
    // Using shorthand declaration
    str1 := "!!Welcome to GeeksforGeeks !!"
    str2 := "@@This is the tutorial of Golang$$"
  
    // Displaying strings
    fmt.Println("Strings before trimming:")
    fmt.Println("String 1: ", str1)
    fmt.Println("String 2:", str2)
  
    // Trimming the given strings
    // Using Trim() function
    res1 := strings.Trim(str1, "!")
    res2 := strings.Trim(str2, "@$")
  
    // Displaying the results
    fmt.Println("\nStrings after trimming:")
    fmt.Println("Result 1: ", res1)
    fmt.Println("Result 2:", res2)
}

apt-get update failed because certificate verification failed because handshake failed on nodesource

apt install을 하는데 다음과 같은 에러가 나오는 경우가 있습니다.

apt-get update failed because certificate verification failed because handshake failed on nodesource

위 에러는 우분투 리눅스에 설치된 certification에 문제가 생겼기 때문입니다.

다음과 같이 재설치하면 해결됩니다.

sudo apt install ca-certificates