touch file
touch *
stat file
ls –l
touch -d"2001-01-01 20:00:00" file
ls -l file
nano timestamps.sh
#!/bin/bash
if [$# -eq 0];then
echo “Use asave (-s) or restore (-r) parameter.”
exit 1
fi
chmod +x timestamps.sh
./timestamps.sh
if [$1 ="-s"] ; then
fi
rm -f timestamps;
ls –l
-rw-r--r-- 1 user user 0 Jan 1 2017 file
ls -l file | sed 's/^.*Jan/Jan/p'
ls -l file | sed 's/^.*Jan/01/p'
ls -l | sed -n 's/^.*Jan/01/p;s/^.*Feb/02/p;s/^.*Mar/03/p;s/^.*Apr/04/p;s/^.*May/05/p;s/^.*Jun/06/p;s/^.*Jul/07/p;s/^.*Aug/08/p;s/^.*Sep/09/p;s/^.*Oct/10/p;s/^.*Nov/11/p;s/^.*Dec/12/p;'
do echo $x | ls -l | sed -n 's/^.*Jan/01/p;s/^.*Feb/02/p;s/^.*Mar/03/p;s/^.*Apr/04/p;s/^.*May/05/p;s/^.*Jun/06/p;s/^.*Jul/07/p;s/^.*Aug/08/p;s/^.*Sep/09/p;s/^.*Oct/10/p;s/^.*Nov/11/p;s/^.*Dec/12/p;' >> timestamps
./timestamps.sh –s
cat timestamps
if $1 = "-r" ; thenfi
cat timestamps |while read linedodone
MONTH=$(echo $line | cut -f1 -d );
DAY=$(echo $line| cut -f2 -d );
FILENAME=$(echo $line | cut -f4 -d );
YEAR=$(echo $line | cut -f3 -d )
CURRENTYEAR=$(cal | head -1 | cut -f6- -d | sed 's/ //g')
touch -d "2001-01-01 20:00:00" file
if [ $YEAR == *:* ]; then
touch -d $CURRENTYEAR-$MONTH-$DAY $YEAR:00 $FILENAME;
else
touch -d ""$YEAR-$MONTH-$DAY"" $FILENAME;
fi
./timestamps.sh –s 保存文件时间戳
touch -d “2050-10-12 10:00:00″ * 修改目录下的所有文件时间戳
ls –a 确认修改的文件
./timestamps.sh –r 恢复文件原始时间戳
标签:yyds,00,01,盘点,干货,ls,file,touch,timestamps
From: https://blog.51cto.com/u_15452495/6177947