I'm having the following problem:
I can't remove a specific file
$ ls -l
ls: cannot access fisier: Input/output error
total 0
d????????? ? ? ? ? ? fisier
$ rm -rf fisier
rm: cannot remove ‘fisier’: Permission denied
$ sudo rm -rf fisier
[sudo] password for myusername:
rm: cannot remove ‘fisier’: Is a directory
Related
rm -r .git
rm -r .git --force
I get the following and there seems to be a never ending supply after I enter 'yes' and move to the next.
override r--r--r-- redacted/staff for .git/objects/95/90087aa4b351e278e6e53ff6240045ab2db6d1?
Analysis and explanation:
The message override r--r--r-- ...? is seen in some versions of the rm command when you try to delete a file or files with the rm command that have write access removed.
To reproduce:
▶ mkdir -p foo/{bar,baz} ; touch foo/bar/qux
▶ chmod -R -w foo
▶ find foo -ls
4305147410 0 dr-xr-xr-x 4 alexharvey wheel 128 24 Mar 18:19 foo
4305147412 0 dr-xr-xr-x 2 alexharvey wheel 64 24 Mar 18:19 foo/baz
4305147411 0 dr-xr-xr-x 3 alexharvey wheel 96 24 Mar 18:19 foo/bar
4305147413 0 -r--r--r-- 1 alexharvey wheel 0 24 Mar 18:19 foo/bar/qux
Now if you try to delete these files you'll be asked if you really want to override this file mode:
▶ rm -r foo
override r-xr-xr-x alexharvey/wheel for foo/baz?
Note also that if you are on Mac OS X or other BSD variant, as appears to be the case, then you have specified the --force argument incorrectly by adding it to the end of the command line, where it will be interpreted as the name of an additional file to delete.
But even if I correct that, -f still can't override r--r--r--. Instead, you would see this:
▶ rm -rf foo
rm: foo/baz: Permission denied
rm: foo/bar/qux: Permission denied
rm: foo/bar: Permission denied
rm: foo: Directory not empty
The fix:
To fix this, firstly restore the write permission within the folder:
▶ chmod -R +w foo
Then rm -r should work fine:
▶ rm -r foo
▶ ls foo
ls: foo: No such file or directory
See also:
this related question at Unix & Linux Stack Exchange.
source code for BSD rm here.
if you want to delete directories in git, just log in to sudo:
$ sudo rm -r file-name
rm -rf .folder
does the trick without spending extra time setting parameters
I'm trying to change the owner and the group of a directory and any subdirectories and archives in a centos sytem
I'm using this commands:
chown -R mc4380 [502] /home/minecraft/multicraft/servers/server4380
chgrp -R mc4380 [502] /home/minecraft/multicraft/servers/server4380
The way to directory is:
/home/minecraft/multicraft/servers/server4380
And the new owner and group are:
mc4380 [502]
The problem is the space in the mc4380 [502], I receive this error when I execute the command:
chown: cannot access `[502]': No such file or directory
I Already tried this and don't worked:
chown -R "mc4380 [502]" /home/minecraft/multicraft/servers/server4380
chown -R 'mc4380 [502]' /home/minecraft/multicraft/servers/server4380
chown -R mc4380\ [502] /home/minecraft/multicraft/servers/server4380
everytime receiving this:
chown: invalid user: `mc4380 [502]'
But the user/group exists and are okay, and when i used this command:
chown -R new_owner:new_group /directory
Him understood the first argument changing successful the owner of the archives/directory and subdirectorys
Oh, sorry my bad english, I tried to do my best
Try this command:
chown -R mc4380\ \[502\] /home/minecraft/multicraft/servers/server4380
I tried to write a generic Dockerfile and I would like not changed the file names each time the version changes. How is it possible to use a * for variable names?
ADD ./Trimmomatic-*.zip /tmp/
RUN cd /usr/local ; unzip /tmp/Trimmomatic*.zip
ENV JAR_LOC echo `ls -1 /usr/local/Trimmomatic/trimmomatic-*.jar`
RUN chmod 755 ${JAR_LOC}
RUN ln -s /usr/local/Trimmomatic/trimmomatic-*.jar /usr/local/bin/trimmomatic.jar
RUN rm -rf /tmp/Trimmomatic*.zip
Unfortunately, I got the following error:
Step 12 : ADD ./Trimmomatic-*.zip /tmp/
---> Using cache
---> b0104788f151
Step 13 : RUN cd /usr/local ; unzip /tmp/Trimmomatic*.zip
---> Using cache
---> ffeae9bbd5f6
Step 14 : ENV JAR_LOC echo `ls -1 /usr/local/Trimmomatic/trimmomatic-*.jar`
---> Using cache
---> e4f836c140ca
Step 15 : RUN chmod 755 ${JAR_LOC}
---> Running in 539728a7f13f
chmod: cannot access '755': No such file or directory
chmod: cannot access 'echo': No such file or directory
chmod: cannot access '`ls': No such file or directory
chmod: cannot access '/usr/local/Trimmomatic/trimmomatic-*.jar`': No such file or directory
The command '/bin/sh -c chmod 755 ${JAR_LOC}' returned a non-zero code: 1
Why a * does not get replaced in variable value
I want to list directory disk usage in a fileserver.
I also want to ignore the error messages. Here is my command:
du -sh * | grep -v "Permission denied" | sort -n
The result still contains the permission denied lines:
du: cannot access './myFile1/': Permission denied
du: cannot access './myFile2/': Permission denied
du: cannot access './myFile3/': Permission denied
What am I doing wrong?
This is because the "Permission denied" is sent through standard error, not through standard output.
If you don't want this information, just silence it by redirecting stderr to /dev/null:
du -sh * 2>/dev/null | sort -n
This happens with all these error messages:
$ touch a
$ ls a asfasd
ls: cannot access asfasd: No such file or directory
a
$ ls a asfasd | grep cannot
ls: cannot access asfasd: No such file or directory
$ ls a asfasd 2>/dev/null
a
I am writing a bash script, which has a problem:
path=$(pwd)
data=$(ls -al $path) > /dev/null 2>/dev/null
The problem occurs if $path is a "locked" directory (no permission for user x), call it "BadDir". In that case, the program outputs:
ls: cannot access /home/user/.../BadDir/..: Permission denied
All I want is to hide this output.
I know there is redirection to /dev/null but I don't know how to use it in this particular case.
you can redirect all error message to another with using EXEC
for test, first create folder
mkdir /tmp/t/
sudo chown root /tmp/t/
sudo chgrp root /tmp/t/
sudo chmod 400 /tmp/t/
e.g:
ls -al /tmp/t/
output:
ls: cannot open directory /tmp/t/: Permission denied
and using EXEC first of file:
exec 2>/dev/null
ls -al /tmp/t/
with exec you can control and redirect all error message or another output