Trending November 2023 # Input Output Redirection In Linux/Unix Examples # Suggested December 2023 # Top 16 Popular

You are reading the article Input Output Redirection In Linux/Unix Examples updated in November 2023 on the website Minhminhbmm.com. We hope that the information we have shared is helpful to you. If you find the content interesting and meaningful, please share it with your friends and continue to follow and support us for the latest updates. Suggested December 2023 Input Output Redirection In Linux/Unix Examples

What is Redirection?

Redirection is a feature in Linux such that when executing a command, you can change the standard input/output devices. The basic workflow of any Linux command is that it takes an input and give an output.

The standard input (stdin) device is the keyboard.

The standard output (stdout) device is the screen.

With redirection, the above standard input/output can be changed.

In this tutorial, we will learn-

Output Redirection

Example:

Here the output of command ls -al is re-directed to file “listings” instead of your screen.

Note: Use the correct file name while redirecting command output to a file. If there is an existing file with the same name, the redirected command will delete the contents of that file and then it may be overwritten.”

You can redirect standard output, to not just files, but also devices!

Input redirection

The ‘<‘ symbol is used for input(STDIN) redirection

Example: The mail program in Linux can help you send emails from the Terminal.

You can type the contents of the email using the standard device keyboard. But if you want to attach a File to email you can use the input re-direction operator in the following format.

Mail -s "Subject" to-address < Filename

This would attach the file with the email, and it would be sent to the recipient.

File Descriptors (FD)

In Linux/Unix, everything is a file. Regular file, Directories, and even Devices are files. Every File has an associated number called File Descriptor (FD).

Error Redirection

Whenever you execute a program/command at the terminal, 3 files are always open, viz., standard input, standard output, standard error.

These files are always present whenever a program is run. As explained before a file descriptor, is associated with each of these files.

File File Descriptor

Standard Input STDIN

0

Standard Output STDOUT

1

Standard Error STDERR

2

By default, error stream is displayed on the screen. Error redirection is routing the errors to a file other than the screen.

Why Error Redirection?

Error re-direction is one of the very popular features of Unix/Linux.

Frequent UNIX users will reckon that many commands give you massive amounts of errors.

For instance, while searching for files, one typically gets permission denied errors. These errors usually do not help the person searching for a particular file.

While executing shell scripts, you often do NOT want error messages cluttering up the normal program output.

The solution is to re-direct the error messages to a file.

Example 1

Above we are executing a program names myprogram.

The file descriptor for standard error is 2.

Thus, program output is not cluttered with errors.

Example 2

Here is another example which uses find statement –

Using the “find” command, we are searching the “.” current directory for a file with “name” starting with “my”

Example 3: Let’s see a more complex example,

Server Administrators frequently, list directories and store both error and standard output into a file, which can be processed later. Here is the command.

Here,

We are redirecting error output to standard output which in turn is being re-directed to file dirlist. Hence, both the output is written to file dirlist

Summary

Each file in Linux has a corresponding File Descriptor associated with it

The keyboard is the standard input device while your screen is the standard output device

“<” is the input redirection operator

You can re-direct error using its corresponding File Descriptor 2.

You're reading Input Output Redirection In Linux/Unix Examples

How To Change Terminal Output Color In Linux?

Introduction

The Linux Terminal is a powerful tool that allows users to interact with the operating system through the command line. However, the terminal’s default output color can be dull and unattractive. In this article, we will discuss several ways to change the terminal output color in Linux. We’ll cover the use of different commands and tools that can be used to customize the terminal’s color scheme, as well as some examples of how to use them. This guide is intended for Linux users who want to improve their terminal experience by changing the output color.

Using the “LS” command

One of the easiest ways to change the terminal output color in Linux is by using the “ls” command. The “ls” command is used to list the contents of a directory and has several options that can be used to customize the output. Here is an example of the “ls” command −

$ ls

The output will look like this −

