Debian Shell: List Files

IMPORTANT: You should NOT use empty spaces within files or directories names

You can use a program to rename directories and files without empty spaces

List size files from DIR
OUTPUT: <logical_size_bytes> <physical_size_bytes> <filepath>

$ LC_ALL=C find DIR -type f -exec stat -c '%s %b %B %n' {} + 2>/dev/null | awk '{ fname=""; for (i=4; i <= NF; i++) fname=fname $i " "; print $1" "($2*$3)" "fname }'


List files from DIR with physical size >= nMB
OUTPUT: <logical_size_bytes> <physical_size_bytes> <filepath>

$ LC_ALL=C find DIR -type f -exec stat -c '%s %b %B %n' {} + 2>/dev/null | awk '{ fname=""; for (i=4; i <= NF; i++) fname=fname $i " "; print $1" "($2*$3)" "fname }' | awk '$2>=nMB*(1024^2) {print $0}'
List ALL files from DIR, No Sort, date (mtime)
STD_CMD_LS_ALL
OUTPUT:
<mode?rwx> <links> <uname> <gname> <size_bytes> <mdate YYYY-MM-DD> <mtime hh:mm:ss> <filename>
$ LC_ALL=C ls -al --time-style="+%F %T" DIR 2>/dev/null | sed '/^total /d' | awk '($8 != "." && $8 != "..") {print $0}'


List ALL files from DIR, No Sort, date (mtime)
SPE_CMD_LS
OUTPUT: <mdate YYYY-MM-DD> <mtime hh:mm:ss> <mode?rwx> <uname> <gname> <size_bytes> <filename>
$ STD_CMD_LS_ALL | awk '{ fname=""; for (i=8; i <= NF; i++) fname=fname $i " "; print $6" "$7" "$1" "$3" "$4" "$5" "fname }'


List ALL files from DIR, No Sort, date (mtime)
SPE_CMD_STAT
OUTPUT: <mdate YYYY-MM-DD> <mtime hh:mm:ss> <mode?rwx> <uname> <gname> <size_bytes> <filepath>
$ LC_ALL=C stat -c '%y %A %U %G %s %n' DIR/{*,.*} 2>/dev/null | sed -e 's;[.][0-9]\{9\} +[0-9]\{4\};;g'
List regular files/dirs/symlinks from DIR, No Sort, date (mtime)
STD_CMD_LS_FDL
OUTPUT: <mode?rwx> <links> <uname> <gname> <size_bytes> <mdate YYYY-MM-DD> <mtime hh:mm:ss> <filepath>
$ STD_CMD_LS_ALL | grep '^-\|^d\|^l'


List regular files/dirs/symlinks from DIR, No Sort, date (mtime)
SPE_CMD_LS_FDL
OUTPUT: <mdate YYYY-MM-DD> <mtime hh:mm:ss> <mode?rwx> <uname> <gname> <size_bytes> <filename>
$ STD_CMD_LS_FDL | awk '{ fname=""; for (i=8; i <= NF; i++) fname=fname $i " "; print $6" "$7" "$1" "$3" "$4" "$5" "fname }'
List regular files/dirs/symlinks from DIR, Sort: ascending date (mtime)
CMD_LS_FDL_MTIME_SORT_ASC
OUTPUT: <mdate YYYY-MM-DD> <mtime hh:mm:ss> <mode?rwx> <uname> <gname> <size_bytes> <filename>

$ SPE_CMD_LS_FDL | sort
List regular files/dirs/symlinks from DIR, Sort: descending date (mtime)
CMD_LS_FDL_MTIME_SORT_DESC
OUTPUT: <mdate YYYY-MM-DD> <mtime hh:mm:ss> <mode?rwx> <uname> <gname> <size_bytes> <filename>

$ SPE_CMD_LS_FDL | sort -r
List regular files/dirs/symlinks from DIR, Latest and Oldest (mtime)
OUTPUT: <mdate YYYY-MM-DD> <mtime hh:mm:ss> <mode?rwx> <uname> <gname> <size_bytes> <filename>

$ CMD_LS_FDL_MTIME_SORT_DESC | sed -n '1p;$p'
List regular files/dirs/symlinks from DIR, Sort: ascending filename
OUTPUT: <mdate YYYY-MM-DD> <mtime hh:mm:ss> <mode?rwx> <uname> <gname> <size_bytes> <filename>

$ SPE_CMD_LS_FDL | sort -k7
List regular files/dirs/symlinks from DIR, Sort: descending size
OUTPUT: <mdate YYYY-MM-DD> <mtime hh:mm:ss> <mode?rwx> <uname> <gname> <size_bytes> <filename>

