Unable to Change Permission for File on External Disc on Mac - macos

Problem
I have a corrupt file on a network NAS:
/bad/bad_file.file
Which I want to remove but I cannot. The file name is extremely long, so this may be part of the problem.
Finder
The file has the permission user:Read&Write, everyone:No Access
If I try to change it with in macs file info, it basically tells me that the file is not found:
An unexpected error occurred (error code -43).
Terminal
If cd to the folder containing the bad file's folder
sudo chmod -R 777 bad
I get
chmod: Unable to change file mode on bad_file.file
If I want to make myself the owner of the file:
sudo chown -R $(whoami) bad
I get the error:
chown: bad_file.file No such file or directory
Question
How can I remove this file, or if it is not there make it disappear under the path in case it's not there?

Related

mkdir/cp in Mac terminal gives "Permission denied" error

I'm trying to copy a directory in terminal from the Downloads directory to a sub-directory within the Applications/ directory, and I keep getting "Permission denied" error. Why is this so?
try
ls -lt
to see access permission of the folder you want copy file into
then use
chmod 777 your_folder_name
to change the access permissions of the folder
If you "right-click -> Get info" the Applications folder you will notice that the permissions for the Applications folder are Read/Write for 'system' or 'admin'. For 'everyone' it's Read-only. If you are not an admin you need to use 'sudo cp -R Downloads/___Test /Applications'. Obviously, you need to enter a password.
MacOS prevents interaction with downloaded files until you confirm that they are safe. You can effectively do this programmatically by running:
xattr -d com.apple.quarantine ~/Downloads/your_file_here
Then you should be able to copy the file.

make a file with the space in its name inaccessible in the cpanel using bash command

I'm installing a watcher system for my server, this will basically watch my directories for any change/delete/modify/create ... so I can call a .sh file in the watcher when those events occur so I have these in my watcher.sh file
#!/bin/bash
LOGFILE=/etc/watcher.log
chmod 000 -R $1
chown root $1
echo "$(date +%Y-%m-%d);$(date +%H:%M:%S);$1;$3;$2;watcher.sh" >> $LOGFILE
It works fine when I upload a file called a.txt but if I upload a file with space in their names nothing happens. In the log file I have
2017-06-04;18:37:34;/home/domain/public_html/upload/a b.txt;IN_CREATE;128;watcher.sh
chmod: cannot access `/home/domain/public_html/upload/a': No such file or directory
chmod: cannot access `b.txt': No such file or directory
chown: cannot access `/home/domain/public_html/upload/a': No such file or directory
chown: cannot access `b.txt': No such file or directory
the space in the name is messing this up. How can I fix this? Also why can I still delete the newly uploaded file from cpanel I tough by changing ownership to root it would be inaccessible in the cpanel.
You may place quote characters around the parameters such as:
chmod 000 -R "$1"
chown root "$1"
The quotes should resolve the issue with the spaces via the parameters in the shell script.

How to get rid of permision denied while using mv command?

I am trying to move a file from one directory to other by command line.I used this command
raghul#raghul-Aspire-5750Z:~/temp/newfolder$ mv copy.txt /temp/
I got error like this
cannot create regular file '/temp': Permission denied
Can someone help me to figure this out? I need to move a file from one directory to other.
First of all you are using the copy command cp, not the move command mv.
Secondly you are trying to copy the file to a new file named /temp, ie. a file named temp in the / directory. This resides in the filesystem's root directory, which is mostly likely owned by root. Unless you have root permissions you can not write to the root directory.
Given that you are naming the file temp, I assume that you want to move the file to the /tmp directory, for which you will have permission to write to. Do this:
$ mv copy.txt /tmp
This will work only if you also have write permission on the file copy.txt because you need to be able to remove it. If you just wanted to copy the file, just read permission is required.
Otherwise, if you really do wish to move the file to a /temp directory, you can use sudo to do that, provided that you are set up as a sudo user:
$ sudo mv copy.txt /temp
[sudo] password for raghul
I just noticed that you're in a personal directory called ~/temp/newfolder. Is that the temp you're trying to move the file to: your personal one, in which onefolder is in? So you want to move the file up one directory?
Then the problem is that your command is missing the 'personal' tag ~. The command should be:
mv copy.txt ~/temp/
Try moving it with sudo command as it seems you don't have permission to move the file.
If you are requested for a password enter the root's password.
Try this:
sudo cp copy.txt /temp/
Try this: change /temp to
mv index.text temp

Giving a script permission to execute mkdir on its own

I have a file I downloaded from the Internet. When I run it in the osx terminal, one of the automated things it does is make a new directory in my /usr/local/bin, but this fails as terminal says that permission is denied. How do I give this file permission to execute the mkdir command? I know how to give myself permission with sudo, but not how to give this file permission to do the same on its own.
You can give your user permission to that folder by running sudo chown -R $(whoami) /usr/local/bin/. Once you make sure you own the directory and sub-directories (ls -l /usr/local and ls -l /usr/local/bin) your script should be able to write to those directories as well.
As a general rule of thumb, sudoing to work around permission errors just makes the problem worse. Fixing the underlying permissions take a few extra minutes but is better in the long run.

Permission denied when chmoding

I want to remove an Adobe folder with empty subfolders. I am using Git Bash on Windows 8 to chmod -R 777 Adobe/ but I am getting this error: changing permissions of 'insert_directory_here': Permission denied. Does anyone know what I can possibly do to delete this empty folders/subfolders? Thank you.

Resources