Advanced

Four ways to extract the current directory name

Posted by Scott_Ruecker on · 1 comment
Linux.com; By Sergio Gonzalez Duran
Mail this story
Print this story

When you're programming a shell script, you often only need the current directory name, not the whole path that the pwd command returns. Here are four ways you can extract only the current directory.

Full Story

  Nav
» Read more about: Story Type: News Story; Groups: Linux

» Get new stories by e-mail: nightly or as they are published

« Return to the newswire homepage

  Related stories
» More like this

Comments (1)

Rather than using the rev thing you can use $NF, the awk number of fields built in. Although I'll confess to using rev as a way to sort my .com's and yahoo.com's and my.yahoo.com's in a reasonable way.

holderm@harpo:~/frodoconf/toshiba$ pwd | awk -F / '{print $NF}' toshiba

Post a comment

A free account is needed to post. Write your comment here first: your text is kept in this browser while you sign up or log in, and is waiting for you when you come back.

Your message:
|||||
10
Markdown: **bold**, *italic*, [text](https://link), - lists, > quotes, $x^2$ for math. Formatting help

Sign up and post (it is free)  or  Log in and post