bin@ home/ lib32@ media/ root/ sys/ vmlinuz@ boot/ chúng tôi lib64@ mnt/ run/ tmp/ vmlinuz.old@ dev/ chúng tôi libx32@ opt/ sbin@ usr/ etc/ lib@ lost+found/ proc/ srv/ var/ Using the “LS_COLORS” environment variable

Another way to change the color of terminal output on Linux is to use the “LS_COLORS” environment variable. This variable can be used to set the color scheme for the “ls” command. The variable can be set in the “.bashrc” file, located in the user’s home directory. To set the “LS_COLORS” variable, add the following line to the “.bashrc” file −

$ export LS_COLORS='rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.'

The line above sets the color scheme for different file types. For example, “of” represents the directory and “1;35” represents the color code of the directory. Similarly, “ex” represents the executable and “01;32” represents the color code of the executable.

Using the “Tput” command

The “tput” command can be used to change the color of terminal output on Linux. The “tput” command can be used to set the color scheme of the terminal, as well as change the background and text color. Below is an example of how to use the “tput” command to set the text color to red −

$ tput setaf 1

The above command sets the text color to red. To change the background color, use the “setab” option instead of “setaf”. Here is an example of how to use the “tput” command to set the background color to blue −

$ tput setab 4 Using “Gnome-Terminal” ANSI escape codes

Another method to change the color of terminal output is to use ANSI escape codes. ANSI escape codes are standardized commands used to manipulate the behavior and appearance of text in a terminal or terminal emulator. For example, we can write a script that prints the red words “Hello world” on a green background using the echo command and then resets the colors to normal −

#!/bin/sh RED_ON_GREEN='33[31;42m' RESET='33[0m' echo "${RED_ON_GREEN}Hello world${RESET}"

“33” is the most platform-independent way of encoding an ESC character in the terminal, although a reference, “e”, can also be used on Linux. Also, it’s worth noting that the color settings aren’t encapsulated in any way. As a result, if we don’t restart them, they will bleed out of our script, which is undesirable in most cases. We can find the full list of color codes on Wikipedia.

#!/bin/sh RED_FG=`tput setaf 1` GREEN_BG=`tput setab 2` RESET=`tput sgr0` echo "${RED_FG}${GREEN_BG}Hello world${RESET}" tput command

The tput command is another option that can be used to change the color of terminal output on Linux. The tput command allows users to query the terminfo database and provides a convenient way to extract the escape codes we need. For example, we can recreate the script from the previous section using the tput command −

Conclusion

In this article, we have discussed various ways to change the color of terminal output in Linux. We have covered the use of several commands and tools such as the “ls” command, the “LS_COLORS” environment variable, the “tput” command, and Gnome-Terminal to customize the terminal’s color scheme. We also discussed using ANSI escape codes and the tput command to change the color of terminal output. Using these methods, you can make your terminal more visually appealing and easier to read. Remember to use commands with the correct syntax and options to change the color of terminal output on Linux.

Difference Between Dos And Unix

DOS and Unix are operating systems where DOS is supported for only x86 computer systems and Unix supports for all systems. DOS is a single user operating system whereas Unix is a multi-user operating system.

DOS was developed for personal computers (x86 type) and embedded systems. Unix was developed in AT &T Bell University which is primarily used in servers.

What is DOS?

DOS is the short form of Disc Operating system. 86-DOS was developed by Tim Patterson in 1980. Later Microsoft bought this and released MS-DOS in 1981. It is a single processing operating system that can be run only on x86 based computers. This is the first OS used for personal computers which was later replaced by Windows.

DOS is written in C and Assembly language. It has three proprietary versions (MS-DOS, IBM DOS and DR-DOS) and a free version (Free DOS). It has command line interface (CLI). It is read from hard disc or floppy disc. Its kernel is of Monolithic type.

DOS is not case sensitive. It consists of number of commands which are difficult to remember. Dir is the command used for internal code and Deltree for external code. It can perform only a single task at a time. It can’t perform multi-tasking. DOS doesn’t have any inbuilt security.

