Basic Linux TutorialIntroduction – What is it? Why to learn? Linux installation directory structures Boot process Run levels in Linux Desktop Environments Different shells BASH Internal and External Commands Basic Linux Commands Important files and directories in Linux Environmental and Shell Variables Command history in Linux Character classes in Linux Text editors vim nano Searching files Creating new files Viewing File Contents File commands File permissions and ownership WildCards (Globbing) in files File compression Directory commands xargs command in Linux Comparing files Searching patterns using grep command Translating the characters using tr command Extracting data using cut command Stream editing using sed command Data extraction and reporting using awk command Sorting the file or string input uniq command in Linux Difference between grep, tr, cut, sed and awk commands Hardware commands Hard disk and memory space commands Working with Processes Managing Jobs Working with cron jobs Service command in Linux Network commands Managing Users and Groups Other Popular commands Standard streams and Redirection Pipes Package Managers in Linux
File permissions in linux shellA file or directory can have below types of permission attributes.
- Read (r)
- Write (w)
- chmod – change the file permissions
- chown – change the ownership of the file
- chgrp – change the group of the file
chmod command in Linuxchmod command is used to change the permission of a file or directory. There are 2 ways in which we can specify the permission attributes.
Symbolic file permissionIt is very easy to work with symbolic file permissions. Let us say you want to give write permission on abc.txt file to others(o), then you can use below syntax. Here o stands for others. + means we are adding permission. w means we are adding write permission.
If you want to remove write access from others, you can use below syntax. here – means we are removing permission.
chmod o+w abc.txt
Now let us say you want to add write permission for user of the file and at the same time remove execute permission for group. Then you can execute below command.
chmod o-w abc.txt
chmod u+w,g-x abc.txt
Numerical permissions of fileYou can also use numerical representation in chmod command. Below
chmod 700 abc.txt
chown command in Linuxchown command is used to change the owner and group of a file. Here is the syntax of chown command
For example – To change owner to paul and group to dev for file “abc.txt”, you can use below command.
chown <new_user>:<new_group> file
To change the owner and group of all files in a directory, you can use -R option.
chown paul:dev abc.txt
chown -R paul:dev /home/project
chgrp command in Linuxchgrp command is used to change the group of a file. Here is the syntax of chgrp command.
You can also change the group of files recursively using below syntax.
chgrp <group_name> file
Note that you might need to execute the commands using sudo to avoid error saying operation not permitted.
chgrp -R <group_name> directory
Web development and Automation testing