대체하는 방법의 위치를 포함하는 디렉토리 공간

0

질문

나는 두 개의 파이프라인;이 x="$(ls -1p | grep "/$" | tr -d "/")" 모든 하위 디렉터리를 작업 디렉터리에서,그리고 이 y="$(ls -1p | grep "/$"| grep \ | tr -d "/")" 을 얻는 하위 디렉터리를 포함하는 공간에서 작업 디렉터리입니다.

그래서 이제 나가려고 하는 위치를 대체하는 디렉토리의 담백하고 그것을 두고 맨 위에,ie., 말 아래 하위 디렉토리:

Dir1
Dir2
Dir 3

지금 Dir 3 맨 위로 이동:

Dir 3
Dir1
Dir1
for I in $x; do
    for X in $y; do
        if [[ $I == $X ]];then
            sed "/"$X"/d" "$I"
        fi
    done
    echo "$I"
done

위의 내 루프를 하는 작업입니다. 그것은 인쇄의 모든 하위 디렉터 포함하지 않는 공간이지만 그것을 인쇄한다:

Dir1
Dir2
sed: Dir: No such file or directory
Dir
sed: 3: No such file or directory
3

킬 수 있는 사람이 있다면 도움이 될 것입니다 크게 감사합니다.

bash
2021-11-24 00:05:11
2

최고의 응답

0

당신이 선호하는 경우 for 루프 find 명령을 어떻:

#!/bin/bash

# 1st loop to print the dirnames containing space character
for d in */; do                         # loops over subdirectories under current directory
    if [[ $d =~ [[:space:]] ]]; then    # if the dirname contains a space character
        echo "${d%/}"                   # then print the name removing the trailing slash
    fi
done

# 2nd loop to print the dirnames without space character
for d in */; do
    if [[ ! $d =~ [[:space:]] ]]; then  # if the dirname does not contain a space character
        echo "${d%/}"
    fi
done

출력 제공된 예제:

Dir 3
Dir1
Dir2
2021-11-24 01:45:53
0

사용 GNU 찾기:

find . -mindepth 1 -type d -name '*[[:space:]]*'       # spaces
find . -mindepth 1 -type d -regex '.*/[^/[:space:]]+$' # no spaces

이 재귀적입니다.

2021-11-24 01:57:20

다른 언어로

이 페이지는 다른 언어로되어 있습니다

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................