DOS provide access for various input-output devices. DOS doesn’t need any pointing devices. DOS is mostly used in Embedded systems.

Features of DOS

16-bit operating system

Command line interface

Doesn’t support GUI

Pointer devices are not supported

What is UNIX?

Unix is a multi-tasking and multi-user operating system developed by Dennis Ritchie and Ken Thompson and released on November 3, 1971. It is written in C and assembly language. It can be run on all computers. Unix has many proprietary versions and free and open-source versions.

Unix provides Graphical user interface similar to that of windows. It is a multi-purpose operating system and supports multiple users at a time. It follows the concept of time sharing where CPU time is divided into multiple time slices and each time slice is allotted to a single user. After completion of that time, the control is passed to the next user. Also, it can perform multiple tasks or programs simultaneously. We can work on multiple programs at the same time.

Unix represents the word UNICS that stands for UNiplexed Information Computing system. Unix provides high security compared to other OS. It has multiple layers of security. Each user is assigned with username and password to protect data. The commands of Unix are case-sensitive.

Unix is easy for those who dealt with DOS. The commands of Unix can be understood easily. But it not for beginners as they find it difficult to understand. Unix is only for programmers.

Unix is used in mainframe and super computers. It is widely used in server computers to provide high security and storage. Recently some of the mobile phones and tablets are also using Unix operating system.

Unix manages its memory very effectively. When the number of programs increases, Unix increases its virtual memory. As most of the Unix is written in C language, it is portable.

Features of Unix

Multi-tasking

Multi-processing

Multi-user

High security

Portable

Open source

Difference between DOS and UNIX

The following table highlights the major differences between DOS and UNIX −

Parameter

DOS

UNIX

Definition

DOS is a computer operating system which is read from disc storage devices such as floppy discs or hard disc

Unix is a multi-user and multi-tasking operating system

Released in

DOS is released in 1981

Unix is released in 1971

Full form

DOS stands for Disc Operating System

Unix actually refers to the word UNICS that stands for UNiplexed Information Computing system

No. of users

It allows only single user

It allows multi-users

No. of tasks

It can perform only single task at a time

Unix performs multi-tasking

Case sensitivity

DOS is not case sensitive

Unix is case sensitive

Path separator

It uses backward slash

It uses forward slash

System supported

DOS can only be operated on x86 based systems

Unix can be operated on any system

Interface

DOS is command line operating system

Unix supports few GUI features

Internet

DOS doesn’t support networking

Unix supports networking

Versions available

DOS has three proprietary versions (MS-DOS, IBM DOS and DR-DOS) and a free version (Free DOS)

Unix has a no. of proprietary and free versions

Languages

It is written in C and x86 assembly language

It is written in c and assembly language

Usage

DOS is used in embedded systems

Unix is used in servers and some mobiles

File type

It contains batch files

It contains shell files

Power consumed

It consumes less power

It consumes more power

Memory

It doesn’t have virtual and protected memory

Unix has virtual and protected memory

Security

DOS doesn’t provide any inbuilt security features

Unix is more secured than DOS

Run on

DOS is designed to run only on a single computer

AS Unix supports multi-users, it is designed to run on a network of computers

Conclusion

DOS is an operating system whose services is mostly provided for x86 systems and embedded systems. Unix operating systems are used in large complex computers such as super computers which is used as servers.

The main difference between the two is that the DOS is a single user processing system that can perform only a single task at a time whereas Unix is a multi-user processing system supports multi-tasking.

Workday In Excel (Formula, Examples)

WORKDAY Function in Excel (Table of Contents)

WORKDAY in Excel

Workday function in excel returns the Date, which is the official working day from the date which we feed into the syntax. This is quite useful for getting what would the working day date after selective day counts. As per syntax, we just need to select the date from which we need to count the number of the working day, then select how many days we need to count, and if there is any week off, we have optional. If we select today’s date with 5 days and 2 weeks off days, we will get the date of the same weekday.