$ SPE_CMD_LS_FDL | sort -k6n,6nr

Recursive

List ALL (not hidden) files from DIR, Recursive, No Sort, date (mtime)
Standard command ls -R without headers
OUTPUT: <mode?rwx> <links> <uname> <gname> <size_bytes> <mdate YYYY-MM-DD> <mtime hh:mm:ss> <filepath>

$ LC_ALL=C ls -lR --time-style='+%F %T' DIR 2>/dev/null | sed '/:$/,/^total [0-9]\{1,\}/d' | tr -s '\n'


List ALL (hidden) files from DIR, Recursive, No Sort, date (mtime)
Standard command ls -R without headers
OUTPUT: <mode?rwx> <links> <uname> <gname> <size_bytes> <mdate YYYY-MM-DD> <mtime hh:mm:ss> <filepath>

$ LC_ALL=C ls -alR --time-style='+%F %T' DIR 2>/dev/null | sed '/:$/,/^total [0-9]\{1,\}/d' | tr -s '\n' | awk '($8 != "." && $8 != "..") {print $0}'
List regular files/dirs/symlinks from DIR, Recursive, No Sort, date (mtime)

CMD_FIND_FDL_RECURSIVE_STAT_MTIME
OUTPUT: <mdate YYYY-MM-DD> <mtime hh:mm:ss> <mode?rwx> <uname> <gname> <size_bytes> <filepath>

$ LC_ALL=C find DIR \( -type f -o -type d -o -type l \) -exec stat -c '%y %A %U %G %s %n' {} + 2>/dev/null | sed 's;[.][0-9]\{9\} [+-][0-9]\{4\};;'


CMD_FIND_FDL_RECURSIVE_LS_MTIME
OUTPUT: <mdate YYYY-MM-DD> <mtime hh:mm:ss> <mode?rwx> <uname> <gname> <size_bytes> <filepath>

$ LC_ALL=C find DIR \( -type f -o -type d -o -type l \) -exec ls -ld --time-style="+%F %T" {} + 2>/dev/null | awk '{ fname=""; for (i=8; i <= NF; i++) fname=fname $i " "; print $6" "$7" "$1" "$3" "$4" "$5" "fname }'


CMD_LS_FDL_RECURSIVE_MTIME
OUTPUT: <mdate YYYY-MM-DD> <mtime hh:mm:ss> <mode?rwx> <uname> <gname> <size_bytes> <filename>

$ LC_ALL=C ls -alR --time-style="+%F %T" DIR 2>/dev/null | grep '^-\|^d\|^l'  | awk '($8 != "." && $8 != "..") {print $0}' | awk '{ fname=""; for (i=8; i <= NF; i++) fname=fname $i " "; print $6" "$7" "$1" "$3" "$4" "$5" "fname }'
List regular files/dirs/symlinks from DIR, Recursive, Sort: descending date (mtime)

OUTPUT: <mdate YYYY-MM-DD> <mtime hh:mm:ss> <mode?rwx> <uname> <gname> <size_bytes> <filepath>
CMD_FIND_FDL_RECURSIVE_STAT_MTIME_SORT_DESC

$ CMD_FIND_FDL_RECURSIVE_STAT_MTIME | sort -r


OUTPUT: <mdate YYYY-MM-DD> <mtime hh:mm:ss> <mode?rwx> <uname> <gname> <size_bytes> <filepath>
CMD_FIND_FDL_RECURSIVE_LS_MTIME_SORT_DESC

$ CMD_FIND_FDL_RECURSIVE_LS_MTIME | sort -r


OUTPUT: <mdate YYYY-MM-DD> <mtime hh:mm:ss> <mode?rwx> <uname> <gname> <size_bytes> <filename>
CMD_LS_FDL_RECURSIVE_MTIME_SORT_DESC

$ CMD_LS_FDL_RECURSIVE_MTIME | sort -r
List regular files/dirs/symlinks from DIR, Recursive, Latest and Oldest (mtime)

OUTPUT: <mdate YYYY-MM-DD> <mtime hh:mm:ss> <mode?rwx> <uname> <gname> <size_bytes> <filepath>

$ CMD_FIND_FDL_RECURSIVE_STAT_MTIME_SORT_DESC | sed -n '1p;$p'
$ CMD_FIND_FDL_RECURSIVE_LS_MTIME_SORT_DESC | sed -n '1p;$p'


OUTPUT: <mdate YYYY-MM-DD> <mtime hh:mm:ss> <mode?rwx> <uname> <gname> <size_bytes> <filename>

