COMMAND
|
DESCRIPTION
|
SYNTAX
|
who
|
show who
is logged on
|
who
|
su
|
change
user ID
|
su
<loginname>
|
passwd
|
to
change your password
|
passwd
|
man
|
displays
details of a command
|
man <command_name>
|
ls
|
list
directory contents
|
ls
|
mkdir
|
make
directories
|
mkdir
<foldrname>
|
cd
|
changes
directories
|
cd
|
cp
|
copy
files and directories
|
cp a.txt
copy.txt
|
mv
|
move files
|
cp a.txt
<directory>
|
rm
|
remove
files or directories
|
rm
file1.txt
|
find
|
search
for files in a directory
|
find
file1.txt
|
pwd
|
print
name of current working directory
|
pwd
|
history
|
prints
recently used commands
|
history
|
mount
|
mount a
file system or drive
|
mount
/media/target
|
umount
|
unmount
file systems or drive
|
unmount
/media/target
|
poweroff
|
shut
down the system
|
poweroff
|
reboot
|
restart
the system
|
reboot
|
vim
|
A
programmer’s text editor
|
vi
hello.c
|
gedit
|
A text
Editor
|
gedit
hello.c
|
cal
<month> <year>
|
display
calendar
|
cal april
2012
|
date
|
displays
the current date
|
date
|
echo
|
Print
message on the terminal
|
echo
"Welcome to the workshop"
|
printf
|
Print the formatted message on the terminal |
printf
"the amount is %d\n" 100
|
bc
|
A text
based calculator
|
bc
|
xcalc
|
A
graphical based calculator
|
xcalc
|
gcc
|
To
compile C program file
|
gcc
file1.c
|
g++
|
To
compile C++ program file
|
g++
file1.c
|
ctrl+d
|
Quit
command process
|
ONE DECLARATION :- This blog is about C-programming in Linux using Terminal. As we know, many students are studying and using Linux. But they get many syntax errors and functions, header file errors. Therefore I am writing this blog to give idea about removing those syntax errors. All details in this blog is according to my best knowledge. If you have any doubt or problems, then please inform me by mail or comments.
Friday, September 7, 2012
Some Linux Commands !!!
FIRST PROGRAM –“HELLO”
In this blog we are discussing about the first LINUX program – printing
‘HELLO’ on screen – using GCC. Programming in Linux is same as programming in
Windows TC. For this, start your Linux, open user’s “Home Folder”. Home folder
is accessed from ‘Places’ menu from Left corner of Upper Taskbar or from left
sidebar on Desktop. Home folder name can be your login name. Then right click
on empty space, you will get property menus- Create Folder, Create Documents,
Arrange items, etc… Select ‘Create Documents à Empty file’ menu. It will create an empty file
with name ‘new file’; rename it with ‘hello.c’ (small letters compulsory). Then
you can write your C code in it. Let C code is –
#include<stdio.h>
int main()
{
printf(“\n\n HELLO
\n\n”);
return 0;
}
Now,
In TC (Windows), we are including “conio.h”
header file in C code. Also we are using clrscr(), getch() functions. But in
Linux, we are not using it. It has a reason. Because “conio.h” header file is
not an ANSCII approved header file. Linux GCC has only ANSCII approved header
files and include only them.
If you try to include them in C code, then Terminal (GCC) will give
error that ‘conio.h file can’t be included’.
Now, close the “hello.c” file. Open Linux Terminal, it is in
“Application” menu in left corner of upper taskbar or from left sidebar.
Navigate terminal to “hello.c” file directory (if necessary, using cd command).
Then type one of the following commands.
1)
gcc hello.c
If
C-code is syntactically correct, then on Terminal there will not be any error
message and you will get “a.out” executable file in same directory otherwise
prints errors of C-code with line no. on Terminal.
2)
gcc hello.c –o hello.ext
It
is same is first command but it creates “hello.ext” executable file except
“a.out” in same directory. You can give any filename and extension in command.
3)
gcc hello.c –Wall –Werror –o
hello.ext
It
is same is first command but if C-code contain any warnings then these will be
printed on Terminal as errors and if C-code is syntactically correct then it
creates “hello.ext” executable file in same directory.
Now,
you got “a.out” or “hello.ext” executable file on directory. For running it on
Terminal, you have to give a command like-
./a.out OR
./hello.ext
a.out
or hello.ext file gets executed and you will get result on Terminal screen.
PICTORIAL PROCEDURE IS AS FOLLOWS =
Subscribe to:
Posts (Atom)




