License

Copyright (C) 2008-2017 Oliver Bohlen.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.

A copy of the license is included in the section entitled "GNU Free Documentation License".

Introduction

This documentation comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law.

Howto: Sort files alphabetical for Gentoo Linux

Here a script which sorts file alphabetical. So a file (or directory) beginning with an "a" (e.g. apple) will be moved into the directory "a" and so on.
Please be careful with it. This process can not be undone.

If you want to use this solution you need the following howto(s) finished:

Changes in /gtc/test/etc/thinclient/scripts/az

File permissions:
Owner: root
Group: root
Permissions: -rwxr-xr-x

Click here for a download of the complete file: /gtc/test/etc/thinclient/scripts/az

Changed on 05.05.10
Issued by olli
Beginning line 2

This is a small script which sorts files (or directories) in directories called a-z and 0-9

#!/bin/bash
if [ -z "$1" ]
then
 echo "No directory argument"
 exit 1
fi

cd "$1" || exit 1

# Sort alphabetical
for i in A B C D E F G H I J K L M N O P Q R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 9 
do
 ls -1d $i?* 2>/dev/null | while read j
 do
  mkdir -p "$i"
  if [ -d "$i/$j" ]
  then
   cp -lr "$j"/* "$i/$j"/ && rm -r "$j"
  else
   echo "mv \"$j\" \"$i\"/"
   mv "$j" "$i"/
  fi
 done
done

# Sort non-Alphabetical Characters to _
if [ -n "`ls ??* 2>/dev/null `" ]
then
 mkdir -p _
 mv ??* _
fi

# Ignore Case sensitive
if [ "$2" = "-i" ]
then
 for i in a b c d e f g h i j k l m n o p q r s t u v w x y z
 do
  j=`echo "$i" | awk '{$1=toupper($1);print}'`
  if [ -d "$i" ]
  then
   mv "$i"/* "$j"/
   rmdir "$i"
  fi
 done
fi


Changes in /usr/local/bin/az

File permissions:
Owner: root
Group: root
Permissions: -rwxr-xr-x

Click here for a download of the complete file: /usr/local/bin/az

Changed on 05.05.10
Issued by olli
Beginning line 2

This is a small script which sorts files (or directories) in directories called a-z and 0-9

#!/bin/bash
if [ -z "$1" ]
then
 echo "No directory argument"
 exit 1
fi

cd "$1" || exit 1

# Sort alphabetical
for i in A B C D E F G H I J K L M N O P Q R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 9 
do
 ls -1d $i?* 2>/dev/null | while read j
 do
  mkdir -p "$i"
  if [ -d "$i/$j" ]
  then
   cp -lr "$j"/* "$i/$j"/ && rm -r "$j"
  else
   echo "mv \"$j\" \"$i\"/"
   mv "$j" "$i"/
  fi
 done
done

# Sort non-Alphabetical Characters to _
if [ -n "`ls ??* 2>/dev/null `" ]
then
 mkdir -p _
 mv ??* _
fi

# Ignore Case sensitive
if [ "$2" = "-i" ]
then
 for i in a b c d e f g h i j k l m n o p q r s t u v w x y z
 do
  j=`echo "$i" | awk '{$1=toupper($1);print}'`
  if [ -d "$i" ]
  then
   mv "$i"/* "$j"/
   rmdir "$i"
  fi
 done
fi


Please send a feedback to: doc<at>gabosh.net

Howto listing
File Index

Here you can find the official Gentoo Linux Forums where you can find a lot of answers.

Here a link to the official Gentoo Linux Homepage.

Edit Howto

About / Impressum

Click here for About / Impressum

Wishlist

If you want to support my work you can find my Amazon whishlist here