Question

xx@xx-PC ~/xampp/htdocs/sites
$ rmdir /s "yo-2"
rmdir: `/s': No such file or directory
rmdir: `yo-2': Directory not empty

xx@xx-PC ~/xampp/htdocs/sites
$ rmdir "yo-2"
rmdir: `yo-2': Directory not empty

I cant seem to get rmdir to work in git bash. Its not in a git repo and I've tried the above. Mkdir works as expected, why doesnt this?

Was it helpful?

Solution

rmdir will not work if directory is empty

Try

  rm -rf yo-2

git-bash is a Linux like shell

OTHER TIPS

If you are trying to remove an entire directory regardless of contents, you could use:

rm <dirname> -rf

just use the command below:

rm -rfv mydirectory

After trying out a couple of other commands, this worked for me:

rm dirname -rf

A bit late, but I believe it still can help someone with performance problems on Windows systems. It is REALLY FAST to delete on Windows using git bash comparing with just the ordinary rm -rf. The trick here is to move the file/directory to another random name in a temporary directory at the same drive (on Windows) or at the same partition (on *nix systems) and invoke the rm -rf command in background mode. At least you don't need to wait for a blocking IO task and OS will perform the deletion as soon it gets idle.

Depending on the system you are using you may need to install the realpath program (ie macOS). Another alternative is to write a bash portable function like in this post: bash/fish command to print absolute path to a file.

fast_rm() {
    path=$(realpath $1) # getting the absolute path
    echo $path
    if [ -e $path ]; then
        export TMPDIR="$(dirname $(mktemp -u))"
        kernel=$(uname | awk '{print tolower($0)}')
        # if windows, make sure to use the same drive
        if [[ "${kernel}" == "mingw"* ]]; then # git bash
            export TMPDIR=$(echo "${path}" | awk '{ print substr($0, 1, 2)"/temp"}')
            if [ ! -e $TMPDIR ]; then mkdir -p $TMPDIR; fi
        fi
        if [ "${kernel}" == "darwin" ]; then MD5=md5; else MD5=md5sum; fi
        rnd=$(echo $RANDOM | $MD5 | awk '{print $0}')
        to_remove="${TMPDIR}/$(basename ${path})-${rnd}"
        mv "${path}" "${to_remove}"
        nohup rm -rf "${to_remove}" > /dev/null 2>&1 &
    fi
}

# invoking the function
directory_or_file=./vo-2
fast_delete $directory_or_file

I have faced same issue. this is worked for me

rimraf is a Node.js package, which is the UNIX command rm -rf for node, so you will need to install Node.js which includes npm. Then you can run:

npm install -g rimraf

Then you can run rimraf from the command line.

rimraf directoryname

visit https://superuser.com/questions/78434/how-to-delete-directories-with-path-names-too-long-for-normal-delete

I found this solution because npm itself was causing this problem due to the way it nests dependencies.

Late reply, but for those who search a solution, for me the

rm <dirname> -rf

wasn't good, I always get the directory non-empty or path too long on node directories.

A really simple solution : Move the directory you want to delete to the root of your disk (to shorten your path) and then you can delete it normally.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top