$ CMD_LS_FDL_RECURSIVE_MTIME_SORT_DESC | sed -n '1p;$p'
List regular files/dirs/symlinks from DIR, Recursive, Sort: ascending filepath

OUTPUT: <mdate YYYY-MM-DD> <mtime hh:mm:ss> <mode?rwx> <uname> <gname> <size_bytes> <filepath>

$ CMD_FIND_FDL_RECURSIVE_STAT_MTIME | sort -k7
$ CMD_FIND_FDL_RECURSIVE_LS_MTIME | sort -k7


OUTPUT: <mdate YYYY-MM-DD> <mtime hh:mm:ss> <mode?rwx> <uname> <gname> <size_bytes> <filename>

$ CMD_LS_FDL_RECURSIVE_MTIME | sort -k7
List regular files/dirs/symlinks from DIR, Recursive, Sort: descending size

OUTPUT: <mdate YYYY-MM-DD> <mtime hh:mm:ss> <mode?rwx> <uname> <gname> <size_bytes> <filepath>

$ CMD_FIND_FDL_RECURSIVE_STAT_MTIME | sort -k6n,6nr
$ CMD_FIND_FDL_RECURSIVE_LS_MTIME | sort -k6n,6nr


OUTPUT: <mdate YYYY-MM-DD> <mtime hh:mm:ss> <mode?rwx> <uname> <gname> <size_bytes> <filename>
$ CMD_LS_FDL_RECURSIVE_MTIME | sort -k6n,6nr

List/Delete Empty Directories

List Empty Directories
$ find DIR -type d -empty 2>/dev/null

Delete Empty Directories (verbose)
$ find DIR -type d -empty -exec rmdir -v {} +

List/Delete Empty Files

List Empty Files
$ find DIR -type f -empty 2>/dev/null

Delete Empty Files (verbose)
$ find DIR -type f -empty -exec rm -v {} +

List Top 100 biggest files from DIR

By default 'du' command print the real disk usage in blocks of 1024 bytes (number of used blocks) rather than the logical file' size (raw data in bytes). If you want to show the logical size use -b, --bytes equivalent to '--apparent-size --block-size=1' option.

$ man du
Display  values  are  in  units of the first available SIZE from --block-size, and the DU_BLOCK_SIZE, BLOCK_SIZE and BLOCKSIZE environment variables. Otherwise, units default to 1024 bytes (or 512 if POSIXLY_CORRECT is set).


Real disk usage in blocks (default: 1block=1024bytes)
$ LC_ALL=C find DIR -type f -exec du {} + 2>/dev/null | sort -nr | head -n100

Logical file's size in bytes
$ LC_ALL=C find DIR -type f -exec du -b {} + 2>/dev/null | sort -nr | head -n100
$ LC_ALL=C find DIR -type f -exec du -b -h {} + 2>/dev/null | sort -hr | head -n100

List Top 100 biggest files in blocks
$ LC_ALL=C find / -type f -exec du {} + 2>/dev/null | sort -nr | head -n100

Get directory size (content)

Real disk usage in blocks (default: 1block=1024bytes), hidden subdirectories excluded
$ du -s --exclude=.* DIR 2>/dev/null

Logical directory's size in bytes (approximation), hidden subdirectories excluded
$ du -sb --exclude=.* DIR 2>/dev/nul

List (sub)directories size + mtime from DIR, sort by size

Limiting Directory Tree Depth: 2

Real disk usage in blocks (default: 1block=1024bytes), hidden subdirectories excluded
$ du -d2 --time --time-style='+%F %T' --exclude=.* DIR 2>/dev/null | sort -nr

Logical file's size in bytes (approximation), hidden subdirectories excluded
$ du  -d2 -b   --time --time-style='+%F %T' --exclude=.* DIR 2>/dev/null | sort -nr
$ du  -d2 -bh --time --time-style='+%F %T' --exclude=.* DIR 2>/dev/null | sort -hr

List (sub)directories size + mtime from DIR, sort by name

Limiting Directory Tree Depth: 2

Real disk usage in blocks (default: 1block=1024bytes), hidden subdirectories excluded
$ du -d2 --time --time-style='+%F %T' --exclude=.* DIR 2>/dev/null | sort -k4

Logical file's size in bytes (approximation), hidden subdirectories excluded
$ du  -d2 -b   --time --time-style='+%F %T' --exclude=.* DIR 2>/dev/null | sort -k4
$ du  -d2 -bh --time --time-style='+%F %T' --exclude=.* DIR 2>/dev/null | sort -k4