我有一个bash脚本的问题。 我有这样的事情:linux“查找”命令
find /home -mindepth 1 -maxdepth 1 -not -empty -type d | sort
,输出是这样的:
/home/dir1
/home/dir2
我所要的输出是:
dir1
dir2
我有一个bash脚本的问题。 我有这样的事情:linux“查找”命令
find /home -mindepth 1 -maxdepth 1 -not -empty -type d | sort
,输出是这样的:
/home/dir1
/home/dir2
我所要的输出是:
dir1
dir2
您可以-printf
find /home -mindepth 1 -maxdepth 1 -not -empty -type d -printf "%f\n" | sort
你可以使用basename(1):
只是附加-exec basename {} \;
您find命令。
find /home -mindepth 1 -maxdepth 1 -not -empty -type d -exec basename {} \; | sort
find /home -mindepth 1 -maxdepth 1 -not -empty -type d -exec basename {} \; | sort