该命令列出当前路径下的目录:
ls -d */
模式*/到底做什么?
我们如何在上面的命令中给出绝对路径(例如ls -d /home/alice/Documents),只列出该路径下的目录?
该命令列出当前路径下的目录:
ls -d */
模式*/到底做什么?
我们如何在上面的命令中给出绝对路径(例如ls -d /home/alice/Documents),只列出该路径下的目录?
当前回答
我用以下方法部分解决了这个问题:
cd "/path/to/pricipal/folder"
for i in $(ls -d .*/); do sudo ln -s "$PWD"/${i%%/} /home/inukaze/${i%%/}; done
ln: «/home/inukaze/./.»: can't overwrite a directory
ln: «/home/inukaze/../..»: can't overwrite a directory
ln: accesing to «/home/inukaze/.config»: too much symbolics links levels
ln: accesing to «/home/inukaze/.disruptive»: too much symbolics links levels
ln: accesing to «/home/inukaze/innovations»: too much symbolics links levels
ln: accesing to «/home/inukaze/sarl»: too much symbolics links levels
ln: accesing to «/home/inukaze/.e_old»: too much symbolics links levels
ln: accesing to «/home/inukaze/.gnome2_private»: too much symbolics links levels
ln: accesing to «/home/inukaze/.gvfs»: too much symbolics links levels
ln: accesing to «/home/inukaze/.kde»: too much symbolics links levels
ln: accesing to «/home/inukaze/.local»: too much symbolics links levels
ln: accesing to «/home/inukaze/.xVideoServiceThief»: too much symbolics links levels
好吧,这对我来说是主要的部分:)
其他回答
对于所有没有子文件夹的文件夹:
find /home/alice/Documents -maxdepth 1 -type d
对于所有带子文件夹的文件夹:
find /home/alice/Documents -type d
只从“这里”列出目录的一行程序。
文件计数。
for i in `ls -d */`; do g=`find ./$i -type f -print| wc -l`; echo "Directory $i contains $g files."; done
Ls和awk(不含grep)
No need to use grep since awk can perform regularexpressino check so it is enough to do this:ls -l | awk '/^d/ {print $9}'
ls -l列出有权限的文件 Awk滤波器输出 '/^d/'正则表达式,只搜索以字母d开头的行(作为目录),并查看第一行-权限 {print}将打印所有列 {print $9}将只打印ls -l输出中的第9列(name)
非常简单明了
我用以下方法部分解决了这个问题:
cd "/path/to/pricipal/folder"
for i in $(ls -d .*/); do sudo ln -s "$PWD"/${i%%/} /home/inukaze/${i%%/}; done
ln: «/home/inukaze/./.»: can't overwrite a directory
ln: «/home/inukaze/../..»: can't overwrite a directory
ln: accesing to «/home/inukaze/.config»: too much symbolics links levels
ln: accesing to «/home/inukaze/.disruptive»: too much symbolics links levels
ln: accesing to «/home/inukaze/innovations»: too much symbolics links levels
ln: accesing to «/home/inukaze/sarl»: too much symbolics links levels
ln: accesing to «/home/inukaze/.e_old»: too much symbolics links levels
ln: accesing to «/home/inukaze/.gnome2_private»: too much symbolics links levels
ln: accesing to «/home/inukaze/.gvfs»: too much symbolics links levels
ln: accesing to «/home/inukaze/.kde»: too much symbolics links levels
ln: accesing to «/home/inukaze/.local»: too much symbolics links levels
ln: accesing to «/home/inukaze/.xVideoServiceThief»: too much symbolics links levels
好吧,这对我来说是主要的部分:)
*/是一个文件名匹配模式,匹配当前目录中的目录。
只列出目录,我喜欢这个函数:
# Long list only directories
llod () {
ls -l --color=always "$@" | grep --color=never '^d'
}
把它放在你的。bashrc文件中。
使用例子:
llod # Long listing of all directories in current directory
llod -tr # Same but in chronological order oldest first
llod -d a* # Limit to directories beginning with letter 'a'
llod -d .* # Limit to hidden directories
注意:如果您使用-i选项,它将中断。这里有一个解决方案:
# Long list only directories
llod () {
ls -l --color=always "$@" | egrep --color=never '^d|^[[:digit:]]+ d'
}