Simple commands of linux

In the previous post, I discussed few commands to create a file and how to execute any particular file.

In this post we will continue with the same but we will also learn some advanced and easy ways to do programming.

You can compile a file using “gcc” command also. For example gcc file.c

Or you can do that using cc file.c

After compiling file, compiler will generate one executable file and that we call as “a.out”.

To generate output simply type ./a.out in terminal.

Few commands :

cd          –  Change directory to home.

cd ..       –  Go back to previous working directory.

ls -l        – It will show you a long list of files present in the current working directory.

There are two ways of changing directory:

Absolute path     –   cd /home/folder/folder1

Reference path  –   cd ../../folder1

The default compiler will generate a.out executable file. But you can generate the executable file as you want, like b.out, name.out etc.

How?

cc file.c -o file         – Here I am generating an executable file with ./file name.

rm file_name.c        – To remove particular file.

rm dir                       – To remove particular directory.

vi file_name.c          – To create a new file with name file_name and extension .c because we are writing code in c language.

In vi – editor three modes are there:

  1. Insert mode
  2. Command mode
  3. Execute mode

After creating a file using above command it will open a new window. That’s called vi editors and to type program, you need to first press i letter and you can do any changes in the program. Once you are done with your program you need to save that program and need to exit that editor for executing that program.

So, press ctrl + (shift +zz) – For save and exit.

You can do the same using ctrl + shift  +  :wq and pressing enter. It will save and you’ll exit.

If you don’t want to save and you just want to exit then press ctrl + shift + :q and press enter.

ctrl + shift + :setnu  –  It will display line number in vi editor.

How to copy and paste in ‘vi editor’ ?

For any line you want to copy, press yy for that single line.

If you want to copy 2 lines then press 2yy.

And for paste  – press p

How to delete line?

To delete particular line press ctrl+DD .

cp  sourcefilepath   destinationfilepath- Copy particular file to another destination.

Example : cp  /home/file/folder   /pi/java/c

mv– To move a particular file.

Example : mv file.c file1.c

 

 

 

 

 

 

 

 

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Powered by WordPress.com.

Up ↑

%d bloggers like this: