Linux For Home

Linux For The Home PC - 4683
Showing posts with label fedora. Show all posts
Showing posts with label fedora. Show all posts

Saturday, February 15, 2014

Tutorial 4: Understanding File Permissions and umask

Every file or a folder that we create in unix has a set of permissions for the file owner, group owner and the other users. Let us have a look at these permissions.

Eg. touch test1.

Here we created a new empty file called test1.

Now locate the file in the present working directory and right click on it. Then, click on properties and open the permissions tab as below.























From above screen shot we can see that by default the owner of the file gets Read and Write permissions, while the group users and other users have Read permissions only. Moreover, it can be observed that there is a checkbox for Execute which is unchecked by default. Checking this, makes the file executable. This comes handy especially when your file holds a shell script and you want to execute it on terminal.

Read permission allows user only to read the contents of a file.
Read and write permission allows user to read the contents of a file and add or edit the contents of a file.
Execute permission allows user to execute the file on a terminal.

Please note that whenever a file is created, the above set of permissions would be set by default unless you explicitly mention a different set of permissions while creating a file.

It is interesting to know that each of these permissions have a numeric value associated with it.

Eg.
Read - 4
Write - 2
Execute - 1

This means, when the file has the read, write as well as execute permission, then it has a numeric value as 4+2+1 = 7. However, with default settings the file will always have a value of 6 i.e. it will have read and write permission.

Having said that, let me introduce you to a system variable called umask.

umask - It is a system variable.
When we write umask on terminal and press enter, we get output as 0022.
















The first 0 tells that it is an octal number and the remaining three digits 022 are responsible for the default permissions assigned to a file or a folder. For example, for setting the default permission of a file, unix substracts 022 from 666. This gives the output as 644. This means, the owner of file will have read and write permissions (4 for read and 2 for write) while the group members and other users will only have read permission (4 for read).


We will elaborate these concepts further when we look into chmod command to change the file permissions. 

Friday, February 7, 2014

Tutorial 1: Introduction and some basic commands



Shell scripting is one of the easiest programming languages to learn. It is very useful as you can use it to automate your tasks that otherwise would take long time to perform. In this tutorial, we will start from the easier commands and will move to more complex programs.

Shell: It is an interface between the user and the UNIX Kernel.
This means that the user gives the command to shell which in turn converts the command to a form that can be understood by Kernel.

Kernel: It is a program that manages the system resources.

How to access shell:
Shell can be accessed via a terminal. Terminal is the Unix command prompt that can be accessed from "Applications".
Note: All Unix commands are to be typed in lower case. Else, the commands would not be recognized.

Basic Commands:

1. clear - Clears the screen.

2. who am i - Displays the user name, terminal id and the date and time when the user logged in.

Eg. aditya             pts/0     2014-02-04 19:44

Here aditya is the user name. pts/0 is the terminal id and remaining portion shows the date and time.

3. pwd - It tells the user about present working directory.
Eg. /home/Aditya

4. cal - This command is used to display the calendar of current month, with current date highlighted.
cal command can be enhanced to display the calendar for past and future months.
Eg. cal 3 1983
Above command will display the calendar for March 1983.
The above command can also be used with month name instead of number.
Eg. cal mar 1983 will produce the same result as the previous one.

5. date - This command tells us the day, month, date, year and the time.





This command can also be customized to show the date as per our preference.
Eg. date '+DATE:%m-%y%nTIME:%H:%M:%S'







The above result set shows the month and the year. Then, on the next line it shows time i.e hrs, mins and sec.
Let us examine the extension of the command that we used to customize the actual command.
The extension is enclosed in single quotes.
+ denotes that we are adding an extension to the command.
DATE: is the text to denote the date.
%m denotes month.
- is used as separator.
%y denotes year.
%n denotes new line.
TIME: is the text to denote time.
%H denotes hrs.
: is a separator.
%M denotes mins.
%S denotes seconds.

In next tutorial we will come up with some more interesting commands.