How can I find two parent directories in perl?
2 answers
Using Path :: Tiny :
$ perl -MPath::Tiny -e 'CORE::say path($ARGV[0])->parent->parent' /path/to/here/file.txt
This does not perform a file system check. Doing this using only File :: Spec tends to get tedious. I'm not sure about the following works:
$ perl -MFile::Spec::Functions=splitpath,catpath,catdir,splitdir -e \
'($v, $d) = splitpath($ARGV[0]); @d = splitdir $d; splice @d, -2; \
CORE::say catpath($v, catdir (@d))' /path/to/here/file.txt
+2
source to share