Hey Guys this is going to be a new series of posts in which i will be sharing some cool linux tips. You can watch the video of this post on http://www.youtube.com/linuxking
So here is the first tip Chmod:
I hope you guys are already familiar with chmod command if not checkout my Youtube “Linuxking” channel for theses commands.
With Chmod you can change the mode of the files and directories.
e.g
chmod 775 dir command will change the permission on directory with rwxrwxrw-
Also using -R option with chmod will change the permission on the directory as well the content within the directory with same permissions.
However lets say you want to change the permissions of a directories to executable within a directory without changing permissions of file use the below tip.
Lets say you have a directory “test1” & “test2” inside “test” directory
test directory has also a file inside it called file1.txt
file1.txt has permission rw——-
directory test1 has permission rwx——
directory test2 has permission rw——-
linux-11oz:/test # ls -ltr total 0 -rw------- 1 root root 0 Mar 22 17:06 file.txt drwx------ 1 root root 0 Mar 22 17:07 test2 drwx------ 1 root root 0 Mar 22 17:07 test1
Now if you try to change the permission with a simple ” chmod -R command ” of all the directories to “executable” inside test directory you could also change permission of the file inside test diretory.
Example:
linux-11oz:/ # chmod -R ug+x test/ linux-11oz:/ # cd test/ linux-11oz:/test # ls -ltr total 0 -rwx--x--- 1 root root 0 Mar 22 17:06 file.txt (You can see that the file also became executable) drwx--x--- 1 root root 0 Mar 22 17:07 test2 drwx--x--- 1 root root 0 Mar 22 17:07 test1
Now to avoid such situation we will use X instead of x, lets see the impact of X with chmod command
linux-11oz:/ # chmod -R ug+X test/ linux-11oz:/ # cd test/ linux-11oz:/test # ls -ltr total 0 -rw------- 1 root root 0 Mar 22 17:06 file.txt (You can see the file's permission has not changed to executable) drwx--x--- 1 root root 0 Mar 22 17:07 test2 drwx--x--- 1 root root 0 Mar 22 17:07 test1 linux-11oz:/test #
I hope you have Enjoyed this tip, keep visiting our site for more information.