Startertutorials Blog
Tutorials and articles related to programming, computer science, technology and others.
Subscribe to Startertutorials.com's YouTube channel for different tutorial and lecture videos.

Categories: Unix Programming. 1 Comment on Basic Unix Commands

In this article you will learn some of the basic Unix commands along with examples. We will look at description of each basic Unix command followed by an example in XUbuntu operating system. After learning about basic Unix commands we will learn about command substitution and giving multiple commands in Unix.

 

Unix Basic Commands

Unix provides several commands for the users. Most of them are simple and are powerful. Some general basic Unix commands from the user’s point of view are given below:

 

echo Command

The echo command is used to display messages. It is one of the basic Unix commands which is used frequently. It can be used in shell programs to display output and other messages. An example of using echo command is given below:

 

Basic Unix commands echo

 

tput Command

The tput command can be used to control the movement of the cursor on the screen as well as to add certain features like blinking, boldface, and underlining to the displayed messages on the screen.

 

tput command along with cup argument and two more values can be used to position the cursor at a certain location on the screen. tput lines gives the number of rows in the window and tput cols gives the number of columns in the window.

 

For example, tput cup 5 10 command place cursor on 5th row, 10th column as shown below:

 

Unix command tput

 

tty Command

In Unix, every terminal is associated with a special file, called the device file. All the device files will be present in the /dev directory. A user can know the name of his/her device file using the tty command as shown below:

 

Unix command tty

 

who Command

The who command is generally used by the system administrators for monitoring the terminals (users) connected to a system running Unix. It is one of the basic Unix commands which is used frequently. The default who command produced a three column output.

 

First column shows the name of the users, the second column shows the device name and the third column show the login time. Example usage of who command is given below:

 

Unix command who

 

uname Command

Using the uname command one can know the details of one’s Unix system. We can know various details like release information, version information, machine architecture information, and other details using options like r, v, m, and a. Example usage of uname command is given below:

 

Unix command uname

 

date Command

Using date command, we can get the current date and time. This is one of the very few commands that allows the use of format specifiers as arguments. By using the format specifier m, we can display only the month in numeric form.

 

We can display the name of the month using h format specifier. We can also combine multiple format specifier using double quotes. Different examples of using the date command is given below:

 

Unix command date

 

cal Command

This command can be used to view the calendar of a specified year. When no arguments are specified, it displays the calendar of the current month of current year. To view only the calendar of a certain month, we have to specify the month number followed by the year as arguments. Example usage of cal command is given below:

 

Unix cal command

 

passwd Command

The users of a Unix system can change their password using the passwd command. When the command is executed, it will first ask for old password followed by new password two times.

 

After the successfully entering the new password for two times, the prompt will be displayed again denoting that the password changed successfully. Example usage of passwd command is given below:

 

Unix command passwd

 

lock Command

The session over a terminal can be locked for a maximum of 60 minutes using the lock command. By default this command locks the terminal for 30 minutes.

 

When this command is issued, user is asked to enter a password two times. This password can be any random password. When unlocking the terminal again, we have to provide this password again.

 

Example usage of vlock command is given below:

 

Unix command lock

 

cat Command

This command is quite frequently used to create small files. It is one of the basic Unix commands which is used frequently. To create a file, we write cat followed by > symbol, followed by, the name of file. After giving the command and pressing enter key, we can write lines of text and to end, we have to press CTRL-d.

 

To view the content in the file we can write cat followed by the file name. Example usage of cat command is given below:

 

Unix command cat

 

bc Command

The bc command is both a calculator and a small language for writing numerical programs. Using this command, we can perform all arithmetic operations as well as change numbers from one base to another.

 

After giving the bc command, we can call functions or write single line code. To exit from this command, we have to write quit. For converting from one base to another, we use ibase and obase. Here ibase means input base and obase means output base. Example usage of bc command is given below:

 

Unix Command bc

 

spell and ispell Commands

The spell command can be used to check for spelling mistakes in a given document. By default it checks for mistakes based on American usage. We can change that to British by using the -b option.

 

The misspelled words are displayed in alphabetical order. We can’t edit the mistakes directly using this command. Example usage of spell command is given below:

 

Unix command spell

 

The ispell command highlights the mistakes and shows suggestions for removing the misspelled word.  maximum of 10 alternatives will be displayed out of which we can choose one to replace the misspelled word.

 

If we don’t like the suggestions, we can give our own word. Example usage of ispell command is given below:

 

Unix command ispell

 

Command Substitution

It is possible to execute a command as a part of another command. For example we can use the date command within the echo command to simply display the current date along with some text.

 

The inner command should be surrounded within backquotes. In Korn shell, the inner command should be written in parentheses preceded by $ symbol.

 

For example, to specify date as inner command, we will write $(date). Below example demonstrates command substitution in bash shell:

 

Unix command substitution

 

Giving Multiple Commands

We can execute multiple commands by writing a single line. This is like joining multiple commands together. Individual commands are separated by the ; (semicolon) character.

 

The commands are executed one after another from left to right. Executing multiple commands by writing a single line is demonstrated as follows:

 

giving multiple commands in unix

 

For more information on Unix commands visit Unixtutorial.org.

How useful was this post?

Click on a star to rate it!

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Suryateja Pericherla

Suryateja Pericherla, at present is a Research Scholar (full-time Ph.D.) in the Dept. of Computer Science & Systems Engineering at Andhra University, Visakhapatnam. Previously worked as an Associate Professor in the Dept. of CSE at Vishnu Institute of Technology, India.

He has 11+ years of teaching experience and is an individual researcher whose research interests are Cloud Computing, Internet of Things, Computer Security, Network Security and Blockchain.

He is a member of professional societies like IEEE, ACM, CSI and ISCA. He published several research papers which are indexed by SCIE, WoS, Scopus, Springer and others.

1 Comment

You can follow any responses to this entry through the RSS 2.0 feed.

Nice Information

Leave a Reply

Your email address will not be published. Required fields are marked *