파일 이름에 현재 날짜 및 시간 추가

파일 이름에 현재 날짜 및 시간 추가

현재 날짜와 시간을 파일 이름에 추가하려면 명령에 무엇을 추가할 수 있나요?

find . -maxdepth 1 -type f ! -name "*.*" -exec cp -p -t /new/location {} \+

답변1

find . -maxdepth 1 -type f ! -name "*.*" -exec cp -p {} /new/location/{}-$(date +%Y-%m-%d) \;

-t명령에서 target() 매개변수를 제거 cp하고 경로와 파일 이름을 설명했습니다.

{}파일 이름의 자리 표시자로 사용되며 date원하는 형식으로 a를 추가합니다.

예제 형식은 +%Y-%m-%d설명이 필요합니다.

답변2

_$(date +%Y-%m-%d_%H-%M-%S)

데이트용그리고 시간, (또는 date +%F_%T대부분의 구현에서는 간단히 호출됩니다 date).

답변3

그리고 zsh:

autoload zmv # best in ~/.zshrc
now=${(%):-%D{%FT%T%z}} # using prompt expansion with the %
                        # parameter expansion flag

# or (using the strftime builtin)
zmodload zsh/datetime
strftime -s now %FT%T%z $EPOCHSECONDS

# or (using the date external utility)
now=$(date +%FT%T%z)

# optional:
zmodload zsh/files # to enable a cp builtin which would speed
                   # things up considerably if you have
                   # zillions of files to copy.

zmv -C '^*.*(#q.)' '/new/localtion/$f-$now'

(#q.)선택하는 데 사용되는 전역 한정자입니다.정기적인파일만(예: find's' -type f)

관련 정보