代码之家  ›  专栏  ›  技术社区  ›  Matheus Dias de Souza

如何在Bash中将一个目录中的所有文件移动到父目录?[副本]

  •  -1
  • Matheus Dias de Souza  · 技术社区  · 11 月前

    我需要为使用mdBook实用程序编写的帮助文档提供一个GitHub工作流,其中mdBook将工件生成为 book 目录。

    在将这些工件移动到本地Ubuntu存储库的顶部后,我会将本地存储库的更改提交到特定的GitHub分支。

    我试过了:

    mv -f book .
    rm -rf book
    

    我得到:

    mv:“书”和“/书是同一个文件

    我也试过:

    mv -f book ..
    rm -rf book
    

    它有效,但我什么也没得到(我丢失了所有文件)。

    我试过了 cp -r book <something like "." or ".."> ,但它也没有走。

    我想我不能尝试使用 / ~ 作为复制目标,因为工作存储库可能位于另一个目录下。

    以下是完整的工作流程:

    name: Build
    
    on:
      push:
        branches: [ "master" ]
      pull_request:
        branches: [ "master" ]
      workflow_dispatch:
        inputs:
          logLevel:
            description: 'Log level'
            required: true
            default: 'warning'
            type: choice
            options:
            - info
            - warning
            - debug
          tags:
            description: 'Build'
            required: false
            type: boolean
          environment:
            description: 'Environment to run tests against'
            type: environment
            required: true
    
    permissions:
      contents: write
    
    env:
      CARGO_TERM_COLOR: always
    
    jobs:
      build:
        runs-on: ubuntu-latest
    
        steps:
          - uses: actions/checkout@v4
          - name: Install mdbook CLI
            run: cargo install mdbook --version ~0.4
          - name: Build book
            run: mdbook build
          - name: Git commit report
            run: |
              mv -f book .
              rm -rf book
    
              # Git commit
              git config --global user.name '<username>'
              git config --global user.email '<e-mail>'
              git switch -C live
              git rm -r .github src theme .gitignore book.toml
              git add .
              git commit -m "Automated report"
              git push origin -f live
    
    
    1 回复  |  直到 11 月前
        1
  •  0
  •   dognose    11 月前

    您正在尝试移动文件夹 book . -它实际上已经在那里了。

    你想要 mv -f book/* . (将所有文件移到里面 . )