We’re rewarding the question askers & reputations are being recalculated! Read more.
105

All rm needs is write+execute permission on the parent directory. The permissions of the file itself are irrelevant. Here's a reference which explains the permissions model more clearly than I ever could: Any attempt to access a file's data requires read permission. Any attempt to modify a file's data requires write permission. Any attempt to ...


53

Ok, according to your comment to ire_and_curses, what you really want to do is make some files immutable. You can do that with the chattr command. For example: e.g. $ cd /tmp $ touch immutable-file $ sudo chattr +i immutable-file $ rm -f immutable-file rm: remove write-protected regular empty file `immutable-file'? y rm: cannot remove `immutable-file': ...


49

You can set the "immutable" attribute with most filesystems in Linux. chattr +i foo/bar To remove the immutable attribute, you use - instead of +: chattr -i foo/bar To see the current attributes for a file, you can use lsattr: lsattr foo/bar The chattr(1) manpage provides a description of all the available attributes. Here is the description for i: ...


43

You could do this: :set noro That unsets the read-only flag, but if the underlying file is still not writable by you then vim still will be unable to write to it.


30

I think you have have misunderstood what -w does. It does not check to see if the file has "Write permissions", it checks to see if the file is writable by the invoking user. More specifically, it calls access(2) or similar. eg if a script has if [ -w /etc/shadow ] then if you run strace on the script you may see a line similar to faccessat(AT_FDCWD, "/...


29

The default behaviour for most Linux file systems is to safeguard your data. When the kernel detects an error in the storage subsystem it will make the filesystem read-only to prevent (further) data corruption. You can tune this somewhat with the mount option errors={continue|remount-ro|panic} which are documented in the system manual (man mount). When ...


26

test -w aka [ -w doesn't check the file mode. It checks if it's writable. For root, it is. $ help test | grep '\-w' -w FILE True if the file is writable by you. The way I would test would be to do a bitwise comparison against the output of stat(1) ("%a Access rights in octal"). (( 0$(stat -c %a somefile) & 0200 )) && echo rw || ...


22

As the error message says: the filesystem on which omitted is located is read-only. You can't do anything to modify that filesystem, including removing files. You can check the mount point of the filesystem by running df omitted. It is probably /mnt given the command you're running. You can remount the filesystem as read-write by running mount -o remount,...


21

Bind mount is just... well... a bind mount. I.e. it's not a new mount. It just "links"/"exposes"/"considers" a subdirectory as a new mount point. As such it cannot alter the mount parameters. That's why you're getting complaints: # mount /mnt/1/lala /mnt/2 -o bind,ro mount: warning: /mnt/2 seems to be mounted read-write. But as you said a normal bind mount ...


19

squashfs is a read-only compressed file system. It has no provision to make modification to it once it's been created. So you couldn't write to it even if the underlying block device could be made writeable. You'd need to create a new squashfs image of the whole filesystem with your modifications and burn it to the storage device where that file system is ...


18

It is possible using a union filesystem layer like aufs. Demo: Create a filesystem image # dd if=/dev/zero of=/tmp/image bs=1024 count=1024 1024+0 records in 1024+0 records out 1048576 bytes (1.0 MB) copied, 0.0028428 s, 369 MB/s # mke2fs /tmp/image ... Mount it, populate it # mkdir /tmp/imgmnt # mount -o loop /tmp/image /tmp/imgmnt # echo hello > ...


15

ISO 9660 is by design a read-only file system. This means that all the data has to be written in one go to the medium. Once written, there is no provision for altering the stored content. Therefore ISO 9660 is not suitable to be used on random-writable media, such as hard disks. You need to copy whole directory tree to another directory, make your changes ...


15

You normally can't remount a filesystem as read-only if processes have a file on it that's open for writing, or if it contains a file that's deleted but still open. Similarly, you can't unmount a filesystem that has any file open (or similar uses of files such as a process having its current directory there, a running executable, etc.). You can use umount -...


15

It is the correct behaviour. You use the -f flag, which mean: -f, --fake: Causes everything to be done except for the actual system call; if it's not obvious, this ``fakes'' mounting the filesystem. This option is useful in conjunction with the -v flag to determine what the mount command is trying to do. It can also be used to add entries for ...


12

try with blockdev --setrw or hdparm -r 0


11

New answer (2015-03-22) (Note: This answer is simpler than previous, but not more secure. My first answer is stronger because you could keep files read-only by fs mount options before permission flags. So forcing to write a files without permission to write won't work at all.) Yes, under Debian, there is a package: fsprotect (homepage). It use aufs (by ...


11

I've contacted SanDisk, and they've said it happened "beacuse the flash drive has detected a potential fault and became write-protected to prevent data loss. There is no method to fix this." They've offered to replace it if I send it to them on my own expense. They are, as it turns out, aware of this problem. I, however, chose to switch to another company'...


11

Mounting or remounting a filesystem is done using the mount(2) syscall. When remounting, this takes the target location (the mountpoint), the flags to be used in the mount operation, and any extra data used for the specific filesystem involved. When remounting read-only, the flags used are MS_RDONLY and MS_REMOUNT; you're also supposed to provide any other ...


10

Why is your system read-only? Try to search in dmesg | less. If you would like remount it to read-write, use mount -o remount,rw /


9

You can run chmod from within vim: :!chmod +w % ! means run a shell command, and % is the current filename. You can also just force the file write: :w!


9

The proper solution is really to mount it twice. On the command line: mount -t none -o bind /source/dir /destination/dir mount -t none -o bind,remount,ro /source/dir /destination/dir In /etc/fstab: /source/dir /destination/dir none bind 0 0 /source/dir /destination/dir none remount,bind,ro 0 0 The manual (man ...


9

OK, so I do have a working read-only system on an SD card that allows the read/write switch to be set to read-only mode. I'm going to answer my own question, since I have a feeling I'll be looking here again for the steps, and hopefully this will help someone else out. While setting various directories in /etc/fstab as read-only on a Red Hat Enterprise ...


8

Update: It seems there are 2 other simpler ways to do this on Ubuntu (at least the later versions): sudo apt-get install overlayroot followed by setting overlayroot="tmpfs:swap=1,recurse=0" in /etc/overlayroot.local.conf. sudo apt-get install fsprotect followed by passing fsprotect as a kernel parameter I finally figured out how to do this with the root ...


8

Unmount the drive and run badblocks -n on it. This will rewrite every sector on the drive — read-then-write, so it's nondestructive — which forces the drive to swap in a fresh sector for every dodgy one found during the pass. If badblocks can't fix it, you could step up to SpinRite which does that and more. If either of those "fixes" the drive ...


8

An array could make the string parsing without the need for a temporal file. Don't forget to turn off globbing. set -f IFS=: Hosts=($HostFull) HostMain=${Hosts[0]} HostMid=${Hosts[1]} HostSub=${Hosts[2]} set +f


8

You should set necessary directory permissions. For directories they are: read: permitted to view files and sub-directories in that directory write: permitted to create files and sub-directories in that directory execute: permitted to enter into a directory. For files the situation is similar, it's quite obvious, so you can handle it on your own. Numeric ...


7

If you happen to run an OS supporting it (Linux & BSDs), you might use Unionfs to somewhat mount an ISO in read-write mode. All writes will be actually be done on a read-write file system but depending on your needs, that might fit them.


6

A read-only /etc is increasingly common on embedded devices. A rarely-changing /etc is also increasingly common on desktop and server installations, with files like /etc/mtab and /etc/resolv.conf located on another filesystem and symbolically linked in /etc (so that files in /etc need to be modified when installing software or when the computer's ...


6

Tar didn't overwrite the existing read-only file, it removed it and then created a new file with the same name. This is a consequence of the way -x works; it replaces existing versions of a file by design in order to accommodate the old incremental backup method of appending files to an existing archive. A tar archive might have multiple versions of a file ...


6

From the error it would seem that the disk partition your home directory resides is mounted read-only. You can verify that by issuing the following command in a terminal prompt: mount | grep home That should output something like: /dev/xxxxx on /home type ext3 (ro) Note the ro in parenthesis for read-only. If that command gives no output, probably the ...


Only top voted, non community-wiki answers of a minimum length are eligible