A shell is a program that provides the traditional, text-only user interface for Linux and other Unix-like operating systems. The shell is an intermediary program which interprets the commands that are typed into a console (an all-text display mode) or terminal window (an all-text window) in a GUI (graphical user interface) and translates them into commands that the kernel (the core of the operating system) understands. A shell is the most fundamental way that a user can interact with the system, and the shell hides the details of the underlying operating system from the user. Almost all Linux distributions supply a shell program from the GNU Project called bash. The name "bash" is a Unix shell written by Brian Fox for the GNU Project as a free software replacement for the Bourne shell (sh). Released in 1989, it has been distributed widely as the shell for the GNU operating system and as a default shell on Linux and Mac OS X.
A shell prompt, also referred to as a command prompt is a character or set of characters at the start of the command line that indicates that the shell is ready to receive commands. It usually ends with a dollar sign ($) for ordinary users and a pound sign (#) for the root (i.e., administrative) user. The term command line is sometimes used interchangeably with the shell prompt, because that is where the user enters commands. For example, instructions for performing some activity might say "Enter the following at the command line," which is the same as saying "Enter the following at the shell prompt." However, a command line is not a program but rather just the space to the right of a shell prompt.
Here is a list of commonly used keyboard shortcuts using the default shell, bash :
|Up Arrow & Down Arrow||Previously used commands in the current session.
|Ctrl-A||Move the cursor to beginning of the current line.|
|Ctrl-E||Move the cursor to the end of the current line.|
|Ctrl-U||Delete all the line from the start of the line to the current cursor position.|
|Ctrl-H||Same as backspace.|
|Ctrl-K||Delete all the line from the current cursor position.|
|Ctrl-W||Delete the word before the current cursor position.|
|Ctrl-D||On a blank line is the same as the exit command. Otherwise, it deletes the character in front of the cursor.|
|Ctrl-C||Stop the current running command.|
|Ctrl-Shift-V or Shift-Insert||Paste|
Let's work with some simple commands. The first one is an exit.
The exit command is used to exit the shell.
datasoft @ datasoft-linux ~$ exit
The clear command is used to clear the terminal screen.
The help command is used to display information about commands
help [-d | -m | -s]
datasoft @ datasoft-linux ~$ help exit exit: exit [n] Exit the shell. Exits the shell with a status of N. If N is omitted, the exit status is that of the last command executed. datasoft @ datasoft-linux ~$
Description: Display a short description for each topic.
datasoft @ datasoft-linux ~$ help -d exit exit - Exit the shell. datasoft @ datasoft-linux ~$
Description: Display usage in pseudo-manpage format.
datasoft @ datasoft-linux ~$ help -m exit NAME exit - Exit the shell. SYNOPSIS exit [n] DESCRIPTION Exit the shell. Exits the shell with a status of N. If N is omitted, the exit status is that of the last command executed. SEE ALSO bash(1) IMPLEMENTATION GNU bash, version 4.3.8(1)-release (i686-pc-linux-gnu) Copyright (C) 2013 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> datasoft @ datasoft-linux ~$
Description: Display a short usage synopsis for each topic matching.
datasoft @ datasoft-linux ~$ help -s exit exit: exit [n] datasoft @ datasoft-linux ~$
If PATTERN is specified, gives detailed help on all commands matching PATTERN, otherwise the list of help topics is printed.
Cal or ncal is used to display a calendar and the date of Easter. The cal utility displays a simple calendar in traditional format and ncal offers an alternative layout.
cal [-3hjy] [-A number] [-B number] [[month] year]
cal [-3hj] [-A number] [-B number] -m month [year]
ncal [-3bhjJpwySM] [-A number] [-B number] [-S country_code] [[month] year]
ncal [-3bhjJeoSM] [-A number] [-B number] [year] ncal [-CN] [-H yyyy-mm-dd] [-d yyyy-mm]
datasoft @ datasoft-linux ~$ cal August 2014 Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 datasoft @ datasoft-linux ~$ ncal August 2014 Su 3 10 17 24 31 Mo 4 11 18 25 Tu 5 12 19 26 We 6 13 20 27 Th 7 14 21 28 Fr 1 8 15 22 29 Sa 2 9 16 23 30 datasoft @ datasoft-linux ~$
Note: Not all options can be used together. For example "-3 -A 2 -B -y -m 7" means, show the three months around the seventh month, three before that, two after that and the whole year. ncal will warn about these combinations.
The date command is used to display the current time in the given FORMAT, or set the system date. The command can display the date, time, time zone and more.
date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]
datasoft @ datasoft-linux ~$ date Sat Aug 23 17:40:43 IST 2014 datasoft @ datasoft-linux ~$
Note: Running date with no options will output the system date and time.
Description: Display time described by STRING, as opposed to the default, which is 'now'.
datasoft @ datasoft-linux ~$ date --date="4/15/2015" Wed Apr 15 00:00:00 IST 2015 datasoft @ datasoft-linux ~$ date --date="15 apr 2015" Wed Apr 15 00:00:00 IST 2015 datasoft @ datasoft-linux ~$ date --date="Apr 15 2015" Wed Apr 15 00:00:00 IST 2015 datasoft @ datasoft-linux ~$
Display date of next Sunday :
datasoft @ datasoft-linux ~$ date Sat Aug 23 17:46:37 IST 2014 datasoft @ datasoft-linux ~$ date --date="next sun" Sun Aug 24 00:00:00 IST 2014 datasoft @ datasoft-linux ~$
Display past dates :
datasoft @ datasoft-linux ~$ date Sat Aug 23 17:48:03 IST 2014 datasoft @ datasoft-linux ~$ date --date='15 seconds ago' Sat Aug 23 17:48:36 IST 2014 datasoft @ datasoft-linux ~$ date --date='1 day ago' Fri Aug 22 17:49:13 IST 2014 datasoft @ datasoft-linux ~$ date --date='yesterday' Fri Aug 22 17:49:29 IST 2014 datasoft @ datasoft-linux ~$ date --date='1 month ago' Wed Jul 23 17:49:52 IST 2014 datasoft @ datasoft-linux ~$ date --date='2 years ago' Thu Aug 23 17:50:14 IST 2012 datasoft @ datasoft-linux ~
Description: like --date once for each line of DATEFILE.
datasoft @ datasoft-linux ~$ cat datefile datasoft @ datasoft-linux ~$ cat datefile Feb 21 1993 Jan 02 2012 datasoft @ datasoft-linux ~$ date --file=datefile Sun Feb 21 00:00:00 IST 1993 Mon Jan 2 00:00:00 IST 2012 datasoft @ datasoft-linux ~$
Description: display the last modification time of FILE.
Description: output date and time in RFC 2822 format.
Mon, 07 Aug 2006 12:34:56 -0600
Description: output date and time in RFC 3339 format. TIMESPEC=‘date’, ‘seconds’, or ‘ns’ for date and time to the indicated precision.
Example: Date and time components are separated by a single space.
Description: Set time described by STRINGS.
datasoft @ datasoft-linux ~$ date Sat Aug 23 18:00:18 IST 2014 datasoft @ datasoft-linux ~$ date -s "08/23/2014 06:01:00" Sat Aug 23 06:01:00 IST 2014 datasoft @ datasoft-linux ~$ date Sat Aug 23 18:02:50 IST 2014
-u, --utc, --universal
datasoft @ datasoft-linux ~$ date Sat Aug 23 18:05:23 IST 2014 datasoft @ datasoft-linux ~$ date -u Sat Aug 23 12:35:30 UTC 2014 datasoft @ datasoft-linux ~$
Various Date Command Formats
FORMAT controls the output. Interpreted sequences are :
|Options||Description||Related with||Values or example|
|%%||a literal %|
|%a||Locale’s abbreviated weekday name||Date||Sun|
|%A||locale’s full weekday name||Date||Sunday|
|%b||locale’s abbreviated month name||Month||Jan|
|%B||locale’s full month name||Month||January|
|%c||locale’s date and time||Date and time||Thu Mar 3 23:05:25 2005|
|%C||century; like %Y, except omit last two digits||Century||20|
|%d||day of month (two digits, zero filled)||Day||01|
|%D||date; same as %m/%d/%y [mm/dd/yy]||Date||01/27/14|
|%e||day of month, space padded; same as %_d||Day||27|
|%F||full date; same as %Y-%m-%d||Date||2014-01-27|
|%g||last two digits of year of ISO week number (see %G)||Year||14|
|%G||year of ISO week number (see %V); normally useful only with %V||Year||2014|
|%h||same as %b||Month||Jan|
|%j||day of year||Day||001..366|
|%p||locale’s equivalent of either AM or PM; blank if not known||Hours||AM or PM|
|%P||like %p, but lower case||Hours||am or pm|
|%r||locale’s 12-hour clock time||Time||11:11:04 PM|
|%R||24-hour hour and minute; same as %H:%M||Time||10:23|
|%s||seconds since 1970-01-01 00:00:00 UTC||Seconds||1390831606|
|%T||time; same as %H:%M:%S||Time||10:24:48|
|%u||day of week (1..7)||Day||1 is Monday|
|%U||week number of year, with Sunday as first day of week (00..53)||Week||04|
|%V||ISO week number, with Monday as first day of week (01..53)||Week||05|
|%w||day of week (0..6)||Day||0 is Sunday|
|%W||week number of year, with Monday as first day of week (00..53)||Week||04|
|%x||locale’s date representation||Date||01/27/2014|
|%X||locale’s time representation||Time||10:30:41 AM|
|%y||last two digits of year||Year||14|
|%z||+hhmm numeric timezone (e.g., -0400)||Time zone||+0530|
|%:z||+hh:mm numeric timezone (e.g., -04:00)||Time zone||+05:30|
|%::z||+hh:mm:ss numeric time zone (e.g., -04:00:00)||Time zone||+05:30:00|
|%:::z||numeric time zone with : to necessary precision (e.g., -04, +05:30)||Time zone||+05:30|
|%Z||alphabetic time zone abbreviation (e.g., EDT)||Time zone||IST|
# Display a date in mm-dd-yyyy format.
datasoft @ datasoft-linux ~$ date +%d-%m-%Y 23-08-2014 datasoft @ datasoft-linux ~$
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join
We are closing our Disqus commenting system for some maintenanace issues. You may write to us at reach[at]yahoo[dot]com or visit us at Facebook