Visit Our UNIX and Linux User Community

display only file names

Thread Tools Search this Thread
Special Forums UNIX and Linux Applications display only file names
# 1  
Old 12-27-2007
display only file names


I want to display only the file names of the ls command with a delimiter of comma.

For example:-

ls /etc/dir/N*

gives the following output

/etc/dir/N1 /etc/dir/N2 /etc/dir/N3

I want the output as N1,N2,N3,-->Here i need the final comma also.

Also, here /etc/dir is being passed as a parameter and hence will be dynamic

Please let me know how we can implement this.

# 2  
Old 12-27-2007
ls --format=commas

at least on my version of ls :
(GNU coreutils) 5.97
# 3  
Old 12-27-2007
Originally Posted by sysgate
ls --format=commas

at least on my version of ls :
he needs extra comma at the end.
# 4  
Old 12-27-2007
/usr/bin/ls | tr "\n" ","
# 5  
Old 12-31-2007
Try the "-m" switch. A "man ls" reveals:
-m     fill width with a comma separated list of entries

Then just suffix your last comma. I hope that helps some.


Previous Thread | Next Thread
Test Your Knowledge in Computers #402
Difficulty: Medium
The term 3D printing originally referred to a powder bed process employing standard and custom inkjet print heads.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Exclude certain file names while selectingData files coming in different names in a file name called

Data files coming in different names in a file name called process.txt. 1. shipments_yyyymmdd.gz 2 Order_yyyymmdd.gz 3. Invoice_yyyymmdd.gz 4. globalorder_yyyymmdd.gz The process needs to discard all the below files and only process two of the 4 file names available ... (1 Reply)
Discussion started by: dsravanam
1 Replies

2. Shell Programming and Scripting

Change the file name and copy old file content to new file names.

Hi, I have a files in a directory as below :- ls -1 mqdepth-S1STC02 proc-mq-S1STC01 proc-mq-S1STC02 proc-mq-S1STC03 Whereever i have S1STC i need to copy them into new file with file name S2STC. expected output :- ls -1 mqdepth-S2STC02 proc-mq-S2STC01 proc-mq-S2STC02... (3 Replies)
Discussion started by: satishmallidi
3 Replies

3. Shell Programming and Scripting

Split File by Pattern with File Names in Source File... Awk?

Hi all, I'm pretty new to Shell scripting and I need some help to split a source text file into multiple files. The source has a row with pattern where the file needs to be split, and the pattern row also contains the file name of the destination for that specific piece. Here is an example: ... (2 Replies)
Discussion started by: cul8er
2 Replies

4. Shell Programming and Scripting

How to split a data file into separate files with the file names depending upon a column's value?

Hi, I have a data file xyz.dat similar to the one given below, 2345|98|809||x|969|0 2345|98|809||y|0|537 2345|97|809||x|544|0 2345|97|809||y|0|651 9685|98|809||x|321|0 9685|98|809||y|0|357 9685|98|709||x|687|0 9685|98|709||y|0|234 2315|98|809||x|564|0 2315|98|809||y|0|537... (2 Replies)
Discussion started by: nithins007
2 Replies

5. UNIX for Dummies Questions & Answers

How to display only Owner and directory/sub directory names under particular root

hai, I am new to Unix, I have a requirement to display owner name , directory or sub directory name, who's owner name is not equal to "oasitqtc". (here "oasitqtc" is the owner of the directory or sub directory.) i have a command (below) which will display all folders and sub folders, but i... (6 Replies)
Discussion started by: gagan4599
6 Replies

6. Solaris

using ls -ltr : display only last four file names

Hi , Server details – Machine hardware: sun4u OS version: 5.9 Processor type: sparc Hardware: SUNW,Sun-Fire-880 When I put ls –ltr command I get – /users/testuser> ls -ltr -rw-rw-r-- 1 testuser dba 76 Jan 13 2009 ftp.scr -rwxr-xr-x 1... (6 Replies)
Discussion started by: rahulbahulekar
6 Replies

7. Shell Programming and Scripting

Searching for file names in a directory while ignoring certain file names

Sun Solaris Unix Question Haven't been able to find any solution for this situation. Let's just say the file names listed below exist in a directory. I want the find command to find all files in this directory but at the same time I want to eliminate certain file names or files with certain... (2 Replies)
Discussion started by: 2reperry
2 Replies

8. Shell Programming and Scripting

Shell Script to display function names (called & defined) in a C++ Source Code

Hello to all, I am looking for a way to display only the names of function (calls & definition) of a C++ source code.There is already a post related to this, but the script is to find the functions using a specific variable, and the replies are not that convincing since they cannot be used for... (2 Replies)
Discussion started by: frozensmilz
2 Replies

9. Shell Programming and Scripting

Reading file names from a file and executing the relative file from shell script

Hi How can i dynamically read files names from a list file and execute them from a single shell script. Please help its urgent Thanks in Advance (4 Replies)
Discussion started by: anushilrai
4 Replies

10. Shell Programming and Scripting

Display file names that are being deleted

The print command lists the path of the file being found. I want the output as the file name along with the date that particular files were created i.e similar to a ls -l command. I am using find to list all the files that satisfy the selection criteria and delete them using rm. Can I display... (2 Replies)
Discussion started by: theguy16
2 Replies

Featured Tech Videos