

We can copy the new_fstab over the existing fstab and our changes will have been made.Īs these are changes to the fstab file, they’d take effect when the computer was next rebooted, or immediately if the mount command was used as so: sudo mount -a Be Careful Out There The file permissions and ownership are now correct. sudo chmod -reference=/etc/fstab new_fstab sudo chown -reference=/etc/fstab new_fstab ls -l new_fstab We can then use ls to check that the attributes of the edited file are correctly set before we copy that back over the original file. It forces chmod and chown to take the file mode permissions and file ownership values from that file and to copy them to the target file. The -reference option takes a filename as a parameter. The file owner is dave, and the file mode permissions are read and write for the file owner and read-only for the group and for others. We can use ls to check the file attributes and see what file mode permissions it has and who the file owner is. You won’t need to do this when you are editing your own files. This step is purely for demonstration purposes to make sure the new file does not have the same mode permissions and ownership as the original file. To ensure we have a change of file ownership and mode permissions, we’ll create a new file and then copy the existing file over it. Let’s say we want to edit the fstab file. You need to make sure these are exactly the same on your new file as they are on the original file before you copy the new version over the original file. When you copy a file, the file ownership can change, and the file mode permissions can be altered. If you make a mess of editing the copied file, there’s no harm done. When you’ve finished editing the new file, you can copy it back over the original file. Replicating Ownership and Permissions to a New FIleĪ cautious way to edit system files–and therefore a commendable way to edit system files-is to copy the file and then edit the copy. This command opens gedit and loads the samba config file for editing. Mess up the wrong system file, and you can find yourself locked out of your computer following a reboot. Warning: Don’t edit system files if you don’t know exactly what your changes are going to do to your system. To be strictly accurate you’ll be able to open a system file even if you don’t use sudo, but you won’t be able to save any changes back to the file unless you have used sudo. To edit a system file, you will usually need to use sudo because the owner of the file is likely to be root. Click the green “Save” button to save the file. You can browse to the directory you wish to save the file in, and you can provide a name for the file. This will open a standard file save dialog. To save your file with a different name or in a different location click the menu button on the toolbar and then select “Save As” from the menu. You can also press Ctrl+S to save the file. To save your changes, click the “Save” button in the toolbar. It acts as a reminder that if you want to keep the changes you need to save the file.

This lets you know that changes have been made to the content of the file. If you wish to open a different file, click the “Other documents…” button at the bottom of the menu. If you want to re-open one of the listed files click on the name of the file. You can also press Ctrl+O to open a file. To open an existing text file click the “Open” button in the gedit toolbar. Type gedit, a space, an ampersand &, then press Enter-like this: gedit & You get the command line prompt back straight away and you can carry on using the terminal window even when gedit is running. If you want to use the terminal window while gedit is still open, launch gedit with this command instead. The terminal window will wait for gedit to close before it returns you to the command prompt. It’s often named “Text Editor.” Just search the applications menu for “gedit.” Of course, you can also launch gedit from your Linux desktop’s application menu. You can get on with the task of typing up whatever you’re working on with no distractions. It’s an uncluttered and clean application window.
