- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- 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 “” “
”
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 ...