Hi there!, Lets learn few more about Linux/Unix commands.
chmod stands for change mode. It’s used to change access of a file. Linux has total 27 kinds of file permissions. listing few of them.
Please don’t apply this command outside of your home directory. If you will change access on System Directory with sudo command, you may have to reinstall your OS again.
chmod [references][operator][modes] file...
we can also say that, this syntax as who(user) as reference,what(what permission) as operator, mode as which(which permission).
[reference]: It represents that whom to give permission.
|g||group||Users who are Members of the file’s group|
|o||others||User who are neither the file’s owner nor members of the file’s group|
|a||all||All three of the above, same as ugo|
[operator]: It represents what permission we are making. Are we adding or removing or setting new permission?
|+||add the permission.|
|–||remove the permission.|
|=||set the permission and wipe out previous permissions.|
[modes]: It represents which permission to be granted.
|r||read||read permission to a file or a directory|
|w||write||write permission to a file or a directory|
|x||execute||execute permission to a file|
Please see left sided values in above example ( like drwxrwxr-x or -rw-r–r– etc), we called these symbolic value. These sections divided into 4 parts- File types, owner, group and other.
Let’s make this example simple to see what permission given to which file. I am taking few examples from the above screenshot.
|File types||owner permission||group permission||other permission||hard link||file/directory name|
File type: It has two types
d: for directory and
– : for regular file.
owner permission: we can see different owner permissions.
rwx: For Desktop & payal directories, the directory’s owner can create files within it, can list its contents and descend into it.
rw-: For get-docker.sh file, the file owner can read from the file and write to the file but can’t execute the file as “-” ( which means no permission) provided in execute position.
r-x: For test.sh file, the file owner can read from the file and execute the file.
group permission: we can see different group permission.
r-x: For Desktop directory, the member of directory’s group can read and descend into it.
r–: For get-docker.sh & test.sh files, the members of the file’s group can read from the file but can’t write and execute as “-” provided for both places.
rwx: For payal directory, the members of the directory’s group can read, write and descend into it.
r-x: For Desktop and payal directories, the other users can read and descend into it.
r–: For get-docker.sh & test.sh files, other users can only read from the file .
File Permission can also be given through octa values:
Let’s take an example from above example for Desktop directory.
rwx r-x r-x u g o
Now we can change the permission using below ways:
chmod u+rwx g+rx o+rx
So both of the commands will give same permission to the file.
cal stands for calendar i.e. use to see calendar in terminal.
cal [-jy] [[month] year]
-j: Show julian dates (days one-based, numbered from January 1)
-y: Show calendar from the current year
grep stands for Global Regular Expression Print. It is used to search for a particular pattern of a character and print all the contain that pattern.
grep [OPTIONs]... PATTERN [FILE]..
We can use grep command in so many ways. Given few examples.
grep [options] Pattern [file]: Search the file with Options. There are so many options, I provided few as examples.
- grep -c “string-to-search” [FILE] : It find the number of lines that matches the pattern.
Do grep –help to know more about Options.
grep “string-to-search” [file] : Search the word in a single file.
grep “string-to-search” [file1] [file2] [file3] [file4]: Search the word in a multiple files.
[some-commands] | grep “string-to-search” : Put some command and search.
cat [file] | grep “string-to-search” : While concatenate the file and search particular.
zip command used for compressed files with .zip extension. We can zip files and directories in linux/unix. zip files use in Linux for many reasons. Even we can share the zip file with Window users instead of .tar extension as it won’t be compatible.
zip [OPTIONS] filename.zip [list of files]
- zip filename.zip [file1] [file2] : Creating zip with files:
- zip filename.zip [list of files] [list of directories] : Creating zip with files and directories.
- zip -e filename.zip [list of files] : Creating password protecting zip.
unzip command used for unzipping the zip files.
unzip [OPTIONS] [filename.zip]
- unzip [filename.zip] : Unzipping the above created zip file combined with files and directories.
- unzip -P [password] [filename.zip] : Unzipping password protected zip file.
NOTE: Providing password in command line is not secure and it should be avoided. We can overcome this situation just providing the below command without providing the password. So, if the zip file is encrypted then unzip command will prompt with window to enter the password.