Friday, December 7, 2018

Basic UNIX Commands With Examples

In this post you will learn Basic UNIX Commands for every software Developer. Unix is a common Operating System. UNIX is used by the workstations and multi-user servers within the school.
On X terminals and the workstations, X Windows provide a graphical interface between the user and
UNIX. However, knowledge of UNIX is required for operations which aren't covered by a graphical
program, or for when there is no X windows system, for example, in a telnet session.

The UNIX operating system is made up of three parts; the kernel, the shell and the programs.

kernel
The kernel of UNIX is the hub of the operating system: it allocates time and memory to programs
and handles the filestore and communications in response to system calls.

shell
The shell acts as an interface between the user and the kernel. When a user logs in, the login
program checks the username and password, and then starts another program called the shell.

The following are the Basic commands:

ls (list) :

When you first login, your current working directory is your home directory. Your home directory has the same name as your user-name, for example, ee91ab, and it is where your personal files and subdirectories are saved.
To find out what is in your home directory, type

% ls (short for list)

The ls command lists the contents of your current working directory.

To list all files in your home directory including those whose names begin
with a dot, type

% ls -a

ls is an example of a command which can take options: -a is an example of an option. The options change the behaviour of the command. There are online manual pages that tell you which options a particular command can take, and how each option modifies the behaviour of the command.

mkdir (make directory):

We will now make a subdirectory in your home directory to hold the files you
will be creating and using in the course of this tutorial. To make a
subdirectory called unixpoint in your current working directory type

% mkdir unixpoint

cd (change directory)

The command cd directory means change the current working directory to 'directory'. The current working directory may be thought of as the directory you are in, i.e. your current position in the file-system tree.

To change to the directory you have just made, type

% cd unixpoint

pwd (print working directory)

Pathnames enable you to work out where you are in relation to the whole file-system. For example, to find out the absolute pathname of your homedirectory,

type cd to get back to your home-directory and then type 

% pwd

cp (copy)

cp file1 file2 is the command which makes a copy of file1 in the current working directory and calls it file2 What we are going to do now, is to take a file stored in an open access area of the file system, and use the cp command to copy it to your unixpoint
directory.

mv (move)

mv file1 file2 moves (or renames) file1 to file2

To move a file from one place to another, use the mv command. This has the effect of moving rather than copying the file, so you end up with only one file rather than two.It can also be used to rename a file, by moving the file to the same directory, but giving it a different name.




rm (remove), rmdir (remove directory)

To delete (remove) a file, use the rm command. As an example, we are going to create a copy of the Tech.txt file then delete it.

Inside your unixpoint directory, type

% cp Tech.txt tempfile.txt
% ls (to check if it has created the file)
% rm tempfile.txt

% ls (to check if it has deleted the file)
You can use the rmdir command to remove a directory (make sure it is empty first). Try to remove the backups directory. You will not be able to since UNIX will not let you remove a non-empty directory.

clear (clear screen)
Before you start the next section, you may like to clear the terminal window of the previous commands so the output of the following commands can be clearly understood.

At the prompt, type
% clear
This will clear all text and leave you with the % prompt at the top of the window.

cat (concatenate)
The command cat can be used to display the contents of a file on the screen. Type:

% cat Tech.txt

tail

The tail command writes the last ten lines of a file to the screen. Clear the screen and type

% tail Tech.txt


grep:

grep is one of many standard UNIX utilities. It searches files for specified words or patterns.

chmod:

chmod is the command and system call which may change the access permissions to file system objects (files and directories).

cal:

It is used to display the calendar.

Date:

It is used to display the date.

Who:

This command is used to display the list of users currently logged in.











No comments:

Post a Comment

High Paying Jobs after Learning Python

Everyone knows Python is one of the most demand Programming Language. It is a computer programming language to build web applications and sc...