Ubuntu: List all files in dir with color-coding alphabetically (dir and files separated)



Question:

I'm looking for a command to list all files in a directory with ls command.

Requirements: - Alphabetically - Folders first, then files (both alphabetically) - No timestamps or other information, just the plain names

I've been experimenting and assembled this command but it's nowhere close to what I need:

ls -la | rev | cut -d' ' -f 1| rev  

I would like an output like this (folders need to have a blue color):

folder_A  folder_B  folder_C    file_A    file_B   file_C  


Solution:1

At least with recent versions of ls, you can add the option --group-directories-first to get a listing with directories above plain files. Your ls command is probably already aliased to use --color=auto but if not, you can add that (you could use --color=always, but that may cause undesirable results if you ever use the command in a pipe). Finally, -1 causes the output to be presented in a single column. So the full command would be

ls -1 --color=auto --group-directories-first  


Solution:2

@Bruni answered with the tree command but removed it? This was actually a good answer, I dug into the man and found the solution: tree -L 1 --dirsfirst

This is the output:

.  â"œâ"€â"€ docs  â"œâ"€â"€ media  â"œâ"€â"€ node_modules  â"œâ"€â"€ src  â"œâ"€â"€ test  â"œâ"€â"€ API.md  â"œâ"€â"€ CODE_OF_CONDUCT.md  â"œâ"€â"€ CONTRIBUTING.rst  â"œâ"€â"€ LICENSE  â"œâ"€â"€ package.json  â"œâ"€â"€ README.md  â"œâ"€â"€ webpack.config.js  â""â"€â"€ yarn.lock    5 directories, 8 files  

How to get rid of the line '5 dirs, 8 files' without losing the color coding on the folders?

Edit: @steeldriver, thanks for your reply as well: ls -1 --color=auto --group-directories-first


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »