Have you considered using an absolute pathname on the find (i.e. find "$PWD" ... instead of find . ...) and moving to the directory in which you want the files to be created before invoking mseed2sac instead of moving all of the files mseed2sac creates after it is done?
Your script will run faster and use fewer system resources if you change:
to:
And, I assume that you will also actually invoke mseed2sac and mkdir instead of just including them in comments and echo statements. (This also applies to mv if you decide to ignore my first suggestion above.)
This User Gave Thanks to Don Cragun For This Post:
That's correct. I am just doing echo to check the commands created are correct so
when I happy with how things are set up, I can then invoke them properly.
---------- Post updated at 05:12 PM ---------- Previous update was at 04:24 PM ----------
Should I do `cd` to the directory so that I can run `mseed2sac`? I am not following
very well how to use `find $pwd`
I give here some of the output. There are lot of stations
---------- Post updated at 05:55 PM ---------- Previous update was at 05:12 PM ----------
Quote:
Originally Posted by Don Cragun
Have you considered using an absolute pathname on the find (i.e. find "$PWD" ... instead of find . ...) and moving to the directory in which you want the files to be created before invoking mseed2sac instead of moving all of the files mseed2sac creates after it is done?
Your script will run faster and use fewer system resources if you change:
to:
And, I assume that you will also actually invoke mseed2sac and mkdir instead of just including them in comments and echo statements. (This also applies to mv if you decide to ignore my first suggestion above.)
I get the same results
as doing
How is one faster than the latter? What does `dirname` and `basename` work?
I did a test and variable substitution is faster as you say.
That's correct. I am just doing echo to check the commands created are correct so
when I happy with how things are set up, I can then invoke them properly.
---------- Post updated at 05:12 PM ---------- Previous update was at 04:24 PM ----------
Should I do `cd` to the directory so that I can run `mseed2sac`? I am not following
very well how to use `find $pwd`
First, I suggested using find $PWD ...; not find $pwd .... Your shell sets PWD to an absolute pathname of your current working directory when it starts up and updates it every time you successfully execute a cd command. (When you successfully execute cd, your shell also sets OLDPWD to an absolute pathname of the directory you were in before you executed cd.)
There is no reason to think that the value assigned to the variable pwd will have any value assigned to it unless your script does that. And $pwd will not be updated by your shell when you execute cd!
Your code does the following:
read a relative pathname of an input file to be processed from /tmp/wrk,
runs mseed2sac,
calculates the directory where the output file(s) should be located,
create that directory (if it doesn't already exist), and
move the output file(s) to that directory.
My suggestion is to change that to:
read an absolute pathname of an input file to be processed from /tmp/wrk,
calculate the directory where the output file(s) should be located,
create that directory (if it doesn't already exist),
cd to that directory, and
run mseed2sac.
Note that no mv is included in the above suggestion.
This User Gave Thanks to Don Cragun For This Post:
How is one faster than the latter? What does `dirname` and `basename` work?
I did a test and variable substitution is faster as you say.
Your code uses command substitution (i.e., $(command arguments)). That involves forking a shell, executing command, waiting for command to finish, reading the results from command, and assigning them to a variable.
My code uses variable expansion which is done entirely in the shell. The fork and exec done by command substitution is a very slow shell operation. The string manipulations done by variable expansions are much faster.
This User Gave Thanks to Don Cragun For This Post:
Hello,
I'm a first time poster looking for help in scripting a task in my daily routine. I am new in unix but i am attracted to its use as a mac user.
Bear with me...
I have several files (20) that I manually drag via the mouse into several named directories over a network. I've used rsync... (14 Replies)
hi,
i have a requirement to delete all the files from all the directories except some specific directories like archive and log.
for example:
there are following directories such as
A B C D Archive E Log F
which contains some sub directories and files. The requirement is to delete all the... (7 Replies)
Hi everyone
My issue is this, I need to list all the sub directories in a directory that contains files that have the extension *.log, *.dat and *.out . After reviewing the output i need to delete those directories i do not need. I am running Solaris 10 in a bash shell. I have a script that I... (2 Replies)
Hi,
I have to find specific files only in the current directory...not in the sub directories.
But when I use Find command ... it searches all the files in the current directory as well as in the subdirectories. I am using AIX-UNIX machine.Please help..
I am using the below command. And i am... (2 Replies)
Hi Guys,
What I am looking at doing is to run a C program in my home directory, but output files in multiple directories BUT not at the same instance.
For e.g.
1st instance:
Run program.c and output results in path /aaa/bbb/ccc/
2nd instance:
Run program.c again and output results... (9 Replies)
I would like to transfer all files ending with .log from /tmp and to /tmp/archive (using find )
The directory structure looks like :-
/tmp
a.log
b.log
c.log
/abcd
d.log
e.log
When I tried the following command , it movies all the log files... (8 Replies)
I have searched about 30 threads, a load of Google pages and cannot find what I am looking for. I have some of the parts but not the whole. I cannot seem to get the puzzle fit together.
I have three folders, two of which contain different versions of multiple files, dist/file1.php dist/file2.php... (4 Replies)
Hello, this is probably another really simple tasks for most of you gurus, however I am trying to make a script which takes an input, greps a specific file for that input, prints back to screen the results (which are directory names) and then be able to use the directory names to move files.... (1 Reply)
Hello,
I would like to list the files from all directories that has been modified more than 1 month ago, and whose name is like '*risk*log'.
I think a script like this should work :
ls -R | find -name '*risk*.log' -mtime 30 -type f
But it tells me "no file found" though I can see some.
... (4 Replies)