Start Your Free Excel Course

Excel functions, formula, charts, formatting creating excel dashboard & others

WORKDAY Formula in Excel:

Below is the WORKDAY Formula in Excel.

Explanation of WORKDAY Formula in Excel

A WORKDAY Function in Excel includes two mandatory parameters and one optional parameter.

Start_date: “Starting date of the project or any work”.

Days: The total number of days required to complete the work or project. This does not include weekends (Saturday and Sunday).

[Holidays]: This is an optional parameter. This section asks whether the days you have mentioned include any holidays. For this, you need to make a list of holidays separately.

WORKDAY Function in Excel by default excludes Saturday and Sunday as weekend days. If at all you need weekends for any other day, you can use chúng tôi function. For example: In the Middle East region, weekend days are Friday & Saturday. In these cases, we can use chúng tôi function instead of a normal WORKDAY Function in Excel.

How to Use WORKDAY Function in Excel?

You can download this WORKDAY Function Excel Template here – WORKDAY Function Excel Template

Example #1

Using the WORKDAY Function in excel, we can generate a series of dates even though we can generate by using the drag and drop option.

Step 1: Enter the one date on cell A2 as 12/Nov/2023.

Step 2: Now, in cell A3, apply the WORKDAY Function as shown in the below image.

=WORKDAY(A2,1)

The above formula takes the cell A2 as a reference and increases the date by 1.

Step 3: Drag the formula until cell A18.

Look at the formula here; 12/Nov/2023 is on Monday; we are increasing the day by 1. When we drag the formula, it will increment the date by 1 until 16/Nov/2023. If you drag one more time, it will jump to 19/Nov/2023 and excludes 17/Nov/2023 and 18/Nov/2023; those are weekends.

Similarly, in the next week, workdays are from 19/Nov/2023 to 23/Nov/2023, and weekends are 24/Nov/2023 and 25/Nov/2023.

Example #2

The project starting date and project duration date calculate the project ending date by using a WORKDAY Function in Excel.

Note: No holidays apply to these projects.

Step 1: Copy and paste the above data to an excel sheet.

Step 2: Apply the WORKDAY Function in column C starting from cell C2.

=WORKDAY(A2,B2)

Result is :

Example #3

Consider the above example data for this also. But here, the list of holidays is available to estimate the project ending date.

The list of holidays are:

Apply the same formula as shown in example 2, but here you need to add one more parameter, i.e. holidays.

=WORKDAY(A2,B2,$G$2:$G$21)

Result is :

Example 2 vs Example 3:

Now we will see the difference between the two examples.

In the second example for the first project-ending date is 8/8/2023, and there is one holiday, for example, 3, so the ending date increased by 1 day.

For the second project, the ending date is 30/01/2023, for example, 2 and example 3; there 5 holidays, so the ending date increased by 7 days because of the in-between weekend.

Example #4

Assume you are working in the Accounts Receivable team; you have a list of invoices and due dates against those invoices. You need to find the due days for those invoices.

=WORKDAY(A2,B2)

Result is :

Initially, the result looks like serial numbers. We need to change our formatting to make it correct.

Step 1: Select the entire range.

Step 2: Now press ctrl +1. It will open up a formatting dialogue box.

Step 4: Your result looks like the below one.

Things to Remember

If you want to use different weekends other than Saturday and Sunday, use chúng tôi function.

We can use only numeric values for the day’s argument.

The date and days should be accurate otherwise;, we will get the error as #VALUE!

If the date includes time, then the formula considers only the date portion and ignores the time portion.

If you supply decimal numbers, a formula will round down the value. For example: if you supply 10.6 days, then the formula treats this as 10 days only.

Recommended Articles

This has been a guide to WORKDAY ID in Excel. Here we discuss the WORKDAY Formula in Excel and how to use the WORKDAY Function in Excel along with practical examples and downloadable excel templates. You can also go through our other suggested articles –

