

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- 1,203 Views
Hi All,
I have one query .
Any path and need to print end of the directory only if provided path .
example:
/tmp/my-test/testing/logs/mars/water
in the above path need print only water directory .( sample & example purposes mentioned path).
How to get end directory only ,
if any command in the Linux OS then could you please provide command .
I am waiting for your valuable information.
Regards,
Jeesshnasree
Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- 1,158 Views
Hi
echo "/tmp/my-test/testing/logs/mars/water" | sed 's|.*/\(.*$\)|\1|'


- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- 1,096 Views
Hi @shura ,
Thank you so much , its working now . Please find attached screenshot .

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- 908 Views
Hi
If you want to see last any entry in directory:
ls -r <dir> | head -1
If you want to see last directory entry in directory:
ls -F -r <dir> | grep '/$' | head -1
Good lack

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- 908 Views
Hi
If you want to see any type entry in directory:
ls -r /tmp/my-test/testing/logs/mars | head -1
if you want to see only directory ( only water directory ) entry in directory:
ls -F -r /tmp/my-test/testing/logs/mars | grep '/$' | head -1
Good lack

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- 1,159 Views
Hi
echo "/tmp/my-test/testing/logs/mars/water" | sed 's|.*/\(.*$\)|\1|'


- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- 1,097 Views
Hi @shura ,
Thank you so much , its working now . Please find attached screenshot .


- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- 1,093 Views
Hi @shura ,
Thank you . I also got one more soultion .
echo "";echo "/tmp/my-test/testing/logs/mars/water" | sed 's|.*/\(.*$\)|\1|'; ls -ld /tmp/my-test/testing/logs/mars/water|sed 's|.*/\(.*$\)|\1|';echo "";ls -ld /tmp/my-test/testing/logs/mars/water|awk -F "/" '{print $NF}'
water
water
water