Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I list one filename per output line in Linux?

Tags:

linux

shell

ls

I'm using ls -a command to get the file names in a directory, but the output is in a single line.

Like this:

.  ..  .bash_history  .ssh  updater_error_log.txt 

I need a built-in alternative to get filenames, each on a new line, like this:

.   ..   .bash_history   .ssh   updater_error_log.txt 
like image 799
fixxxer Avatar asked Oct 07 '10 22:10

fixxxer


People also ask

How do I list a few files in Linux?

The easiest way to list files by name is simply to list them using the ls command. Listing files by name (alphanumeric order) is, after all, the default. You can choose the ls (no details) or ls -l (lots of details) to determine your view.

How do I list only the filenames in Unix?

Linux or UNIX-like system use the ls command to list files and directories. However, ls does not have an option to list only directories. You can use combination of ls command, find command, and grep command to list directory names only. You can use the find command too.


1 Answers

Use the -1 option (note this is a "one" digit, not a lowercase letter "L"), like this:

ls -1a 

First, though, make sure your ls supports -1. GNU coreutils (installed on standard Linux systems) and Solaris do; but if in doubt, use man ls or ls --help or check the documentation. E.g.:

$ man ls ...        -1     list one file per line.  Avoid '\n' with -q or -b 
like image 52
Bert F Avatar answered Sep 28 '22 21:09

Bert F