Linux For Home

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

Thursday, February 20, 2014

Tutorial 5: Introduction to ls Command

ls command is used to list files and directories in current working directory.

Eg.

cat > test1
This is a test file.
ls


In the above set of commands we created a file called test1. Later, we executed ls command to see the list of files and directories in pwd.

ls command









The above screenshot shows the output of ls command. We can see that it shows the list of files and directories. The names highlighted in blue are the names of folders while the ones in white are the files. The same can also be verified from the file browser.

ls command can also be used to view the files and folders in another directory.

Eg. ls Desktop

The above command will show the list of files and directories in Desktop folder. It is shown in the below screenshot.

Using ls in different folder










From above screenshot we can see that the Desktop folder has a file named Shell Scripting - In a Nutshell.docx

If we also want to see the files and permissions for the files and the folders then we can use ls command with -l.

Eg. ls -l

ls - l














You can see from the above screenshot that the first line of output shows "total 40".

This means that all the files and folders listed collectively occupy 40 blocks of memory (Each block of memory is 1024 bytes).

Moreover, you can observe that some of the listing the first column starts with d, while for some it starts with -. Please note that, whenever the first column starts with d, then it is a directory while, if the first column starts with - then it is a file.

Now, let us have a look at the permissions. The second, third and the fourth columns tell about the permissions to the owner, next three columns tell about the permissions to the group while the subsequent three columns tell about the permissions to other user.

For example, the Desktop has read, write and execute permissions for the owner, while only read and execute permissions for the group and other users.

Another important extension for ls is -a where 'a' stands for 'All'. When you use ls command with -a, it will show the list of all the files and folders including those which are hidden.

Eg.

ls - a















As seen in the above screenshot, ls -a displayed the list of all the files and folders in present working directory including those which are hidden. Here, all the files and folders starting with . denote hidden.

ls command can be used with many more options however, above two are the most widely used options. As we move further in the tutorial, we will see some more.

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.