Delete the first n folders sorted by time in the current folder in Linux

Source: Internet
Author: User

Today, someone in the group asked how to delete the first n folders sorted by time under a folder, which only contains folders. I wrote a script, and someone in the Group wrote a script, which is now sorted out for future reference.

Personal:

#! /Bin/sh

Ls-LRT | awk '{If (NR <4 & Nr! = 1) printf ("RM-RF % s \ n", $8)} '> rm2.sh

Chmod 755 rm2.sh

./Rm2.sh

Rm rm2.sh

Master's:

#! /Bin/sh

For I in 'LS-lthr | head-3 | grep-V 'total''

Do

Rm-RF $ I

Done;

From the above two scripts, we can see that the gap between the two is so big. I also need to continue to study Linux scripts and move towards the goal of a master.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.