Home IT Linux Windows Database Network Programming Server Mobile  
           
  Home \ Linux \ Automatic Clear date directory shell script     - Linux System Getting Started Tutorial: How to automatically set the JAVA_HOME environment variable on Linux (Linux)

- Linux module mechanism of (Programming)

- 29 practical examples Linux system / network administrator of nmap (Linux)

- Grub2: Save Your bootloader (Linux)

- Java polymorphic methods inside constructors complete analysis (Programming)

- The SVN installation, configuration and start - up under Linux (CentOS 6.5) (Server)

- To install file manager Nautilus 3.12.2 under ubuntu (Linux)

- Linux security concerns again (Linux)

- Nine artifact control disk partition under Linux (Linux)

- How to defragment the hard disk in Linux (Linux)

- Use PDFBox parse PDF file (Linux)

- Upgrade installation manual CentOS6.5 GCC4.8.2 (Linux)

- Java class loading order (Programming)

- Ubuntu 12.04 kernel configuration automatically restart and crash dump (Linux)

- Ubuntu comes with gedit editor to add Markdown preview widget (Linux)

- Linux operating system security settings initial understanding (Linux)

- Oracle table space usage monitoring (Database)

- Share Practical Tutorial GitHub (Linux)

- JavaScript is implemented without new keywords constructor (Programming)

- To share some very useful Vim command (Linux)

 
         
  Automatic Clear date directory shell script
     
  Add Date : 2017-08-31      
         
       
         
  Many times the backup is often used to create folders based on the date for which the date folder below there are many sub-folders, remove the entire document for these dates, find looks bloated by combining rm or delete. This article provides a simple little script that can be embedded into other scripts, can be called directly, as described below for your reference.

1, the script content

[Root @ SZDB ~] # more purge_datedir.sh
#! / Bin / bash
# Author: Leshami

RemoveDir = / log / hotbak / physical
dt = `date +% Y% m% d -d" 3 day ago "`

for subdir in `ls $ RemoveDir`;
do
    if [ "$ {subdir}" \ < "$ {dt}"];
        then
        rm -rf $ RemoveDir / $ subdir> / dev / null
        echo "The directory $ RemoveDir / $ subdir has been removed."
    fi
done

2 Demo

[Root @ SZDB ~] # ls / log / hotbak / physical
20141203 20141210 20141217 20141224 20141231 20150107 20150114 20150125 tmp.sh
2,014,120,720,141,214 2,014,122,120,141,228 2,015,010,420,150,111 2,015,012,120,150,128

[Root @ SZDB ~] # ./purge_datedir.sh
The directory / log / hotbak / physical / 20141203 has been removed.
The directory / log / hotbak / physical / 20141207 has been removed.
The directory / log / hotbak / physical / 20141210 has been removed.
The directory / log / hotbak / physical / 20141214 has been removed.
The directory / log / hotbak / physical / 20141217 has been removed.
The directory / log / hotbak / physical / 20141221 has been removed.
The directory / log / hotbak / physical / 20141224 has been removed.
The directory / log / hotbak / physical / 20141228 has been removed.
The directory / log / hotbak / physical / 20141231 has been removed.
The directory / log / hotbak / physical / 20150104 has been removed.
The directory / log / hotbak / physical / 20150107 has been removed.
The directory / log / hotbak / physical / 20150111 has been removed.
The directory / log / hotbak / physical / 20150114 has been removed.
The directory / log / hotbak / physical / 20150121 has been removed.

[Root @ SZDB ~] # ls / log / hotbak / physical
2,015,012,520,150,128
     
         
       
         
  More:      
 
- The Objects in JavaScript (Programming)
- Java, on the dfile.encoding Systemproperty (Programming)
- LMMS 1.03 install on Ubuntu 14.04 (Linux)
- Manager Docker browser (Server)
- Linux file time Comments ctime mtime atime (Linux)
- Linux Shell Understanding and Learning (Linux)
- Kitematic how seamless and DockerFILE (Server)
- Python image processing library (PIL) to install and simple to use (Linux)
- C language - Traverse pci device (Programming)
- cursor_sharing induced error ORA-00600 (Database)
- C language programming entry - Common operators (Programming)
- Three easy open source firewall on the Linux platform (Linux)
- PostgreSQL using the system cache to improve operational efficiency (Database)
- Security Configuration SQL Server 2000 database tutorial (Linux)
- Linux, Oracle listen address modification (Database)
- Using Linux strace command trace / debug a program commonly used options (Linux)
- Automatic and Manual Proxy Settings Switch GNOME Shell Extension Proxy Switcher Recommend (Linux)
- linux raid levels and concepts introduced (Linux)
- rsync + inotify to achieve real-time synchronization (Server)
- OpenSSL to generate public and private key (Linux)
     
           
     
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.