Shell批量重命名增加文件时间戳前缀

思路:

  1. 首先要获得文件的时间戳,ls --full-timestat -c %y命令都可以
  2. 因为是批量,需要获得文件名列表,ls -p | grep [^/]$find * -type -f
1
2
3
4
5
6
7
8
#!bin/bash
files=$(ls -p | grep [^/]$)
for file in $files
do
DATE=$(ls --full-time $file | awk '{print $6}')
mv $file "$DATE-$file"
done

依旧没有解决的问题:
只能重命名当前目录,如果使用files=$(ls -p $1 | grep [^/]$),然后传入参数,会报没有这个文件或目录