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

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.

Related

Visual Studio Code always asks for sudo permissions

Ok, so I've got a problem with VSCode where every time I try to save a file it asks me for sudo permission and it's really annoying and I can't make folders or files directly in the IDE. Can please someone help me?
Screenshot from VSCode
The running instance of VS Code doesn't seem to have write permission to the file you wish to save.
Since the file is in the directory of user uteu3, first make sure that it is user uteu3 that has started VS Code (it probably is, if uteu3 is the user logged into the system).
make sure uteu3 is the owner of the file and change the permissions by opening a terminal and executing:
sudo chown uteu3 filename && sudo chmod 664 filename
(Replace filename with actual path+name to the file.)
If this doesn't solve the problem, please execute the following two lines in a terminal and provide the output:
ps aux | grep visual-studio-code
stat -f '%A %a %N' filename
Since you indicate that this happens repeatedly also with other files, maybe several of the file permissions in your home directory are problematic. In that case, consider trying to fix them all. See for example: Need to fix file permissions in a user's home directory
.

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

Why can't I locate or navigate to this directory that my find command grabs?

I ran sudo find -L / -name .rvmrc and got:
/Library/Application Support/Comodo/Antivirus/Quarantine: Permission denied
and also: /dev/fd/3
When I try navigating to the directory I can only get to Application Support, and then from that directory when I run cd Comodo I get Comodo: No such file or directory But it is there if find is finding it right? or no? <<< I believe this is just the find process?
When I try to navigate to it using the finder I just get to Application Support, and Comodo is not there. I am displaying hidden files too. I am trying to remove all files of a certain type so I can get a new program to work properly. This find command suggests one of these files is still out there but I can not get to it.
For /dev/fd/3 why is this being matched? I'm no expert but I just did a quick google search and this is a file descriptor right? Does it even have content? How/Why could it match .rvmrc? When I try looking at it with cat I just get a bad file descriptor error. (Should I extract this into a separate question?)
Thanks for your help.
It looks like your user do not have sufficient privileges to access this Comodo directory.
Try ls -la "/Library/Application Support"/* . This should show who can access Comodo. If it is owned by yourself, then you can do a
chmod +rx "/Library/Application Support/Comodo/"
, then only view its content.
You might have access Quarantine because the find -L followed a link.
Edit
Once you have done this and cannot chmod anymore, then try to see who owns the dir:
ls -lad "/Library/Application Support/Comodo/Antivirus/"*

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.

/usr/bin Permission change on mac

I am trying to set up java on XCODE and it needs to access /usr/bin/java at some point. But I cannot get hold of this folder and I get this message:
The folder “java” can’t be opened because you don’t have permission to see its contents.
Even when I try to reach the permission through Get Info the system does not open the folder because of the same restriction. I think it is possible to change the permission through Terminal but I am afraid to blow up something on my mac.
How can I change the permission safely?
As the root user ("sudo su -" from the command line and then enter system password), execute the following from the command line -- "chmod 777 /usr/bin/java" . That won't blow anything up, and will allow read/write/execute (rwx) to the directory's owner, group, and guests.
-TU

Resources