Folder copy and rename with date

 

cp -rf /home/xxx/webapps/crm-file crm-file`date +%Y%m%d`

 

1. Output the date in a certain format:
  

    date +"%y%m%d"

    Format description:
    % : print out %
%n : next line
%t : tab
%H : hour (00-23)
%I : hour (01-12)
%k : hour (0-23)
%l : hour ( 1-12)
%M : minutes (00-59)
%p : display local AM or PM
%r : display time directly (12-hour format hh:mm:ss [AP]M)
%s : year from 1970 January 1st 00:00:00 UTC Seconds so far
%S : seconds (00-60)
%T : direct display time (24-hour clock)
%X : equivalent to %H:%M:%S
% Z : Display time zone
date:
%a : Day of the week (Sun-Sat)
%A : Day of the week (Sunday-Saturday)
%b : Month (Jan-Dec)
%B : Month (January-December)
%c : Direct display Date and time
%d : Day (01-31)
%D : Display date directly (mm/dd/yy)
%h : Same as %b
%j : Day of the year (001-366)
%m : Month (01-12)
%U : Week of the year (00-53) (when Sunday is the first day of the week)
%w : Day of the week (0-6)
%W : Week of the year (00-53) (when Monday is the first day of the week)
%x : Display the date directly (mm/ dd/yy)
%y : last two digits of year (00.99)
%Y : full year (0000-9999)

2. Name a file with a date: filename`date +%y%m%d`, where "`" is not a single quote.

2. Delete the file with the date of creation of the file as the boundary

1. A brief explanation of the find command

       find pathname -options [-print -exec -ok ...]

    pathname: The directory path that the find command looks for. For example, use . to represent the current directory and / to represent the system root directory.
    -print: The find command outputs matching files to standard output.
    -exec: The find command executes the shell command given by this parameter to the matching files. The corresponding command is of the form 'command' { } \;, note the space between { } and \;.
    -ok: The same as -exec, except that the shell command given by this parameter is executed in a safer mode. Before executing each command, a prompt will be given to let the user determine whether to execute it.

  options:
  -name

Find files by file name.

-perm 
Find files by file permissions.

-prune 
Use this option to make the find command not search in the currently specified directory. If the -depth option is used at the same time, -prune will be ignored by the find command.

-user 
Find files by file owner.

-group 
按照文件所属的组来查找文件。

-mtime -n +n 
按照文件的更改时间来查找文件, - n表示文件更改时间距现在n天以内,+ n表示文件更改时间距现在n天以前。find命令还有-atime和-ctime 选项,但它们都和-m time选项。

-nogroup 
查找无有效所属组的文件,即该文件所属的组在/etc/groups中不存在。

-nouser 
查找无有效属主的文件,即该文件的属主在/etc/passwd中不存在。
-newer file1 ! file2

查找更改时间比文件file1新但比文件file2旧的文件。
-type

查找某一类型的文件,诸如:

b - 块设备文件。
d - 目录。
c - 字符设备文件。
p - 管道文件。
l - 符号链接文件。
f - 普通文件。

-size n:[c] 查找文件长度为n块的文件,带有c时表示文件长度以字节计。
-depth:在查找文件时,首先查找当前目录中的文件,然后再在其子目录中查找。
-fstype:查找位于某一类型文件系统中的文件,这些文件系统类型通常可以在配置文件/etc/fstab中找到,该配置文件中包含了本系统中有关文件系统的信息。

-mount:在查找文件时不跨越文件系统mount点。
-follow:如果find命令遇到符号链接文件,就跟踪至链接所指向的文件。
-cpio:对匹配的文件使用cpio命令,将这些文件备份到磁带设备中。

对于时间相关的参数,有以下补充:
 -amin n
  查找系统中最后N分钟访问的文件

  -atime n
  查找系统中最后n*24小时访问的文件

  -cmin n
  查找系统中最后N分钟被改变文件状态的文件

  -ctime n
  查找系统中最后n*24小时被改变文件状态的文件

    -mmin n
  查找系统中最后N分钟被改变文件数据的文件

  -mtime n
  查找系统中最后n*24小时被改变文件数据的文件

2、删除固定日期以前的文件
   find logs -type f -mtime +5 -exec rm {  } \;

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326802166&siteId=291194637