cancel
Showing results for 
Search instead for 
Did you mean: 
jeesshnasree
Starfighter Starfighter
Starfighter
  • 626 Views

Print end of the directory only

Jump to solution

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

Labels (1)
2 Solutions

Accepted Solutions
shura
Flight Engineer
Flight Engineer
  • 581 Views

Hi

echo "/tmp/my-test/testing/logs/mars/water" | sed 's|.*/\(.*$\)|\1|'

View solution in original post

jeesshnasree
Starfighter Starfighter
Starfighter
  • 519 Views

last-working.png

Hi @shura ,

Thank you so much , its working now . Please find attached screenshot .

View solution in original post

5 Replies
shura
Flight Engineer
Flight Engineer
  • 331 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

0 Kudos
shura
Flight Engineer
Flight Engineer
  • 331 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

0 Kudos
shura
Flight Engineer
Flight Engineer
  • 582 Views

Hi

echo "/tmp/my-test/testing/logs/mars/water" | sed 's|.*/\(.*$\)|\1|'

jeesshnasree
Starfighter Starfighter
Starfighter
  • 520 Views

last-working.png

Hi @shura ,

Thank you so much , its working now . Please find attached screenshot .

jeesshnasree
Starfighter Starfighter
Starfighter
  • 516 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

Join the discussion
You must log in to join this conversation.