How to delete the files in UNIX/LINUX

How do i  remove the files?

In this topic I will show you how to remove the files by using the “rm” command  and also by using the options  & without options..

The “rm” command removes  a file with out asking confirmation from the user end(On Linux ,alias has been created with the rm command(-i option interactive) to ask the confirmation every time if you try to remove a file from a directory).

Be sure you really want to delete your files before you user “rm” command,because once the files are gone ,they are not coming back

Note:If you want to be prompted before  the deletion use the -i option

There is one little safety features in “rm” command it wont delete a directory(unless you use  -f option).

-f  means forcefully.

Let me show you how to delete the files with option and without option.

Ex:1 To remove a file from a directory

syntax:

#rm  <option>    <filename>

or

#rm   <filename>

Task: Remove a file form the /var  directory

First let me create a file inside the /  directory

#touch   /testfile

#ls -l  /testfile

#rm  /testfile

Note: Once you hit the enter button it will ask for the confirmation from the user end ,Once you give the permission “yes” to delete The file will get removed  from the directory.

I will show you with one example here:

 

 

Ex :2 Now i am going to apply the option -f with the “rm” command .

#touch   /anotherfile

#rm  -f  /anotherfile

Note: Here it will not ask the confirmation from the user as you have applied the force option -f which eliminates the interactive option.

Here you go….

 

Ex:3 Now applying the verbose option(-v) with the “rm” command

Verbose is nothing but the program provides the comments on the operation as they occur,so you will see the real time status of what the utility or program is doing to run the tasks or commands.

#touch  /myfile

#rm  -v  /myfile

I will show you this  with an simple example…

..

Note: From the above output if you see it is asking for the confirmation from the user before it gets delete from the directory,Because i haven’t applied the -f options ,if i would have applied then it will not ask the confirmation.

The order of options doesn’t a matter you can use it as you wish.

Ex:4 Applying -f and -v option with the “rm” command

#rm  -vf  /datafile

Here  as i said above it will not ask the confirmation from the user end before it gets delete(coz of -f option) and also it will print a message on your screen regarding this task(coz of -v option).

 

If you found this article useful, Kindly Subscribe here Click this link to Subscribe

http://www.linuxvasanth.com/create-empty-file-linux/

 

 

 

How to Create an empty file in Linux?

Methods to create a file in UNIX/LINUX:

Linux/UNIX considers everything as  a file. Whenever you start working on Linux/UNIX box you have to deal with different file-types. 

There are three popular methods available to create a empty file.

Method:1

By using the “touch” command  we can create a empty file ..

Note: The syntax to run the UNIX commands is

<command>    <options>   <arguments>

options: It modify the way in which a command works.

Arguments: It could be a file or directory name as you wish

Note: You must type space between command,options and file or directory name else you will get syntax error message on your screen after execution of the command.

 syntax to create a file is:

#<command>  <filename or filepath>

Task: Create a file inside the parent / directory

#touch   /myfile

The file has been created successfully  inside the path /…

To get the details of this file you have to use the command “ls” with -l option.

Note: The syntax to run the UNIX commands is

<command>    <options>   <arguments>

options: It modify the way in which a command works.

Arguments: It could be a file or directory name as you wish

Note: You must type space between command,options and file or directory name else you will get syntax error message on your screen after execution of the command.

#ls   -l  /myfile

or

#ls   /myfile

With option or without option you can call the ls program to list view the file/dir properties,but it will give you the full details of a file or dir once you add -l option with the “ls” command .

-l option will give you the information’s like:

1.Type of the file

2.Default permission for the file/directory

3.The link count for the file/directory.

4.Owner of the file/directory

5.Group ownership for a file/drectory

6.Size of the file or directory

7.Date and time creation of the file/directory

With out -l option it would display only the file or directory name you mention with the “ls” command.So i recommend you to use -l option always with the “ls” command to fetch the details.

Let me show this with an practical example

In the above example if you can see with out the -l option it displayed only the file name but with the -l option the “ls” command fetches all the details of the file.

Method:2

By using the command called “cat” we can also create an empty file.This command  allows you to add the content to the file while you create

Let me show you the example

The same syntax  once again we are going to use here…

#cat   >   <filename or filename path>

Task: Create a file inside the /  directory

To create a file here we use the notation > with the “cat” command…

#cat  >   <filename or filename path>

#cat  >  /testfile

Here once you hit the enter button the cat program waits for the input to be sent to the file(testfile) after typing the content you can save the content to the file by  pressing control+d from your keyboard.

Note: Before insert the content press control+d to save the file .

 

 

 

 

