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
Hi
echo "/tmp/my-test/testing/logs/mars/water" | sed 's|.*/\(.*$\)|\1|'
Hi @shura ,
Thank you so much , its working now . Please find attached screenshot .
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
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
Hi
echo "/tmp/my-test/testing/logs/mars/water" | sed 's|.*/\(.*$\)|\1|'
Hi @shura ,
Thank you so much , its working now . Please find attached screenshot .
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
Red Hat
Learning Community
A collaborative learning environment, enabling open source skill development.