Wednesday, September 18, 2019

gcc and what to do

What happens when you run gcc main.c?

What is gcc?

First to start thing we need to know what gcc is. The GNU Compiler Collection (GCC) is a compiler system produced by the GNU Project supporting various programming languages. GCC is a key component of the GNU toolchain and the standard compiler for most projects related to GNU and Linux, including the Linux kernel.

The Free Software Foundation (FSF) distributes GCC under the GNU General Public License (GNU GPL). GCC has played an important role in the growth of free software, as both a tool and an example.

For more information about gcc visit: https://en.m.wikipedia.org/wiki/GNU_Compiler_Collection

What is the C programming language?

C is a general-purpose, procedural computer programming language supporting structured programming, lexical variable scope, and recursion, while a static type system prevents unintended operations. 

By design, C provides constructs that map efficiently to typical machine instructions and has found lasting use in applications previously coded in assembly language. Such applications include operating systems and various application software for computers, from supercomputers to embedded systems.

For more information about C visit: https://en.wikipedia.org/wiki/C_(programming_language)

Steps on how to use gcc

  • First step is to open your Terminal/Command prompt.
  • create a file using the C programming language, the file must have the format .c at the end of its name.
  • now this c file will have a program that will print: Hello, World! but for that to happen we need to compile said file in order to present the output. We use the command gcc in order to compile the main.c file.
  •  What gcc will do is to make the main.c file executable so it will print the text Hello, World!
  • Now that we have compiled our file we can now execute it using this command: ./a-out .
Now that we have executed our main.c file we have printed the words Hello, World! The gcc command will compile files on C programming language and will make those executable to run in your Terminal/ Command prompt.


Monday, September 16, 2019

Symbolic and Hard Links

Symbolic and Hard links on Linux

What is a hard link?
A hard link is merely an additional name for existing file on Linux and other Unix-like operating systems. Any number of hard links, and thus any number of names can be created for any file. Hard links may also be created for other hard links but they cannot be created for directories and also cannot cross filesystem boundaries.

What is a symbolic link?
A symbolic link is a file that links to another file or directory using its path. In Linux and Unix symbolic links are created with the 'ln' command, and in the Windows command line, symbolic links are created using the 'mklink' command. 

Now what is the difference?
  • Symbolic links , unlike hard links, can link to any file or directory on any computer.
  • In a hardlink you can use any of the hardlink names created to execute a program or script in the same manner as the original name given.
  • A hard link preserves the contents of the file.
  • A soft link does not contain the data in the target file.
Here we use the 'ln' command to make a hard link to the file called file1.
Now we use the command 'ls -i' to view the link.
If you look at the file1 and the hlink1 you can view the inode on the left side is the same. As you can see,  hardlinks act as a shortcut to that file that is hard linked.

Now lets look at Symbolic links.
Using the command 'ln -s' will create a symbolic link between files.
Now we use the 'ls -i' to view the link. 

Notice that only the hardlink file has the same inode as the hardlink while the soft link file has different inodes.

Beginners guide to ls on linux

This is a simple guide to use the Linux command 'ls' with the option '*.c'.


  • objective: Learn how to use the ls *.c command

First let's talk about what does the 'ls' command do. The 'ls' command will list all files in your current working directory like this: 


The * acts as a wildcard that in this case will be used to filter what type of file we want to display. The option for the 'ls' command '*.c' will act as a filter that will only display files that end with the format  ".c". for example:

As you can now see, all the files that end with the format '.txt' were not displayed and all files that end with the format '.c' have been listed.