#过滤所有目录
[root@localhost tmp]# ldd /usr/bin/vim linux-vdso.so.1 => (0x00007fffedffd000) libncurses.so.5 => /usr/lib64/libncurses.so.5 (0x00000031b5200000) libselinux.so.1 => /lib64/libselinux.so.1 (0x00000031b3e00000) libacl.so.1 => /lib64/libacl.so.1 (0x00000031b4e00000) libgpm.so.1 => /usr/lib64/libgpm.so.1 (0x00000031b4600000) libperl.so => /usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/CORE/libperl.so (0x00000031b5600000) libresolv.so.2 => /lib64/libresolv.so.2 (0x00000031b6200000) libutil.so.1 => /lib64/libutil.so.1 (0x00000031b5a00000) libc.so.6 => /lib64/libc.so.6 (0x00000031b2a00000) libm.so.6 => /lib64/libm.so.6 (0x00000031b3600000) libdl.so.2 => /lib64/libdl.so.2 (0x00000031b2e00000) libpthread.so.0 => /lib64/libpthread.so.0 (0x00000031b3200000) libsepol.so.1 => /lib64/libsepol.so.1 (0x00000031b4200000) /lib64/ld-linux-x86-64.so.2 (0x00000031b2600000) libattr.so.1 => /lib64/libattr.so.1 (0x00000031b3a00000) libnsl.so.1 => /lib64/libnsl.so.1 (0x00000031b7200000) libcrypt.so.1 => /lib64/libcrypt.so.1 (0x00000031b4a00000) [root@localhost tmp]# ldd /usr/bin/vim | grep -o "/[^[:space:]]\{1,\}" /usr/lib64/libncurses.so.5 /lib64/libselinux.so.1 /lib64/libacl.so.1 /usr/lib64/libgpm.so.1 /usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/CORE/libperl.so /lib64/libresolv.so.2 /lib64/libutil.so.1 /lib64/libc.so.6 /lib64/libm.so.6 /lib64/libdl.so.2 /lib64/libpthread.so.0 /lib64/libsepol.so.1 /lib64/ld-linux-x86-64.so.2 /lib64/libattr.so.1 /lib64/libnsl.so.1 /lib64/libcrypt.so.1
[root@localhost tmp]# which ls alias ls=‘ls --color=tty‘ /bin/ls [root@localhost tmp]# which ls | grep -o "/[^[:space:]]\{1,\}" /bin/ls
截取文件的父目录
[root@localhost tmp]# export DPATH=/usr/local/file/name/test.file [root@localhost tmp]# echo ${DPATH%/*} /usr/local/file/name
截取目录路径中的文件名
[root@localhost tmp]# echo ${DPATH##*/} test.file
原文:http://leozhenping.blog.51cto.com/10043183/1651781