How Do I Input A String From The User In Python?

In Python, there are several ways to input a string from the user. The most common method is by using the built-in function input(). This function allows the user to enter a string, which is then stored as a variable for use in the program.

Example

Here’s an example of how to input a string from the user in Python −

# Define a variable to store the input name = input("Please enter your name: ") # Print the input print("Hello, " + name + "! Good to see you.")

Output

The above code generates the following output for us −

Please enter your name: Max Hello, Max! Good to see you.

In the code above, we have,

Define a variable to store the input − name = input(“Please enter your name: “)

In this step, a variable named “name” is created to store the input from the user.

Prompt the user to enter their name − input(“Please enter your name: “)

The “input()” function is used to display a message to the user, asking them to enter their name. The message, “Please enter your name: “, is passed as an argument to the function.

Store the user’s input in the “name” variable − name = …

The result of the “input()” function call is stored in the “name” variable. This means that the user’s input is now stored in the “name” variable, ready to be used.

Print the input − print(“Hello, ” + name + “! Good to see you.”)

In this step, the “print()” function is used to display a message to the user, using the value stored in the “name” variable. The message, “Hello, [name]! Good to see you.”, is passed as an argument to the function. The value of “name” is concatenated with the rest of the string using the “+” operator.

It’s crucial to remember that the output of the “input()” function will always be a string, even if the user enters a numerical value. If you need to use the input as a number, you’ll need to convert it to the appropriate data type (e.g. int or float).

Example

Here’s an example of how to input a number from the user −

# Define a variable to store the input age = int(input("Please enter your age: ")) # Print the input print("Wow, you are " + str(age) + " years old!")

Output

The above code generates the following output for us −

Please enter your age: 24 Wow, you are 24 years old!

From the above code,

A variable named “age” is created to store the input from the user.

The message, “Please enter your age: “, is passed as an argument to the function.

Since the “input()” function always returns a string, we need to convert the user’s input to an integer using the “int()” function. This allows us to store the user’s input as a number, rather than a string.

The result of the “int()” function call is stored in the “age” variable.

The “print()” function is used to display a message to the user, using the value stored in the “age” variable. The message, “Wow, you are [age] years old!”, is passed as an argument to the function. The value of “age” is first converted to a string using the “str()” function and then concatenated with the rest of the string using the “+” operator.

It’s also possible to assign a default value to the input, in case the user doesn’t provide any input. This can be done using the “or” operator and a default value −

Example # Define a variable to store the input name = input("Please enter your name (or press enter for default): ") or "Max" # Print the input print("Hello, " + name + "! Good to see you.")

Output

The above code generates the following output for us −

Please enter your name (or press enter for default): Hello, Max! Good to see you.

Here in the code above,

A variable named “name” is created to store the name input by the user.

The message, “Please enter your name (or press enter for default) − “, is passed as an argument to the function.

The or operator is used to set a default value for the name variable. If the user presses enter without entering a name, the input() function will return an empty string. If the user’s input is an empty string, the or operator will evaluate to the default value, “Max”.

The result of the input() function call, or the default value “Max” is stored in the name variable.

A personalized greeting is printed, using the name variable. The + operator is used to concatenate the string values, creating a single string to be printed.

Conclusion

To summarize, receiving a string from a user in Python is a simple task that can be accomplished by making use of the readily available “input()” method. Regardless of whether you need to collect a string or a numerical value, it is effortless to convert the input into a suitable data type and save it in a variable for future reference.

The “input()” method is a convenient tool for obtaining information from a user and storing it for later use in your code.

Sum By Color In Excel (Examples)

Sum by Color in Excel

In this article, we will learn about Sum By Color in Excel. In Excel, we have a function for adding numbers. But there is no direct way to add the number by their background color. By this, we don’t need to sum the numbers separating the colored cells. We can directly consider all the cells in the formula and sum them as per their background color.

Start Your Free Excel Course

