Here's a working example with the python code you cited:
Usage: tree.py -f [file limit] <directory>
If a number is specified for -f [file limit] then ... <additional files> is printed and the other files are skipped. Additional directories should not be skipped however. If the file limit is set to 10000 (default) this acts as no limit
#! /usr/bin/env python
# tree.py
#
# Written by Doug Dahms
# modified by glallen @ StackExchange
#
# Prints the tree structure for the path specified on the command line
from os import listdir, sep
from os.path import abspath, basename, isdir
from sys import argv
def tree(dir, padding, print_files=False, limit=10000):
print padding[:-1] + '+-' + basename(abspath(dir)) + '/'
padding = padding + ' '
limit = int(limit)
files = []
if print_files:
files = listdir(dir)
else:
files = [x for x in listdir(dir) if isdir(dir + sep + x)]
count = 0
for file in files:
count += 1
path = dir + sep + file
if isdir(path):
print padding + '|'
if count == len(files):
tree(path, padding + ' ', print_files, limit)
else:
tree(path, padding + '|', print_files, limit)
else:
if limit == 10000:
print padding + '|'
print padding + '+-' + file
continue
elif limit == 0:
print padding + '|'
print padding + '+-' + '... <additional files>'
limit -= 1
elif limit <= 0:
continue
else:
print padding + '|'
print padding + '+-' + file
limit -= 1
def usage():
return '''Usage: %s [-f] [file-listing-limit(int)] <PATH>
Print tree structure of path specified.
Options:
-f Print files as well as directories
-f [limit] Print files as well as directories up to number limit
PATH Path to process''' % basename(argv[0])
def main():
if len(argv) == 1:
print usage()
elif len(argv) == 2:
# print just directories
path = argv[1]
if isdir(path):
tree(path, ' ')
else:
print 'ERROR: \'' + path + '\' is not a directory'
elif len(argv) == 3 and argv[1] == '-f':
# print directories and files
path = argv[2]
if isdir(path):
tree(path, ' ', True)
else:
print 'ERROR: \'' + path + '\' is not a directory'
elif len(argv) == 4 and argv[1] == '-f':
# print directories and files up to max
path = argv[3]
if isdir(path):
tree(path, ' ', True, argv[2])
else:
print 'ERROR: \'' + path + '\' is not a directory'
else:
print usage()
if __name__ == '__main__':
main()
When run, it should produce output similar to:
user@host /usr/share/doc $ python /tmp/recipe-217212-1.py -f 2 . | head -n 40
+-doc/
|
+-libgnuradio-fft3.7.2.1/
| |
| +-copyright
| |
| +-changelog.Debian.gz
|
+-libqt4-script/
| |
| +-LGPL_EXCEPTION.txt
| |
| +-copyright
| |
| +-... <additional files>
|
+-xscreensaver-gl/
| |
| +-copyright
| |
| +-changelog.Debian.gz
| |
| +-... <additional files>
One can use tree --filelimit=N to limit number of subdirectories/file to display. Unfortunately, this will not open directory which has more than N sub-directories and files.
For simple cases, when you have multiple directories and most have too many(say > 100) files, you can use tree --filelimit=100.
.
βββ A1
β βββ A2
β βββ B2
β βββ C2 [369 entries exceeds filelimit, not opening dir]
β βββ D2 [3976 entries exceeds filelimit, not opening dir]
βββ B1
β βββ A2
β βββ A3.jpeg
β βββ B3.png
βββ C1.sh
Note, if A1/C2 has a sub-directory A3, it will not be shown.
P.S. This is not a complete solution but will be quicker for few.
Use options -r and -e:
btrfs qgroup show -pcre /path
I created a simple script that will show the quota limit for each sub-volume in the specified path and the used space too. The syntax is pretty simple:
./quota.sh path
To print the used space for all sub-volumes use the -a flag:
./quota.sh path -a
Don't forget to add execution permissions to the script.
Script:
#! /bin/sh
volumes=$(btrfs subvolume list $1 | cut -d " " -f 9 )
snapshots=$(btrfs subvolume list -s $1 | cut -d " " -f 14 )
regsnap=$(echo $snapshots | sed 's/ /,/g')
normalv=$(echo $volumes | sed "s/\($regsnap\)//g" )
if [ ! -z "$snapshots" ] ; then
echo SNAPSHOTS
for p in $snapshots; do
quot=$(btrfs qgroup show -rF $1/$p | tail -1)
if [ -z $2 ]; then
(echo $quot | grep -q none) || echo $p $quot
else
[ "$2" == "-a" ] && echo $p $quot
fi
done
fi
if [ ! -z "$normalv" ] ; then
echo SUBVOLUMES
for p in $normalv; do
quot=$(btrfs qgroup show -rF $1/$p | tail -1)
if [ -z $2 ]; then
(echo $quot | grep -q none) || echo $p $quot
else
[ "$2" == "-a" ] && echo $p $quot
fi
done
fi
It will print first the traditional sub-volumes and below the snapshots volumes. Sample output:
SNAPSHOTS
apple 0/258 1.32MiB 16.00KiB 20.00MiB
SUBVOLUMES
citrus/orange 0/256 1.32MiB 16.00KiB 20.00MiB
If you're forced to use ext3, then using LVM is probably your best solution. Create a new filesystem per project. That would look something like this:
# Create a 10g filesystem for "project1" in volume group "vg0"
lvcreate -L 10g -n project1 vg0
# Create an ext3 filesystem.
mke2fs -j /dev/vg0/project1
# Mount it (obviously you would want this in /etc/fstab)
mount /dev/vg0/project1 /projects/project1
Growing the project filesystems is easy:
# Add 2GB to the volume.
lvextend -L +2g /dev/vg0/project1
# Grow the filesystem.
resize2fs /dev/vg0/project1
If you don't rely on group permissions, you can use a different UNIX group for each "quota directory", then set sgid bit on each directory (so created files and directories will belong to the group of the directory instead of the primary group of the creator user), and use group quotas.