LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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, 01: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, 03:41 AM   #2
uselpa
Senior Member
 
Registered: Oct 2004
Location: Luxemburg
Distribution: Slackware, OS X
Posts: 1,507

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

Original Poster
Blog Entries: 12

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, 04:28 AM   #4
uselpa
Senior Member
 
Registered: Oct 2004
Location: Luxemburg
Distribution: Slackware, OS X
Posts: 1,507

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

Original Poster
Blog Entries: 12

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


Reply



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

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 05:11 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
Open Source Consulting | Domain Registration