Unix Path Options


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Unix Path Options
# 1  
Old 11-18-2001
Unix Path Options

I am looking for the best way to move files into a directory (ie PDF_files), if the directory doesn't exist to create it.

However I am passing the full filename (psfile) of the file so I will have to remove the filename from the end, which can be at different field end lengths.

This is a piece of the code:

Code:
ENVIRON=`pwd`

find ${ENVIRON} -name "*.ps" -user $user | while read psfile
   do
   pdffile=`echo $psfile | sed s/.ps$//g`
   if [ -f ${pdffile}*.pdf ] ; then
      gzip -f ${pdffile}*.pdf
   fi

I have a few ideas, however I would like to have some guidance. Any suggestions would be much appreciated.

Thanks
Shakey21
# 2  
Old 11-19-2001
See the man pages for 'basename' and 'dirname' for easy ways to extract just the filename or just the directory from a path.
# 3  
Old 11-19-2001
Thanks very much!

That works extremely well, a short extract from the code

Code:

ENVIRON=`pwd`

find ${ENVIRON} -name "*.ps" -user $user | while read psfile
do
   pdffile=`echo $psfile | sed s/.ps$//g`
   filename=`basename $psfile | sed s/.ps$//g`
   directory=`dirname $psfile`
   if [ ! -d ${directory}/PDFs ] ; then
      mkdir ${directory}/PDFs
      chmod 775 ${directory}/PDFs
   fi     
   if [ -f ${directory}/*.pdf.gz ] ; then
      mv ${directory}/*.pdf.gz ${directory}/PDFs/
   fi   
   if [ -f ${directory}/*.pdf ] ; then
      mv ${directory}/*.pdf ${directory}/PDFs/
   fi
   if [ -f ${directory}/PDFs/${filename}*.pdf ] ; then
      gzip -f ${directory}/PDFs/${filename}*.pdf
   fi

Shakey21
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX and Linux Applications

UNIX equivalent of windows terminal server options?

I want to replace Windows terminal server mostly due to cost reasons license cost for 2100 users goes out of roof. The end-user is all windows but I want a jump server that is UNIX based , I have some experience with VNC but I don't want options exists in UNIX to run a terminal services for 2100... (10 Replies)
Discussion started by: lazerz
10 Replies

2. Shell Programming and Scripting

UNIX Date function with -d options

Hi , I couldn't understand how this program works. Can somebody please explain it to me. DT=`date -d "1 day"` # This part I understand echo ${DT/ */} # How this works echo ${DT/* /} (2 Replies)
Discussion started by: LoneRanger
2 Replies

3. UNIX for Dummies Questions & Answers

UNIX ls options

Hi Guys I'm new to the forums and Unix. I have my first assignment for school and i'm stuck on question 1 spent close to 4 hours on it :(. (doesn't look good). I looked the the online documentation of ls but don't really understand it yet. I need to find files whose names that are of length... (1 Reply)
Discussion started by: Stephvai
1 Replies

4. UNIX for Dummies Questions & Answers

UNIX sql options

New to the unix experience and sure love it. I do all my big sql queries using unix sas, it's great, can't complain. Also have isql on the box to work with Sybase db's if need be. Just wondering if there's any large-amt-of-data-folks round here that might suggest some other sql/data tools... (2 Replies)
Discussion started by: sas
2 Replies

5. UNIX for Dummies Questions & Answers

UNIX find command - using multiple -name options

Hi all, What am trying do is search for a directory that is owned by cm that only exists in a path that has a particular directory ex: what I'm using now is find . -user cm -name '*.rel' -type d -exec ls -dl {} \; This is giving me stuff like this ./../../foo1/../../*.rel... (2 Replies)
Discussion started by: jtmed
2 Replies

6. UNIX for Dummies Questions & Answers

What are the career options in unix apart from unix system administration?

What are the career options in unix apart from unix system administration? (2 Replies)
Discussion started by: thulasidharan2k
2 Replies

7. UNIX for Dummies Questions & Answers

Unix : About options of clear command ?

Hello everyone, My question is quite simple, even if I didn't find an answer. I would want a command (maybe clear with some options ?) that can do the following : clear completely the console, as it is when we start a console for the first time. My problem is that I sometimes display a lot... (5 Replies)
Discussion started by: Ben31400
5 Replies

8. Shell Programming and Scripting

path options clarification

hi guys.. i want to know as what these options -O and -n stand for, in the following: HOSTNM=$(/u/bin/wmuname -O) HOSTNM=$(/usr/bin/uname -n) can u please help me! awaiting your reply... (2 Replies)
Discussion started by: pravfraz
2 Replies

9. UNIX for Advanced & Expert Users

missing Path(in UNIX) when i launch a job on to unix machine using windows SSh

hi i want run an unix application from a windows program/application.i am using SSH(command line version)to log on to a unix machine from windows. the application has to read a configuration file inorder to run. the configuration file .CFG is in bin in my home directory. but the application... (1 Reply)
Discussion started by: megastar
1 Replies
Login or Register to Ask a Question