Visit Our UNIX and Linux User Community

How to take the filenames from a directory and store into a file??

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to take the filenames from a directory and store into a file??
# 8  
Old 08-08-2013
ya it works, thanks.. you have used the path a delimeter. but thats fine. thanks
# 9  
Old 08-08-2013
since you know that your *.ksh files are not directories, you can shorten it further ...
cd /dir
ls *.ksh

ls /dir/*.ksh | sed "s/\/dir\///"

# 10  
Old 08-08-2013
for  file in *
        [ "$file" = "*" ] && continue # no files
        [ "$0" = "$file" ] && continue # myself
        [ -d "$file" ] && continue  # dir
        [ -f "$file" ] && echo "$file"  # regular file
        # [ ....   # other testing what you maybe need / are useful
done > result.txt

Last edited by kshji; 08-08-2013 at 01:16 PM..
# 11  
Old 08-08-2013
Originally Posted by kshji
for  file in *
        [ "$0" = "$file" ] && continue # myself
        [ -d "$file" ] && continue  # dir
        [ -f "$file" ] && echo "$file"  # regular file

shorter version ...
for file in *
    [ -f $file ] && echo $file

# 12  
Old 08-08-2013
Try also
find /home/ -name \*.txt -printf "%f\n"

Previous Thread | Next Thread
Test Your Knowledge in Computers #368
Difficulty: Medium
The Open Group released the Single UNIX Specification Version 2 in 1987.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to manipulate a text file and store each version for every changes in a directory?

I attached both picture!Aoomvi55MLAQh1jODfUxa-xurns_ and *.txt file of a sample work file. In this file Reactions which only start with "r1f", "r2f", "r3f"......and so on. And for each reaction the reaction rates is situated couple of lines later with a "+" sign. For each... (1 Reply)
Discussion started by: Atta
1 Replies

2. UNIX for Beginners Questions & Answers

How do I custom sort the files in a directory using the filenames in a text file.?

Hi all, (5 Replies)
Discussion started by: KMusunuru
5 Replies

3. Shell Programming and Scripting

Store filenames for wget in bash

I have a bash that downloads a list of files as a text file using wget. What I now need to do is store those files names and pass them to a download call also using wget. List.txt in /home directory FilterDuplicates.html file1.bam file2.bam file3.bam file1.vcf.gz file2.vcf.gz... (3 Replies)
Discussion started by: cmccabe
3 Replies

4. Shell Programming and Scripting

There are multiple filenames in the directory.How to return the the lastest files for each file name

there are mutiple file nams in the directory. How to return the the lastest files for each file name. ex. abc1234_050201 abc1234_050206 abc1234_050208 xyz34_050204 xyz34_050210 xyz34_050218 thanks (4 Replies)
Discussion started by: grand_sam
4 Replies

5. Shell Programming and Scripting

print all filenames in directory with path to another file

hi, i have a directory at /path/unix with the following files 1.txt 2.txt 3.txt 4.txt I want to make another file called filenames.txt at a different location called /path/home. So, my output file would be /path/home/filenames.txt with contents /path/unix/1.txt... (1 Reply)
Discussion started by: jacobs.smith
1 Replies

6. Shell Programming and Scripting

How to get filenames in a directory and write them in to a file?

I need to get the names of files which are starting with a string testfile. Also i want to create a XML file in the same location and write these file names into the XML. Ex: <path> <dir> <file>testfile1</file> </dir> <dir> <file>testfile2</file> </dir>... (4 Replies)
Discussion started by: vel4ever
4 Replies

7. Shell Programming and Scripting

New file should store all the 7 existing filenames and their record counts and ftp th

Hi, I need help regarding below concern. There is a script and it has 7 existing files(in a path say,. usr/appl/temp/file1.txt) and I need to create one new blank file say “file_count.txt” in the same script itself. Then the new file <file_count.txt> should store all the 7 filenames and... (1 Reply)
Discussion started by: pr293
1 Replies

8. Shell Programming and Scripting

Change all filenames in a directory

I have a directory of files and each file has a random 5 digit string at the beginning that needs to be removed. Plus, there are some files that will be identically named after the 5 digit string is removed and I want those eliminated or moved. any ideas? (17 Replies)
Discussion started by: crumb
17 Replies

9. Shell Programming and Scripting

Replacing string in all instances (both filenames and file contents) in a directory

Hi, I have a set of files stored in a single directory that I use to set parameters for a physics code, and I would like to streamline the process of updating them all when I change a parameter. For instance, if the files are called A2000p300ini, A2000p300sub, A2000p300run, and the text in each... (3 Replies)
Discussion started by: BlueChris
3 Replies

10. Shell Programming and Scripting

concatenating the filenames in a directory

hi all, I have a requirement where in i have to read all the filenames based on a pattern from a directory and concatenate all these file names and write it to another file. i am using the following code to do this var1='' for filename in $_DIR/${FILE_NAME}* do if if then... (7 Replies)
Discussion started by: nvuradi
7 Replies

Featured Tech Videos