LinuxQuestions.org
Visit the LQ Articles and Editorials section
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



Reply
 
Search this Thread
Old 10-28-2006, 02:27 AM   #1
carl0ski
Member
 
Registered: Sep 2004
Location: Melbourne, Victoria Australia
Distribution: Support those that support you :)
Posts: 872
Blog Entries: 12

Rep: Reputation: 30
Bash to find and disect current working Directory


hi

PWD command shows the full path relative to root
however i hoping to find just the last segment
/home/carl0ski/.kde/share/apps/amarok

amarok

pwd |cut -d/ -f5

achieves but i need something that works on varying directory depths.


If you ineterested heres the reason
Amarok creates a .directory file to make the album cover the folder image, linking to the amarok cache in you home directory

however under varying users and computers i prefer the image to be stored in the actual album directory.
i use the folder name (Album name) as the Image name rather that the random characters amarok uses in the cache.
Code:
for cd in *
do cd "$cd"
pwd
image=`cat .directory |grep Icon| cut -d= -f2`

#name of the album based on last path name
album=`pwd |cut -d/ -f5`

#copy source image to the ablum folder and rename it to  album.png
cp "$image" ./"$album".png

#replace Icon=/home/carl0ski/.kde/share/apps/amarok/ with 
#the one contained in the albums directory
##Backing up original
mv .directory .directory.backup
echo [Desktop Entry] >.directory
echo Icon=./${album}.png>>.directory

#back to root fo next Directory
cd ../
pwd
done
 
Old 10-28-2006, 04:41 AM   #2
uselpa
Senior Member
 
Registered: Oct 2004
Location: Luxemburg
Distribution: Slackware, OS X
Posts: 1,507

Rep: Reputation: 46
try
Code:
basename $(pwd)
 
Old 10-28-2006, 05:27 AM   #3
carl0ski
Member
 
Registered: Sep 2004
Location: Melbourne, Victoria Australia
Distribution: Support those that support you :)
Posts: 872
Blog Entries: 12

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by uselpa
try
Code:
basename $(pwd)
cheers

filler to 10 character response

out of interest, is their an opposite command to basename?
 
Old 10-28-2006, 05:28 AM   #4
uselpa
Senior Member
 
Registered: Oct 2004
Location: Luxemburg
Distribution: Slackware, OS X
Posts: 1,507

Rep: Reputation: 46
Something like `dirname` ?
 
Old 10-28-2006, 05:36 AM   #5
carl0ski
Member
 
Registered: Sep 2004
Location: Melbourne, Victoria Australia
Distribution: Support those that support you :)
Posts: 872
Blog Entries: 12

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by uselpa
Something like `dirname` ?
yep that's the one
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
find in current directory ramanadyv Linux - Newbie 3 03-28-2006 11:12 PM
cd keeps snapping back to current directory when called from bash script ghrellin Linux - General 5 08-28-2005 01:50 PM
how do I find out the current working directory? nodger Programming 2 12-26-2004 12:28 PM
setting bash to look in current directory before searching the path muhkuhmasta Linux - Newbie 4 09-21-2004 03:08 AM
BASH: How to get current workin directory? gmitra Programming 9 09-20-2003 11:30 PM


All times are GMT -5. The time now is 01:54 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration