Views:
22,287β
Votes: 3β
Tags:
command-line
bash
Link:
π See Original Answer on Ask Ubuntu β§ π
URL:
https://askubuntu.com/q/1186028
Title:
Is it possible to list only the filename and size for each file in a directory using only options found in the ls utility?
ID:
/2019/11/04/Is-it-possible-to-list-only-the-filename-and-size-for-each-file-in-a-directory-using-only-options-found-in-the-ls-utility_
Created:
November 4, 2019
Upload:
September 15, 2024
Layout: post
TOC:
false
Navigation: false
Copy to clipboard: false
Itβs impossible to do with the ls
command by itself. You can do it by piping ls -l
output to other commands or with a totally different command like find
as others have answered.
The tree
command gives another alternative:
rick@alien:~/askubuntu$ tree -h
.
βββ [8.8K] aptfielout
βββ [1.8K] aptfilein
βββ [ 435] aptfileout
(... SNIP ...)
βββ [ 38] script
βββ [4.0K] subdir-A
βΒ Β βββ [ 14] 1.mp4
βΒ Β βββ [ 14] 2.mp4
βΒ Β βββ [ 14] 3.mp4
βΒ Β βββ [4.0K] JSON
βΒ Β βββ [4.0K] JSON
βΒ Β βββ [ 7] 1.json
βΒ Β βββ [ 7] 2.json
βΒ Β βββ [ 7] 3.json
βΒ Β βββ [ 7] 4.json
(... SNIP ...)
βββ [1.5K] ttlus
βββ [1.3K] ttlus~
7 directories, 57 files
The tree
option passed is -h
for human readable size. For size in exact bytes pass -s
.