C PROGRAMMING

Linux Bash Commands For C

Article by:
Date Published:
Last Modified:
Screenshot of essential bash commands for C being used in a terminal on Ubuntu.
Screenshot of essential bash commands for C being used in a terminal on Ubuntu.

Below are a list of the most essential bash commands when working with the c programming language in linux.

Examples tested on Ubuntu v12.04.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# Install GNU C compiler and other essential C programs onto Linux platform
sudo apt-get install build-essential

## Creates c file called main.c in current directory and opens gedit to begin editing it
# (and frees terminal)
gedit main.c &

## Compiles C program main.c with standard flags and creates executable called main
gcc -Wall -W -Werror main.c -o main

## Run a compiled executable called main in the current directory
# Note that './' is mandatory, otherwise bash will think you have typed a command
./main

## Change file permissions on executable called main so that it will run (if experiencing 'Permission denied' errors)
chmod +x main

## Compiles C program main.c and creates executable called main with debugging symbols
gcc -Wall -W -Werror main.c -o main -g

## Starts debugging session on compile program called main.
# Make sure -g flag was used when compiling
gdb main

# GDB commands (omit the (gdb) prefix, this will be present in the terminal already)
(gdb) break 16   # Set breakpoint at line 16 (when running gdb)
(gdb) run        # Run program (when in gdb)
(gdb) n          # Move to next line
(gdb) c          # Continue to next breakpoint
(gdb) s          # Step to next line (unlike n, will jump into functions)
(gdb) print x    # Print the variable x

Authors

Geoffrey Hunter

Dude making stuff.

Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License .

Tags

    comments powered by Disqus