Linux shell programming ideas for bulk deletion of all directories under a specified directory

Source: Internet
Author: User

Application Scenario: A directory contains many software source Tarball, after the deployment of these software, will certainly generate a lot of useless temporary directory, you can script the way to delete all directories in the directory. When there are some special names in the directory, such as those directories are not supported by the Linux system special characters "/" (these files are usually supported by the Windows system) or there are spaces in the directory name, it becomes difficult to delete these directories in bulk.

Problem Analysis and Solution:

1. There are some important directories in the current working directory that may not want to be deleted

WORKAROUND: Exclude these directories to

Question 2: Some special directory names need to be considered, such as "Test Dir", "2015/03/11-log", "Download"

Workaround: Use Inode to eliminate the peculiarities of user namespaces

Background knowledge:

The inode is an abbreviation for index node or information node, which is a special structure for storing basic information about a file, including the owner, type, access rights, and location of the actual data stored on the disk. The inode is stored in the Inode table of each file system.

Index or information Node. This is a structure containing the basic information on a file such as owner, type, access permissions and pointers to The actual data on the disk. Inodes is stored in the per FileSystem inode table and is referenced through inode numbers. --Http://www.linux-tutorial.info/modules.php?name=MContent&obj=glossary&term=inode

If a Linux system often interacts with a disk or file in a Windows system, it is recommended to install Mtools, which can read and write without mounting the Windows disk format disk.

Summary:programs for accessing MS-DOS disks without mounting the disks

Description:mtools is a collection of utilities for accessing MS-DOS files.
: Mtools allow you to read, write and move around MS-DOS filesystem
: Files (normally on MS-DOS floppy disks). Mtools supports WINDOWS95
: Style long file names, OS/2 XDF disks, and 2m disks
:
: Mtools should is installed if you need to use MS-DOS disks

Shell instance (core Step):

#!/bin/bash work_directory_name=. Exclude_directory_name=python inode_of_exclude_directory_name=$ (ls-id $EXCLUDE _directory_name |awk ' {print $} ') in ode_of_current_directory_name=$ (Ls-fi $WORK _directory_name | grep \ | awk ' {print $} ') Inode_of_remove_directory_nam e=$ (echo $INODE _of_current_directory_name | sed "s/$INODE _of_exclude_directory_name//g") for INODE in $INODE _of_remove _directory_name;    Do find $WORK _directory_name-inum $INODE-exec rm-rf {} \; Done


Actual operation result (only demo effect not specific action):

650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;border-bottom:0px;border-left:0px; " Border= "0" alt= "image" Src= "http://s3.51cto.com/wyfs02/M00/5B/21/wKiom1T_1PLz5yyoAAKsa4VXG2k526.jpg" height= "462" />

--end--

This article is from "Communication, My Favorites" blog, please make sure to keep this source http://dgd2010.blog.51cto.com/1539422/1619310

Linux shell programming ideas for bulk deletion of all directories under a specified directory

Related Article

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.