METHOD :3

Another method to create the file is by using the editor called “vi”(called as visual editor)

In the above first two methods we have seen how to create the files and how to add the content to the empty file,Now what would happen if i use method 1 and method 2 to edit the file? is it possible to edit the file content  with touch and cat command,the answer is NO ..It will not allow you to edit the file content ,”cat” command allows only you to append the content or overwrite the file content .

If you need to edit the file content  i prefer to use the editor called “VI”.The editor is installed in every UNIX system by default.

Note: An improved version of vi editor is vim,but most Linux system have vi editor installed.

I will  explain you in detail about the vi editor in our upcoming topics.

So to create a file by using the vi editor

#vi  <filename or filename path>

#vi   /samplefile

 

IMPORTANT:

Touch command features:

Your manager requested you to modify the date and time of some important files in your directory  as a administrator  what you would do?

Is it possible for you to modify the date and time of the existing file without disturbing the file content?

YES you can do it …

touch program has some special features

1.which is used to update the access date and modification date of the file.

2.Touch avoids opening,saving and closing the files instead it simply updates the date associated with the file

Note: Mostly administrators use the touch command to modify the access information of the files.

Let me show you with some practical example..here we go…….

1.Check the date and time of your server first:

#date

2.Create a file and add some content

#cat  > /test

3.Check the properties of the file 

#ls  -l  /test

4.After 60 second (as you wish you can mention the time) create a file with the same name once again by using touch command

#date

#touch  /test

5.Now check the properties of the file

#ls  -l  /test

From the output you will find the date and time modified to the latest one with out changing the content of the file

6.To  read the content of the file

#cat     /test

Note that the content of the file still remains the same with out it gets overwrite with empty one.

 

HOW TO APPEND THE CONTENT TO THE EXISTING FILE:

Now let me show you how to add the content to the file and how to append the content to the existing file without overwrite.

Its very easy to add and append the content to the file

To add the content to the empty file 

#cat   >/samplefile

Don’t forgot to save the file content by pressing control+d

To confirm whether the content has been added run the following command:

#cat  /samplefile

(Here it will display the content which you have entered)

Now the file samplefile is having some content …..my task is to add some more content to this file without overwrite with the new content.I should read both the previous as well the new content  after saving the file.

1.Run the command to read the content

#cat    /samplefile

2.Append some more content to this file without overwrite

#cat   >>/samplefile

(After adding the content press control+d to save)

Note:To append the content to the existing file we have to use the notation >>

3.Run the command once again to  read the content

#cat  /samplefile

(The output it will show both the old content as well the new content )

The point to remember is use >> notation  to add the content to the  existing file (which is having some content already inside the file)

 

Let me show this with some real time example:

Note: Remember here if you use > notation instead of the >> the file content gets overwrite with the new content

If you found this article useful, Kindly Subscribe here👉🏿👉🏿 Click this link to Subscribe

 

What is meant by shell in Unix

 

What is meant by shell in Unix

Unix Shell


1.Shell is the gateway to interacting with the operating system.
2.It takes the input’s from the keyboard and send to the kernel program and then displays the output on the screen.
There are lots of shells available in UNIX flavors

Types of Shell


In addition to the graphical user interface like Gnome, KDE, The Linux operating system also offers several shells.These command line interfaces provide a powerful environment for software development and system maintenance. Though shells have many commands in common, each type has some unique features.
There are two major shells available in Linux
1)Bourne shell (sh)
2)C-Shell (csh)

Bourne-shell(sh)- The Bourne shell called “sh” is one of the original shells, Developed for Unix systems by Stephen Bourne at AT&T’s Bell Labs in 1977.It offers features such as input and output redirections, Shell scripting with string and integer variables and conditional testing and looping.

The sub-categories of Bourne shell:

a)Bourne again shell (Bash)
b)Korn shell (Ksh)
Bourne Again Shell (Bash)-The popularity of sh motivated the programmers to develop a shell that is compatible with it, but with several enhancements, Linux system still offers the sh shell, but bash –based on sh –become the new standard shell.One attractive feature of bash is its ability to run the sh shell scripts unchanged.Shell scripts are complex set of commands that automate programming and maintenance chores..being able to reuse these scripts saves programmers time Convenience not present with the original Bourne shell include command completion and command history.
Note: The most preferable shell in flavors of UNIX is BASH.Linux uses BASH as its default login shell.
Korn shell(Ksh)-Korn shell is more compatible with the sh and bash.Ksh improves on the Bourne shell by adding floating point arithmetic, job control, command aliasing and command completion.
Note: AT&T held proprietary rights to Ksh until 2000 when it becomes opensource.
C-Shell(Csh) and tcsh-Using C-syntax as a model Bill joy at Berkeley university developed the C-SHELL csh, in 1978
Ken Greer working at Carnegie-Mellon University took Csh concepts a step forward with the new shell,tcsh which Linux systems now offer. Tcsh fixed a problem in csh and added command completion, in which the shell makes educated “guesses” as you type, based on your system directory structure and files.

