Source all files in a directory


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Source all files in a directory
# 1  
Old 05-10-2011
Source all files in a directory

Hi everyone,

Is there an efficient way to source all of the files contained in a directory? Theoretically I could create a FOR loop and successively source each file, but I just wanted to check if there was a cleaner method.

Thanks!

Mike
# 2  
Old 05-10-2011
Question

Can you define 'source all files'?
# 3  
Old 05-10-2011
Quote:
Originally Posted by msb65
Hi everyone,

Is there an efficient way to source all of the files contained in a directory? Theoretically I could create a FOR loop and successively source each file, but I just wanted to check if there was a cleaner method.
A for-loop's pretty efficient, really.

That's the method I usually see done in init scripts and the like. Just for FILE in /etc/env.d/* ; do source $FILE ; done As a bonus it allows them to exclude certain names, they often do something like for FILE in /etc/env.d/[0-9][0-9]-* and only run files like 00-servicename.

I suspect there's not a short form because that would deprive you of the ability to give a sourced script parameters.
# 4  
Old 05-10-2011
If you mean "Source" as listing the files in the directory, then use ls -lrt, and if you want to list all including the subdirectories then use ls -lRt
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Cd \bad-directory ; source junk.1 logs me off!

Dear Gentle Folk, I thought I knew unix/bash etc. The compound statement USING TCSH! cd /lkjsdf ; source junk.1 completes and then logs me off IF the cd directory does not exist. It works fine if the directory does exist. Why is this and how do I fix it. It doesn't matter what... (1 Reply)
Discussion started by: homerwsmith
1 Replies

2. Shell Programming and Scripting

Move directory recursive and leave symlinks at source

Looking for a script or command to - Move a very large directory with tens of thousands of files and sub-directories recursively (filenames can include spaces) and replace with symlinks pointing to the new location at the same time so there is no downtime Looking for speed + safety :o (5 Replies)
Discussion started by: carnagel
5 Replies

3. UNIX for Beginners Questions & Answers

Move directory with rsync and delete from source

I need a rsync command which will exclude certain files and directories from source and copy the rest. I got this command working, sudo rsync -avzh --exclude 'bin' --exclude 'braintree' --exclude 'colinmollenhour' --exclude 'composer' --exclude 'doctrine' --exclude 'fabpot' --exclude... (2 Replies)
Discussion started by: Siddheshk
2 Replies

4. UNIX for Dummies Questions & Answers

How to move gz files from one source directory to destination directory?

Hi All, Daily i am doing the house keeping in one of my server and manually moving the files which were older than 90 days and moving to destination folder. using the find command . Could you please assist me how to put the automation using the shell script . ... (11 Replies)
Discussion started by: venkat918
11 Replies

5. Post Here to Contact Site Administrators and Moderators

How to count successfully copy files source to target location with check directory in Linux?

Hi guys...please any one help me .... how to copy files from source to target location if 5 files copied successfully out of 10 files then implement success=10 and if remaining 5 files not copied successfully then count error=5 how to implement this condition with in loop i need code linux... (0 Replies)
Discussion started by: sravanreddy
0 Replies

6. Shell Programming and Scripting

need a shell script to extract the files from source file and check whether those files existonserve

Hi, I am new to shell scripting.Please help me on this.I am using solaris 10 OS and shell i am using is # echo $0 -sh My requirement is i have source file say makefile.I need to extract files with extensions (.c |.cxx |.h |.hxx |.sc) from the makefile.after doing so i need to check whether... (13 Replies)
Discussion started by: muraliinfy04
13 Replies

7. Shell Programming and Scripting

Move all files from source to destination directory based on the filename

Move all files starting with a specific name to different directory. This shell script program should have three parameters File Name Source Directory Destination Directory User should be able to enter ‘AB_CD*' in file name parameter. In this case all the files starting with AB_CD will... (1 Reply)
Discussion started by: chetancrsp18
1 Replies

8. UNIX for Advanced & Expert Users

Compiling Samba from Source on AIX, Active Directory, LDAP, Kerberos

Hello, I asked this question in the AIX subforum but never received an answer, probably because the AIX forum is not that heavily trafficked. Anyway, here it is.. I have never had any issues like this when compiling applications from source. When I try to compile samba-3.5.0pre2, configure runs... (9 Replies)
Discussion started by: raidzero
9 Replies

9. UNIX for Advanced & Expert Users

Why rsync deletes source directory?

Hi I have a strange problem. Sometimes when I execute the below command something wierd happens. rsync -avz -e ssh travegre@travegre.net: ../travegre.net/ the folder named "hm" that is held in travegre.net and is coppied along with all the other folders and data at travegre.net, gets... (1 Reply)
Discussion started by: travegre
1 Replies
Login or Register to Ask a Question