

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to list one filename per output line in Linux?
There are plenty of Linux utility commands present to print the list of all the files and folders that are present in the current directory. Most commonly used are the ls and the find command.
Let’s explore a simple example where we will make use of the ls command to list all the files and the folders present in a particular directory.
Command
ls
Output
api cluster docs LICENSE Makefile.generated_files pkg staging vendor build cmd go.mod LICENSES _output plugin
On Ubuntu, we get the output in the above format, where all the names of the files and the folders are written like this.
In order to print only the file names in a single line, line by line, we need to either make use of a flag with the ls command or append another command to it.
The first command that will allow us to list one filename per output file is shown below.
Command
ls | tr “” “\n”
In the above command, we are using the tr command that is used for deleting or translating characters.
Output
api build CHANGELOG CHANGELOG.md cluster cmd code-of-conduct.md CONTRIBUTING.md docs go.mod go.sum hack LICENSE LICENSES ...
Another command that we can use is shown below.
Command
ls -a | cat
Output
api build CHANGELOG CHANGELOG.md cluster cmd code-of-conduct.md CONTRIBUTING.md docs go.mod go.sum hack LICENSE LICENSES ...
One more command is also there to print the filenames per line.
Command
ls -1
Output
api build CHANGELOG CHANGELOG.md cluster cmd code-of-conduct.md CONTRIBUTING.md docs go.mod go.sum hack LICENSE LICENSES ...
- Related Questions & Answers
- How to display the complete text one word per line in C language?
- How to match two strings that are present in one line with grep in Linux?
- How to output colored text to a Linux terminal?
- How to Save Command Output to a File in Linux?
- MySQL - How to count all rows per table in one query?
- How to Clear BASH Command Line History in Linux?
- How can we combine multiple print statements per line in Python?
- Convert XLSX to CSV in Linux with Command Line in Linux
- How to compare two sorted files line by line in the Linux system?
- How to execute Python multi-line statements in the one-line at command-line?
- How to display mean line per group in facetted graph using ggplot2 in R?
- What is the maximum number of threads per process in Linux?
- How to list the directory content in Linux?
- How to list all users in a Linux group?
- How to list running screen sessions on Linux?