Wednesday, May 15, 2024
18
rated 0 times [  18] [ 0]  / answers: 1 / hits: 5642  / 3 Years ago, wed, october 27, 2021, 1:55:47

Run Command ls on Current Directory and get the output:



$ ls
Applications Documents Library Music Public
Desktop Downloads Movies Pictures


I'd like to enumerate them like:



1. Applications
2. Desktop
3. Documents
4. Downloads
5. Library
6. Movies
7. Music
8. Pictures
9. Public


This could be achieved using less in an intermediate way



ls | less -N


How to enumerate them in a straightforward way?


More From » command-line

 Answers
0

Or simply do:



ls -b |nl -s '. ' -w 1
1. a file with nonewline
2. a file with
newline
3. a file with space
4. afile


from man nl:



-s, --number-separator=STRING
add STRING after (possible) line number
-w, --number-width=NUMBER
use NUMBER columns for line numbers

[#8774] Thursday, October 28, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
velelf

Total Points: 395
Total Questions: 115
Total Answers: 107

Location: Sudan
Member since Mon, Jun 1, 2020
4 Years ago
;