Solved

retrieve directory name from a $file variable

Posted on 2008-06-24
4
282 Views
Last Modified: 2013-12-26
Hi

I started this script, in which I would like to get the directory name where $file is located, and put it in a variable. I only want the name of the directory, not the path...

Can someone help ?

Cheers

Terence
#!/bin/sh

thumbdir=/Users/terencepires/Documents/Skydog/Images/for_web/thumb
 

for file in $(find . -type f -iname "*.jpg" -o -iname "*.tif" -o -iname "*.tiff" -o -name "*.gif"); do 
 

#imageMagick format and size conversion 

convert $file -quality 10 -resize 25% $thumbdir$file

done

Open in new window

0
Comment
Question by:terencepires
  • 2
4 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 21854483
directory=`dirname $file`
0
 
LVL 1

Author Comment

by:terencepires
ID: 21854563
ok but it gives this :

./__Freddy_Lynxx
./__Flamin_Groovies
./__Eddie_and_Ze_Hot_Rods

I need to remove the ./ how can i do ?
0
 
LVL 1

Author Comment

by:terencepires
ID: 21854880
ok I did it like this : file=`echo $file | cut -c3-70`

thanks anyway

Terence
0
 
LVL 48

Accepted Solution

by:
Tintin earned 500 total points
ID: 21860488
Two better solutions are to do

find *

instead of

find .

or

file=`echo $file | sed "s/^..//"`

instead of

file=`echo $file | cut -c3-70`

0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Deploystudio is a system which can be used to deploy OSX clients and servers within the small/medium or large business environments. The system is built onto of the OSX Server NetBoot system and uses images & workflows as its core assets. While work…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now