-1

Hi I am new to Linux and I need to learn how to perform these 3 tasks

-rw-r--r--@  1 user1  staff     108 Oct 17 21:28 coolstuff.o
  1. Change permissions so that user can read/write/execute, group can read/execute and other can execute. Assume you are not logged in as the root superuser and you are not user user1.
  2. Change ownership from user1 to user2. Assume you are not logged in as the root superuser and you are not user1 or user2.
  3. List all the .o files (and no other files) in this directory (assuming you are currently in the directory), making sure that the permission information for them is shown (as in the example above). This is useful when making sure that the file permission and ownership changes occurred as expected and that other files are unchanged.
azbarcea
  • 3,323
  • 1
  • 20
  • 25

1 Answers1

1

To change directory permissions in Linux, use the following:

    chmod +rwx filename to add permissions.
    chmod -rwx directoryname to remove permissions.
    chmod +x filename to allow executable permissions.
    chmod -wx filename to take out write and executable permissions

The command for changing directory permissions for group owners is similar, but add a “g” for group or “o” for users:

chmod g+w filename
chmod g-wx filename
chmod o+w filename
chmod o-rwx foldername

for changing permission from user1 to user2

chown name filename

for only .o file with permissions

 ls -l *.o
iamdhavalparmar
  • 1,090
  • 6
  • 23
  • Can these commands work even when you are not log in as root or the owner of the file? – Anime_boy Feb 26 '21 at 08:48
  • For the 1st question, you need to be logged in as root user – iamdhavalparmar Feb 26 '21 at 08:51
  • 1
    @Anime_boy: Change permission can be made only by somebody who has ownership of the files. Either they are the owners or the group owning the file/directory. By default `root` is the owner of everything. But if you don't have `root`, you can use `sudo` or be in some relationship with the owner (as last resort, maybe through a process you control that runs with a higher elevated permissions than you have over that file/directory) – azbarcea Feb 28 '21 at 03:29