Excel functions, formula, charts, formatting creating excel dashboard & others

This we can do when we have many cell numbers colored, and filtering the data is not suggested there.

How to Sum by Color in Excel?

Excel Sum by Color is very simple and easy. Let’s understand how to sum by color in Excel with some examples.

You can download this Sum by Color Excel Template here – Sum by Color Excel Template

Sum by Color in Excel – Example #1

Here we have data on some product and their sale. As shown below, column C has numbers with some background color.

Now, as we need to sum the numbers, so from the drop-down of SUBTOTAL Function, select 9, which is for sum.

And for reference1, select the complete range of column C, which we need to total as shown below.

The Output will be as given below.

Now apply the filter in the top row by pressing Ctrl + Shift +L.

Go to Filter by Color from the drop-down menu of it. Select any color; we have selected YELLOW, as shown below.

Once we do that, we will get the Output cell filtered sum as 190, as shown below.

We can also check the correctness of the applied SUBTOTAL formula by filtering the different colors.

Sum by Color in Excel – Example #2

There is another way to sum the numbers by their colors. For this, we will consider the same data as shown in example-1. Now copy the column’s cells with numbers and paste them into a separate sheet or in the same sheet in a different location.

Once we do that, selected cells will convert into the table form. And another menu will add with the name Design in the menu bar. Now Check and tick the Total Row option from the Table Style Options.

Once we do that, we will get the sum of cells at the bottom end of the column with a drop-down menu. Here we are getting a sum of 786.

Now from the drop menu of the total sum, select the Sum option as shown below.

By this, we enable the table to sum the filtered data as per colored cells. Now go to the top filter drop-down of the same column and select any color to get summed up from the Filter by Color option. Select any color; we have selected YELLOW, as shown below.

Once we do that, we will get the YELLOW colored filtered and the sum of the YELLOW colored cells in the below cell.

Sum by Color in Excel – Example #3

There is another method of summing the numbers by their color. VBA Marcos will do this. For this, we will consider the same data we saw in example-1. And we will add separate cells for each product name to get the sum of their quantity sold.

Now press Alt + F11 to enter Visual Basic for the Application screen.

Now go to the Insert menu and select Module.

This will open a new Module to write code. Now in the blank Module, write the code for enabling the sum by color function in Excel, as shown below. You can also use the same code to make some changes in that.

Close the complete window of VBA. Now go to the cell reference of Mobile, where we need to see the result and type the “=” sign. Now search and select the Sum Color function we created in VBA.

And select the reference colored cell and then select the range to get summed, as shown below.

The Result will be as shown below.

Once done, drag the formula to complete respective cells to see the result as shown below.

As we can see in the above screenshot, the sum of yellow-color cells is coming at 190, which the summed value is obtained in example-1 and example-2. This means that all the formulas and functions used in all examples are correct.

Pros

Sum by color from the SUBTOTAL function is the easiest way to get the sum result by color in Excel.

The process steps shown in example-2 take a little longer than in example-1, but it is still easy to apply.

We don’t need to filter the colored cells separately to get the sum.

Cons

Sum by color shown in example-3 by VBA coding takes time, and it doesn’t show the result if we paste the data in another file because it does carry the code with it.

Things to Remember About Sum by Color in Excel

If you are summing colored cells by VBA Coding, it is always recommended to save in the Macro enabled Excel; this will save the coding for future use.

These methods can use anywhere, irrespective of the data size. It is always recommended to use this method when we have a huge set of data, where if we filter the data to get the summed value may crash the file.

Recommended Articles

This has been a guide to Sum by Color in Excel. Here we discuss how to sum by color in Excel, practical examples, and a downloadable Excel template. You may also look at the following articles to learn more –

Update the detailed information about Input Output Redirection In Linux/Unix Examples on the Minhminhbmm.com website. We hope the article's content will meet your needs, and we will regularly update the information to provide you with the fastest and most accurate information. Have a great day!