LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Closed Thread
  Search this Thread
Old 10-15-2016, 11:04 AM   #1
TheEngineer
LQ Newbie
 
Registered: Oct 2006
Location: UK
Distribution: MacOS , Redhat
Posts: 17

Rep: Reputation: 0
Unix shell script/command help needed...


Hi all.

I need some help with the following scenario...


I have this directory structure:

/Dir 1/Dir 2/Dir 3/Dir X/Dir 5/Dir 6/files

/Dir 1/Dir 2/Dir 3/Dir Y/Dir 5/Dir 6/files

/Dir 1/Dir 2/Dir 3/Dir Z/Dir 5/Dir 6/files


Is there a way to list all the files in each path without me having to type the whole path out into the terminal?


I know ls -1 /Dir 1/Dir 2/Dir 3 will list the directories Dir X, Dir Y and Dir Z on separate lines (with no recursion).


Is there a way to insert each separate item that is listed into a find command to search for a file of type *.txt for example?


eg: find /Dir 1/Dir 2/Dir 3/ITEM/Dir 5/Dir 6/ -name *.txt

where ITEM would be the output from the ls command.


All the directory paths have a common path up to Dir X and then the remainder of the path is also common too.


Thanks in advance.
 
Old 10-15-2016, 11:24 AM   #2
sag47
Senior Member
 
Registered: Sep 2009
Location: Raleigh, NC
Distribution: Ubuntu, PopOS, Raspbian
Posts: 1,899
Blog Entries: 36

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
duplicates http://www.linuxquestions.org/questi...ed-4175591472/
 
Old 10-15-2016, 03:40 PM   #3
c0wb0y
Member
 
Registered: Jan 2012
Location: Inside the oven
Distribution: Windows
Posts: 421

Rep: Reputation: 74
Code:
find '/Dir 1/Dir 2/Dir 3' -name '*.txt'
so no need to specify <ITEM> as search query will descend to any directories under 'Dir 3' anyway.
 
Old 10-15-2016, 04:30 PM   #4
onebuck
Moderator
 
Registered: Jan 2005
Location: Central Florida 20 minutes from Disney World
Distribution: SlackwareŽ
Posts: 13,925
Blog Entries: 44

Rep: Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159
Moderator response

Please post your thread in only one forum. Posting a single thread in the most relevant forum will make it easier for members to help you and will keep the discussion in one place. This thread is being closed because it is a duplicate of http://www.linuxquestions.org/questi...ed-4175591472/
 
  


Closed Thread



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Unix shell script/command help needed... TheEngineer Linux - Newbie 9 10-15-2016 12:15 PM
How to pass command line arguments from one shell script to another shell script VijayaRaghavanLakshman Linux - Newbie 5 01-20-2012 09:12 PM
How to visit a url using a shell script or unix command Keerthi Shankar Pattabhi Linux - Newbie 5 08-02-2011 11:00 AM
UNIX shell script: split long command on multiple lines loopoo Linux - Newbie 2 10-23-2006 09:34 AM
Problem with shell script using a variable from a unix command. abefroman Programming 1 05-10-2006 02:14 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 05:53 PM.

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
Open Source Consulting | Domain Registration