Note: Tcsh doesn’t run the Bash scripts as the two have substantial differences.

What is a TERMINAL?


Its a program called terminal emulator.This program is responsible for opens the window and lets you to interact with the shell.
There are a bunch of different terminal emulators you can use.Most Linux distributions supply several such as,gnome-terminal,xterm, Konsole,nxterm and eterm.

Starting a TERMINAL:

Your windows manager probably has a way to launch a terminal from the menu.If you are a KDE user, then your terminal program is “Konsole”, in gnome it’s called gnome-terminal, you can start up as many of these as you want and play with them, while there are a number of different terminal emulators, they all do the same thing.They give you access to shell session.
Terminal=tty=text input and output environment(tty is a particular type of device file which implements a no of additional commands beyond  read and write.)
Note: Some ttys are provided by the kernel on behalf of a hardware device, for example with the input coming from the keyboard and the output going to text-mode screen or you can say like with the input and output transmitted over a serial line.You can open multiple terminals at a time and check the terminal number by using the command called tty , here I show you the example how it looks

Console=Physical Terminal(Every UNIX system has a main console that is connected directly to the machine.A console is a special type of terminal that is recognized when the system is started.console is only accessible by the system operator or system administrator.)

If you found this article useful, Kindly Subscribe here👉🏿👉🏿 Click this link to Subscribe

http://www.linuxvasanth.com/basic-unix-directory-structure/

How Unix flavours are more secured from Virus?

 How Unix flavours  are secured from Virus?We all know about the computer virus how it enters and destroys the real source code.

 

  • A computer virus is a malware program or piece of code that is loaded on to your computer without your knowledge and runs against your wishes.

Note: Computer virus is man-made.

UNIX/LINUX:

  • Destroying or infecting one server means collapse of thousands of computers

Linux is architecturally strong and hence very much immune(not totally) to security threads.

For example now suppose a malicious script is written for an rpm based  system i.e, Red-hat,Fedora,Centos,it cant infect a Debian based system and a destructive script written for Debian based OS cant infect an rpm based system (RPM means red hat package manager, Its a  package management utility for red-hat management systems).

More a script that is going to perform a system-wide change needs “root password”.

If the root password is confidential and strong enough the OS is literally secure, Now a windows virus cant contaminate a Linux until wine is installed and run as root, hence it is suggested not to run wine as root.(Wine is open source for Linux that enables users to run any windows based app on Linux)

You cant set a Linux without setting up a root password and user password.It means every user in a Linux must have a password except “Guest” whereas windows allow you to set user and even root account without a password.

Linux is so much secure in architecture that you even don’t need to go behind a firewall until you are on the network.

If you found this article useful, Kindly Subscribe here👉🏿👉🏿Click this link to Subscribe

 

Types of Operating System

Before Getting in to the Unix operating system we should know the types of operating systems available

I would like to explain this in a simple way,I don’t want you guys to get confused by explaining this in very core as it is not required for this know.

There are three different types of operating systems available

1)Single user and Single Task operating system

2)Single user and Multitask operating

3)Multi-user and Multitask operating system

Let us see this types in a detailed way

Single user and Single Task: Single user means the OS which allows only one user to login in to the system and the single task is nothing but that logged in user can perform only one task at a time.

Example we can say ms-dos operating system(It supports only CLI-Command Line interface)

Single user and Multi-task: Single user the same as above I have explained

Let us see what is that multi-task stuff

The logged in user can perform multiple tasks at a time, an example we can say the updated version of Ms-dos win95,XP,7 and many more(we have GUI access in this).A simple example for this, A logged in user running a music player and if he wants to see some video article he could do that without killing the previous task i.e music player.

Multi-user and Multi-task: Multi-user in the sense the operating system which allows a user to switch in to multiple user accounts without log out from your previous logged in account this is called as Multi-user.Now coming to the multi-task it does the same as multi-user (i have explained above already).
So for the multi-user and multi-task, i would say Unix and its flavors as an example.

If you found this article, useful,Please share it…Thank you!

Subscribe here👉🏿👉🏿 Click this link to Subscribe