I have a .git/ folder that I'd like to delete. However, it isn't possible because there is a puzzling file into it which is not reachable.
Below is my try:
$ rm -rf .git/
rm: cannot remove '.git/': Directory not empty
$ rm -r .git/
rm: descend into directory '.git/'? y
rm: cannot remove '.git/t8QVta1': No such file or directory
rm: remove directory '.git/'? y
rm: cannot remove '.git/': Directory not empty
$ ls -l .git/
ls: cannot access '.git/t8QVta1': No such file or directory
total 0
?????????? ? ? ? ? ? t8QVta1
$
I have no idea what is the 't8QVta1' file and all of the question marks.
Many thanks for your help.
The ?????????? ? ? ? ?... output of ls may indicate that you are missing the correct permissions to access this file. If this is the problem, you could try giving yourself permissions over the parent directory and its children with the following command:
sudo chmod -R g+x .git/
To remove a non-empty folder use -rf flags
$ rm -rf .git
Related
I have a directory reference in my Downloads directory that contains a symbolic link (created with ln -s) to another directory. I get conflicting error message when trying to remove the symlink:
rm returns "Is a directory"
rmdir returns "Not a directory"
This only occurs with cellranger/ (followed by a forward slash) and not with cellranger.
[tom#rlgsw68 cellranger]$ pwd
/home/tom/Downloads/reference
[tom#rlgsw68 cellranger]$ ls -lth
lrwxrwxrwx 1 tom genome 33 Apr 4 14:52 cellranger -> /analysisdata/genomes/cellranger/
[tom#rlgsw68 cellranger]$ rm cellranger/
rm: cannot remove directory `cellranger/': Is a directory
[tom#rlgsw68 cellranger]$ rmdir cellranger/
rmdir: cellranger/: Not a directory
[tom#rlgsw68 cellranger]$ rm cellranger
Why does neither of these commands to remove the symlink work and why do these conflicting errors occur? What is the recommended way to remove symbolic links without removing the content in the source directory. rm -rf cellranger/ also does not remove the symlink (but does not return an error).
Information: I'm running a linux server (Debian 9.0). These errors occur with both bash and zsh. Ambiguous names have been removed from the example. I encountered this when a directory included a link to the parent directory in addition to the contents:
/home/tom/Downloads/reference/cellranger/cellranger/ -> /analysisdata/genomes/cellranger/
By putting a trailing slash you are referring to the directory the symlink points to, no longer the symlink itself. Printing the inode number (the number that a path refers to in the file system) shows the difference between dereferencing the symlink and the directory:
$ cd "$(mktemp --directory)"
$ mkdir a
$ stat --format %i a/
9
$ ln --symbolic a b
$ stat --format %i b
10
$ stat --format %i b/
9
This may be related to the fact that a symlink is never a directory, it is always just a file containing a path.
I tried to delete a directory which contains other directories, but it shows "rmdir: failed to remove './will': Directory not empty"
To delete you need rm and "-rf" for recursive force
rm -rf yourdirectoryname
I tried to search on SO, but not able to find the difference between the following commands. if I have a directory named dir, how the below commands differ?
rm -rf dir/*
rm -rf dir/
rm -rf dir
Also how do the user permissions on the directory affect the outcome, if the id running the command is not the owner or not even in the group of the owner?
I am adding the command to do rm -rf in a shell script I am working on and need help in understanding the difference between the above commands.
rm -rf dir/*
Removes files within the directory (without removing the directory itself).
Note, hidden files won't be removed.
rm -rf dir/
Trailing slash indicates that dir is a directory. If it was a file, it wouldn't get removed. In your case this is identical to rm -rf dir, but in general it differs (see below)
rm -rf dir
In your case, identical to the one above.
In general, tools such as rm usually follow IEEE/OpenGroup standards when it comes to pathname resolution, which means that dir/ is equivalent to dir/.. One implication of that is that if diris a symlink to a directory rm -rf dir/ will remove the content of the directory (including the hidden files) but not the link or the directory itself, whereas rm -rf dir will only remove the symlink.
You need to have write permissions on a file or directory that you are removing, plus exec permissions on a directory that rm needs to traverse to remove files. You can read more about Unix filesystem permissions here.
On Windows I am trying to add a Makefile target to remove all files from a specific directory (NOT including subdirectories)...
clean_files:
rm -f Build/*.*
But I get the error: /bin/sh: rm: command not found
Running it from the command line works and running it without the *'s works.
clean_files:
- rm -f Build/*
putting a '-' before a make command will ignore any errors from that command, like
rm: cannot remove `Build/subdir': Is a directory
For removing all files from directory (NOT including sub-directories) consider:
clean_files:
find Build/ -type f -maxdepth 1 -delete
I used msys to create a symlink. Now I wish to remove it, but here's what I get:
$ ln -s /mypath mylink
$ rm mylink
rm: cannot remove directory `mylink': Is a directory
What's the proper way to remove a symlink on msys?
Symlinks on MSys2 aren't real symlinks but copies. So you can actually use rm:
rm
-r, -R, --recursive remove directories and their contents recursively
Example:
rm -r mylink