Course : C Programming
Faculty : Harshit Garg
LIST OF LINUX COMMANDS
S.No. Command Name
Syntax
Example and Explanation
Print Working Directory pwd
(pwd)
pwd #lists the path of the current directory
or folder
List (ls) to display the
contents
ls # display the contents of current folder
ls /home/student/Desktop # display the
contents of Desktop folder
Make Directory (mkdir) mkdir foldername
mkdir songs # creeaates a folder or
directory with songs as name
Change Directory (cd) Cd (space)
to switch to a directory path_to _
foldername # you
move from one
folder to another
cd songs # you move from current folder to
songs folder
Gedit (opens the editor
for wrting)
gedit filename
gedit hello.c # creates a file called hello.c in
current folder
# it is equal to the double click on file
hello.c
Copy (cp) -
cp sourcefile
destination_folder
cp hello.c /home/student/Desktop # copies
the file hello.c to Desktop
Move (mv) to change mv sourcefile
the location from one
destination_folder
place to another
mv hello.c /home/student/Desktop # moves
the file hello.c to Desktop i.e. Deletes the
file from current folder to Desktop
History to display a
history
list of commands alreay
executed
history # displays a list of commands alreay
executed
Note : Use arrow keys on the terminal to
move up/down in the list
Contatenate (cat) to
cat filename
display the contents of a
file
cat hello.c # displays the name of the file
hello.c in terminal window
10
Gcc (GNU C Compiler gcc sourcefile
or GNU Compiler
Collection)
compiles the source
code to executable code
gcc hello.c # compiles the source file
hello.c
11
Man (Manual)
ls
or
ls path_to_folder
Man commandname man gcc # opens the manual of gcc
command
man ls # opens the manual of ls command
To test if a command works or not, just type that command. If command not found message
comes, then the command does not exist. Also, you can type the following
man commandname,
Eg. man gcc , to see if the command is installed. If it is, then its manual will open.
Steps to programming in C
1. Writing the code (using gedit command)
2. Compiling the code (using gcc command)
3. Executing the code ((using ./a.out ))
Writing the code
1.
2.
3.
4.
open the terminal
type gedit hello.c or type gedit hello.c &
type the source code
save the work
NOTE : Be sure of the location (folder) where you are saving your work
Compiling the code
1.
2.
3.
4.
type gcc hello.c
if there is an error, some message comes
otherwise, no message comes
by default, ./a.out file is created. To create an executable file of any other name, type gcc
hello.c -o hello or gcc -o hello hello.c. This creates an executable file hello instead of
a.out
NOTE : There are two types of errors. One are WARNINGS. Warnigns are just informative
messages, and can be ignored. Other is ERROR. Errors are mistakes in the C program, that need
to be removed before the program can be executed. So edit the program. The line number is
mentioned in the error message. Go to the line number and look for the error.
Executing the code
1. type ./a.out
2. the output is displayed on the screen
NOTE : If you have compiled using step 4 in compiling, then you should type ./filename, like
./hello in the example case.