Showing posts with label Commands. Show all posts
Showing posts with label Commands. Show all posts

Linux Command for calculation - bc


bc Command in Linux with Example


bc is a command line basic calculator. bc is typically used as either a mathematical scripting language or as an interactive mathematical shell.

Doing arithmetic calculation use bc as below.

bc can be used with echo command

Addition

$ echo "3+5" | bc
8

Substraction

$ echo "15-3" | bc
12

Cal Command in Linux

Linux Basic Command - cal to display calendar


Cal displays a simple calendar.  If arguments are not specified, the current month is displayed.  The options are as follows:
     -1      Display single month output.  (This is the default.)
     -3      Display prev/current/next month output.
     -s      Display Sunday as the first day of the week.  (This is the default.)
     -m      Display Monday as the first day of the week.
     -j      Display Julian dates (days one-based, numbered from January 1).

     -y      Display a calendar for the current year.

Internal and External Commands in Linux UNIX

Internal Command


Internal commands are the commands that are executed directly by the shell. These commands will not have a separate process. You can’t find these commands in PATH directories in system because these are built in shell command. echo is an external command and if you try to find its path it will show shell built in.

$ type echo
echo is a shell builtin

when you run echo the system will not search in PATH location, it will execute it from shell builtin commands that are stored in some separate file.

Test Command in Linux



Test command is used to check the condition is true or not. To test a condition use test or [ ] as explained below.

Syntax of test command


if test condition
then
statement
fi

Shift Command


Shift

The shift command can take a numerical parameter indicating how many positions to shift.

Examples of Shift Command usage:


Echo Command and Quoting in Linux


Echo Command With Examples


The echo command writes character strings to standard output. Strings are separated by spaces, and a new-line character follows the last String parameter specified. If no String parameter is specified, a blank line (new-line character) is displayed.

Example:


Here x is assigned as 52

x=52

dot (.) in Linux



dot (.) can be used many ways in Linux. Here are some uses of dot in Linux

  dot (.) as file name


When working with filenames, a leading dot is the prefix of a "hidden file". To show hidden file in listing use command ls –al

Keyboard (ctrl) commands in Linux



Keyboard (Ctrl) Commands - when things go wrong


Keyboard or control commands are the command that are used with combination of ctrl + any other key. These commands are also useful when things goes wrong, like system freezes, to interrupt any process, killing any process, the output of programs scrolls continuously etc.  



batch & at commands in Linux


at command


at: We can schedule jobs at a specified time using at command.

atq: This command lists all pending jobs. It shows Job number followed by date time and job class. at -l is similar to atq.

atrm: It is used to deletes a jobs identified by their job number. at -d is similar to atrm.
Examples:

to run a command cat file after 1 minute run the following

$ at now + 1 minute
 at> cat file
ctrl+d

$

jobs, fg & bg commands in Linux


Jobs Command:

jobs: Jobs command is used to list the jobs that you are running in the background and in the foreground. If the prompt is returned with no information no jobs are present. All shells are not capable of running this command. This command is only available in the csh, bash, tcsh, and ksh shells.

Options:

-p           Display the PID of process group leader

-l             Provides more information about each job listed. This information includes the job                 number,  current job, process group ID, state, and the command that initiated the job.
-n            Display only jobs that have stopped or exited since last notified

-r             Display running jobs

-s            Display stopped jobs

 Each job will be listed with a number; to resume a job, enter %  (percent sign) followed by the number of the job. For example, To restart job number two
$ %2


Linux : ls command

ls Command:


ls is the most basic command of Linux. It list information about the FILEs (the current directory by default). 


Linux ls command


ls command examples:

1- Listing files:
$ ls

2- List directory with relative path
$ ls /home/user


Basic Linux Command


Basic Linux Command : Here are some basic command of Linux with example. Everyone working on Linux should have knowledge of these commands.