Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Linux rm -rf throws Invalid argument error?

Tags:

linux

bash

I logged into rhel 7 box (a docker container) and runs as root. I tried to remove a directory and I keep getting Invalid argument error. Here is my command

[root@sandbox ~]# rm -rf /var/lib/ambari-server/data/tmp/solr-service/custom-services/SOLR/5.5.2.2.5
rm: cannot remove `/var/lib/ambari-server/data/tmp/solr-service/custom-services/SOLR/5.5.2.2.5': Invalid argument

Here is the permission of that folder

[root@sandbox ~]# ls -lrth /var/lib/ambari-server/data/tmp/solr-service/custom-services/SOLR/
total 4.0K
drwxr-xr-x 1 root root 4.0K Nov  7 07:50 5.5.2.2.5

The folder is actually empty:

[root@sandbox ~]# ls -lrth /var/lib/ambari-server/data/tmp/solr-service/custom-services/SOLR/5.5.2.2.5/
total 0

Trying to put the path in quote is not working either:

[root@sandbox ~]# rmdir "/var/lib/ambari-server/data/tmp/solr-service/custom-services/SOLR/5.5.2.2.5"
rmdir: failed to remove `/var/lib/ambari-server/data/tmp/solr-service/custom-services/SOLR/5.5.2.2.5': Invalid argument

Delete by using inode is not working either:

[root@sandbox ~]# ls -il /var/lib/ambari-server/data/tmp/solr-service/custom-services/SOLR/
total 4
98616 drwxr-xr-x 1 root root 4096 Nov  7 07:50 5.5.2.2.5
root@sandbox ~]# find . -inum 98616 -exec rm -i {} \; # doesn't throws error but the folder is still there
[root@sandbox ~]# ls /var/lib/ambari-server/data/tmp/solr-service/custom-services/SOLR/
5.5.2.2.5

Delete by using find is not working either:

[root@sandbox ~]# find /var/lib/ambari-server/data/tmp/solr-service/custom-services/SOLR/ -type d -exec rm -Rf {} \;
rm: cannot remove `/var/lib/ambari-server/data/tmp/solr-service/custom-services/SOLR/5.5.2.2.5': Invalid argument
rm: cannot remove `/var/lib/ambari-server/data/tmp/solr-service/custom-services/SOLR/5.5.2.2.5': Invalid argument

How to remove that folder?

like image 707
Sean Nguyen Avatar asked Sep 18 '25 09:09

Sean Nguyen


1 Answers

If the folder is empty have you tried the rmdircommand instead with the full path in simple quotes? ''

If this not work neither could you find the inode of the folder and then remove it via its inode?

ls -il <path> #get the inumber, let's say it's 782353

Then, find . -inum <782353> -exec rm -ir {} \;

like image 175
Allan Avatar answered Sep 20 '25 01:09

Allan