Created
October 8, 2013 10:53
-
-
Save nobucshirai/6882950 to your computer and use it in GitHub Desktop.
A shell script for removing empty files.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # $Id: emrm.sh,v 1.4 2012-10-13 09:13:03+09 shirai Exp $ | |
| # EMPTY REMOVE | |
| list=(`ls`) | |
| # MAIN | |
| main(){ | |
| if [ $# = 0 ];then | |
| select_emrm | |
| elif [ "$1" = "all" ];then | |
| all_emrm | |
| else | |
| ask_emrm | |
| fi | |
| } | |
| # MODE SELECT | |
| select_emrm(){ | |
| # REMOVE SELECTED EMPTY FILES | |
| echo "---> select files to remove" | |
| for file in ${list[@]} | |
| do | |
| if [ ! -s $file ];then | |
| while ((check==0)) | |
| do | |
| echo -n "remove $file (y/n)? " | |
| read yORn | |
| if [ "$yORn" = "y" ];then | |
| diae rm $file | |
| check=1 | |
| elif [ "$yORn" = "n" ];then check=1 | |
| else | |
| echo " PLEASE INPUT y(yes) or n(no)" | |
| fi | |
| done | |
| check=0 | |
| fi | |
| done | |
| } | |
| all_emrm(){ | |
| # REMOVE ALL EMPTY FILES | |
| echo "---> remove all empty files" | |
| for file in ${list[@]} | |
| do | |
| if [ ! -s $file ];then | |
| diae rm $file | |
| fi | |
| done | |
| } | |
| ask_emrm(){ | |
| # REMOVE BY HANDS | |
| echo "---> remove by hand" | |
| for file in $@ | |
| do | |
| if [ ! -s $file ];then | |
| diae rm $file | |
| else | |
| echo " $file is not empty." | |
| fi | |
| done | |
| } | |
| # FUNCTION | |
| diae(){ | |
| echo $@ | |
| $@ | |
| } | |
| # SCRIPT START ! | |
| main $@ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment