Linux Commands
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.
Administrative Login
User Login
Command Navigation
Here is a list of commonly used keyboard shortcuts using the default shell, bash :
Keyboard shortcuts | Description |
---|---|
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-C | Copy |
Ctrl-Shift-V or Shift-Insert | Paste |
Tab | Command completion. |
Let's work with some simple commands. The first one is an exit.
exit
The exit command is used to exit the shell.
datasoft @ datasoft-linux ~$ exit
clear
The clear command is used to clear the terminal screen.
help
The help command is used to display information about commands
Syntax:
help [-d | -m | -s]
Example:
Option:
-d
Description: Display a short description for each topic.
Example :
Option:
-m
Description: Display usage in pseudo-manpage format.
Example:
Option:
-s
Description: Display a short usage synopsis for each topic matching.
Example:
Arguments: PATTERN
If PATTERN is specified, gives detailed help on all commands matching PATTERN, otherwise the list of help topics is printed.
Calendar
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.
Syntax:
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]
Example:
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.
Date
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.
Syntax:
date [OPTION]..[+FORMAT]
date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]
Example:
Note: Running date with no options will output the system date and time.
Option:
-d, --date=STRING
Description: Display time described by STRING, as opposed to the default, which is 'now'.
Examples:
Display date of next Sunday :
Display past dates :
Option:
-f, --file=DATEFILE
Description: like --date once for each line of DATEFILE.
Example:
Option:
-r, --reference=FILE
Description: display the last modification time of FILE.
Option:
-R, --rfc-2822
Description: output date and time in RFC 2822 format.
Example:
Option:
--rfc-3339=TIMESPEC
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.
Option:
-s, --set=STRING
Description: Set time described by STRINGS.
Example:
Option :
-u, --utc, --universal
Description :
Example:
Various Date Command Formats
Syntax:
date +%<format-option>
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 |
%H | hour | Hours | 00..23 |
%I | hour | Hours | 01..12 |
%j | day of year | Day | 001..366 |
%k | hour | Hours | 0..23 |
%l | hour | Hours | 1..12 |
%m | month | Month | 01..12 |
%M | minute | Minutes | 00..59 |
%n | a newline | ||
%N | nanoseconds () | Seconds | 000000000..999999999 |
%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 |
%S | second (00..60) | Seconds | 30 |
%t | a tab | ||
%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 |
%Y | year | Year | 2014 |
%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 |
Example:
# Display a date in mm-dd-yyyy format.
Previous:
Web-based system administration using Webmin
Next:
Linux - Control-operators