LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-30-2015, 05:08 AM   #1
hack3rcon
Senior Member
 
Registered: Jan 2015
Posts: 1,124

Rep: Reputation: Disabled
Post Command for Generate Files name in a Directory to TXT file.


Hello.
How can I Generate the files name in a directory into a TXT file? I mean is create a list if files.

Tnx.
 
Old 01-30-2015, 05:21 AM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,395

Rep: Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395
Do you mean create list of filenames into another file?
Code:
ls >file.txt
Read these
http://rute.2038bug.com/index.html.gz
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
http://www.tldp.org/LDP/abs/html/
 
Old 01-31-2015, 07:44 AM   #3
hack3rcon
Senior Member
 
Registered: Jan 2015
Posts: 1,124

Original Poster
Rep: Reputation: Disabled
Thank you. I know it but I need a program that create a collection for me like Movies List and PDF files. I input a directory with various extension and it create a list by file type.
 
Old 01-31-2015, 08:55 AM   #4
veerain
Senior Member
 
Registered: Mar 2005
Location: Earth bound to Helios
Distribution: Custom
Posts: 2,524

Rep: Reputation: 319Reputation: 319Reputation: 319Reputation: 319
Here it is:

Code:
for f in `ls | grep -o -E '\..+$' | sort -u`; do ls *"$f" > "/tmp/list$f"; done
 
Old 01-31-2015, 09:23 AM   #5
yancek
LQ Guru
 
Registered: Apr 2008
Distribution: PCLinux, Slackware
Posts: 7,286

Rep: Reputation: 1384Reputation: 1384Reputation: 1384Reputation: 1384Reputation: 1384Reputation: 1384Reputation: 1384Reputation: 1384Reputation: 1384Reputation: 1384
Take a look at the link below which shows a method using the find command about half way down the page.

http://stackoverflow.com/questions/3...ories-in-shell

Code:
find Downloads -type f \( -iname "*.pdf" -o -iname "*.png" -o -iname "*.txt" \) > files.txt
The code above is run from /home/user, you need to put the actual path to your directory where you see Downloads above. It will then output a list of files with the extensions .pdf, .png and .txt to a files.txt file in the directory from which you ran the command. You will need to make the appropriate changes to fit your needs.

Last edited by yancek; 01-31-2015 at 09:25 AM.
 
Old 02-01-2015, 08:36 AM   #6
hack3rcon
Senior Member
 
Registered: Jan 2015
Posts: 1,124

Original Poster
Rep: Reputation: Disabled
Thumbs up

Quote:
Originally Posted by veerain View Post
Here it is:

Code:
for f in `ls | grep -o -E '\..+$' | sort -u`; do ls *"$f" > "/tmp/list$f"; done

Thanks a lot.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating a CMakeLists.txt file in every directory that has Autoconf files Geist Linux - General 0 03-21-2014 01:44 PM
[SOLVED] awk question - read in txt files, offset data by given amount, output new txt files pomico Programming 19 09-17-2012 11:43 AM
Copy the contents of a txt file to other txt files (with similar names) by cp command TheIndependentAquarius Linux - Newbie 7 07-03-2010 12:54 AM
Bash, how do I test for *.txt files in a directory with IF? severian23 Programming 7 11-04-2004 09:47 AM
Perl Script Reading a txt file and generate html to be published! kofi Linux - Software 1 09-22-2003 05:12 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:06 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration