What does [rm -rf /] do? - command-line

This is basically recursively remove everything from root right?
Would this really delete everything on the device?
Do any operating systems have protections against running this – like a confirmation or something?
Seemed like a better idea to ask than to try.

The rm command means it is applied for removing file-folders based on the file path but as you have specified rm -rf / it tells to remove the files which are part of the root directory in the Linux or Unix based system, but again it will not do anything until and unless you apply the command with sudo access or super user do access with your system password.

Yes this would delete recursively.
Actually their is also a protection:
rm: it is dangerous to operate recursively on '/'
rm: use --no-preserve-root to override this failsafe

rm -rf is a dangerouse command in linux.if rm -rf run with root privilage it force to delete all files and folders even hidden file and you must install os again. this command has not confirmation question.
As a security measure, you can set rm to always get you approved for the delete operation, it uses the "-i" option whenever you want to delete a file or directory. To make this command permanent, add the following alias to the $ HOME / .bashrc file.
When you run the rm command, it will run with the "-i" option by default. (If you use the "-f" option, these settings will be overwrite)

rm -rf
this code deletes all files on linux (system ,root files include)
this is very dangerous code

Related

VS Code: NoPermissions (FileSystemError): Error: EACCES: permission denied

I'm trying to save a file called app.js on a folder called js.
Vs Code pop up this:
Failed to save 'app.js': Unable to write file 'vscode-remote://wsl+ubuntu-18.04/js/app.js'
(NoPermissions (FileSystemError): Error: EACCES: permission denied, mkdir '/js')
I tried:
sudo chown -R user /mnt/c/Users/myUser/Documents/myFolder/proyectFolder
but I still can't save this file.
Try this, fixed it for me
sudo chown -R username path
Example:
sudo chown -R emanuel /home/emanuel/test/
In the SSH terminal:
Recommended :
sudo chmod -R 777 folder_name_where_your_file_exists
or
sudo chmod -R 755 folder_name_where_your_file_exists
this works for me
sudo chown -R $USER:$USER /home/
TLDR;
If you're using a docker container, avoid making files from within the container because the owner and group permissions may cause problems with your editor (in my case VS Code)
I was running docker container for a Django project from Windows Terminal and using VS Code to edit my code.
It is a Linux file (since everything in Linux is a file) permission problem that arises because the files don't have proper user and/or group permissions. So VS Code tries to tell us that.
The problem I found only happened when I created files from within my docker container.
I would run docker exec ... bash
make new files using touch /path/to/file from the container bash
then try to edit those files on VS Code (say urls.py) only to get the scary permissions error preventing the file from saving.
I suspect that making files from within the container embellishes those files with different owner and group settings than your system would default to if you just ran the commands locally (not in the container).
Changing the file permissions with chown -hR and chgrp -hR would do the trick but to avoid the error altogether I stopped making files from within the container.
Try activating polling:
This worked for me during I tried using wsl.
The below is for individual file:
sudo chown yourUserNAme filename
For an entire directory it will be (when you write ls to terminal, you should see your directory to execute this command):
sudo chown yourUserNAme dirName
For recursive (i.e files and folders inside a folder):
sudo chown -R yourUserNAme dirName
Note: yourUserNAme is, if you do pwd under any Documents, you will see the path: /home/jhon/Documents. Here user is jhon.
Run VS Code as administrator and it will fix the problem.
https://answers.microsoft.com/en-us/windows/forum/all/error-in-vs-code-destination-directory-and-says/e70dc626-6b12-4791-a960-8b704e57098d
Install the extension Save as Root in Remote SSH in VS code.
While saving press Ctrl + Shift + P.
This open the command palette.
Search Save as Root
It is a Linux user permissions problem.
you should use the command:
sudo chown -R $USER:$USER.

How to change added torrent file location for transmission-daemon

The transmission-daemon stores by default some temporary files and the added torrent files in the following directory:
/var/lib/transmission-daemon/.config/transmission-daemon/
Is it possible to set another directory?
Why not just ln -s /var/lib/transmission-daemon/.config/transmission-daemon/ ~/MyAwesomeTransmissionConfigDirecotry or whatnot? ;-)
You'll just probably need sudo to ls it :)

How to delete a specific number of files in multiple folders using command prompt (Windows 10)

I have 30 folders, each with about 1700 files in them. I'd like to delete 500 files from each of these folders. What is the best way to do this using command prompt?
This question shows how to empty out files and this question shows how to do it in python but otherwise, there doesn't seem to be a way of deleting a specific number of files.
Let me know if you need any further information, thanks!
It's very easy to do in Linux. So you can download Git for Windows and run Linux commands in Windows. Please try this in a test folder/files first. You can not recover files once deleted.
Let's say you have 3 files (my-file-1.txt, my-file-2.txt, my-file-3.txt) in your directory. Then go to the directory and execute commands.
$ rm -rf my-file-1.txt # remove my-file-1.txt only
$ rm -rf my-file-1.txt my-file-3.txt # remove my-file-1 and 3
$ rm -rf my-file-{1,3}.txt # remove my-file-1 and 3
$ rm -rf *.txt # remove all txt files
$ rm -rf my-file-*.txt # remove all txt files begin with my-file

Sudo chown mistake?

I have been trying to install Homebrew on my Mac but ran into permission problems since my user is not an administrator.
I followed the suggestions here: https://stackoverflow.com/a/16450503/4909923
su -l admin
sudo chown -R "$USER":admin /usr/local
sudo chown -R $USER:admin /Library/Caches/Homebrew
Now I'm concerned that I have wrongfully changed the ownership of these folders to a specific user. Will it impact my normal user negatively?
changing ownership of /usr/local to a specific user is not a solution. It is a terrible hack and a workaround if you have a single user system. But then you might as well just chown -R / $USER:$USER – fijiaaron Jan 23
If this was a stupid thing to do, how do I restore it to normal?
It should probably look like the image with /lib/ which is another folder in /usr/, with system Read & Write and wheel Read Only.
It should probably look like this (another folder in /usr/):
I think the permissions I mentioned in the comment should be fine, but if you want to be sure everything is set at its default, you can uninstall Homebrew using this script and then reinstall it from scratch.
You can also follow this advice for resetting the permissions.

Rsync files in local directories and chmod issues

When I do rsync this is my command:
rsync -a source dest
I am using dest as my web root /var/www/
so some folder which are set to chmod 777 were no longer with 777 permission.
does rsync change folder permission as well?
What is best way to sync two local folders in same server.? Will rsync delete any changes done in destination and use the source files?
The manual page for rsync says this:
-a, --archive archive mode; equals -rlptgoD (no -H,-A,-X)
Among those options is -p, about which it says:
-p, --perms preserve permissions
So, yes, rsync is making the permissions on dest match those on source in this case. If that is not desired, then read the manual page and decide what options are more appropriate to your need than rsync -a, and use those instead. In the simplest case, add the --no-perms flag after -a to disable the permission preservation.