ls
:
The easy solution for interactive use is "ell ess minus ell" where column #5 contains the file size in bytes
ls -l *.txt
or if you want 'human readable format'
ls -lh *.txt
You find more details in man ls
. Please notice that ls
is not recommended for automation (in shellscripts etc).
find
:
Your question was vague, so here is a list of commands to find and print text files with the extension txt
. Pick the format you want or some combination. You find more details in man find
.
The primitive list with only the names of text files in the current directory excluding for example directories and symbolic links but including files in subdirectories
find . -type f -name "*.txt"
A list with size (bytes) and file names
find . -type f -name "*.txt" -printf "%9s '%p'\n"
A list with sizes and names sorted according to size
find . -type f -name "*.txt" -printf "%9s '%p'\n" | sort -n
A list with sizes and names sorted according to name
find . -type f -name "*.txt" -printf "%9s '%p'\n" | sort -k2
A list excluding files in subdirectories with sizes and names sorted according to size
find . -maxdepth 1 -type f -name "*.txt" -printf "%9s '%p'\n" | sort -n
The corresponding list where the dot and extension is removed from each file name
find . -maxdepth 1 -type f -name "*.txt" -printf "%9s '%p'\n"|sed "s/\.txt'$/'/"|sort -n
The corresponding list where the name of the starting-point under which the file was found removed
find . -maxdepth 1 -type f -name "*.txt" -printf "%9s '%P'\n"|sed "s/\.txt'$/'/"|sort -n