[colug-432] show path stuff

Rick Hornsby richardjhornsby at gmail.com
Fri Oct 30 12:16:39 EDT 2015


> On Oct 30, 2015, at 11:01, jep200404 at columbus.rr.com wrote:
> 
> What's a better way than the following code 
> of doing ls -ld for a file and all of its parent directories?

Not exactly clear on the goal?  If you just want the path component, use dirname.  If you just want the filename, use basename.  If you want the full path + filename, use realpath.

rhornsby at archer:~$ dirname /etc/udev/rules.d/70-persistent-net.rules
/etc/udev/rules.d

rhornsby at archer:~$ basename /etc/udev/rules.d/70-persistent-net.rules
70-persistent-net.rules

rhornsby at archer:~$ cd /etc/udev/rules.d/
rhornsby at archer:/etc/udev/rules.d$ realpath 70-persistent-net.rules
/etc/udev/rules.d/70-persistent-net.rules

Or, are you trying to iterate over every path component?


>    [sb at dojo ~]$ f=/etc/udev/rules.d/70-persistent-ipoib.rules 
>    [sb at dojo ~]$ while [ "x$f" != "x" ]; do ls -ld "$f";f=`echo "$f" | sed -e 's%/[^/]*$%%'`;done
>    -rw-r--r--. 1 root root 709 Mar  6  2015 /etc/udev/rules.d/70-persistent-ipoib.rules
>    drwxr-xr-x. 2 root root 38 Jun 23 19:48 /etc/udev/rules.d
>    drwxr-xr-x. 3 root root 51 Jul  1 13:30 /etc/udev
>    drwxr-xr-x. 146 root root 12288 Oct 23 15:18 /etc
>    [sb at dojo ~]$ 
> 
> _______________________________________________
> colug-432 mailing list
> colug-432 at colug.net
> http://lists.colug.net/mailman/listinfo/colug-432




More information about the colug-432 mailing list