ls
, cd
, pwd
, mkdir
, cp
, mv
, rm
, touch
, and man
, cat
, find
, grep
, wget
, unzip
, echo
, and input/output modificators: |
, >
, »
.1. Integer sum function
Compile with gcc filename.c -o outputFilename
#include <stdio.h> int sum(int a,int b) { return (a + b); } int main() { int myAge = 29; int a =10; int b =20; int result = sum(a,b); printf("My name is George, and I am %i years old.\n", myAge); printf("My sum is%i \n", result); return 0; }
2. Float sum function
Compile with gcc filename.c -o outputFilename
#include <stdio.h> float sum(float a,float b) { return (a + b); } int main() { int myAge = 29; float a =10.1; float b =20; float result = sum(a,b); printf("My name is George, and I am %i years old.\n", myAge); printf("My sum is%.3f \n", result); return 0; }
3. Square root function Important! Compile with gcc filename.c -o myoutput -lm
#include <stdio.h> #include <math.h> float getRoot(float a) { //this function calculates the square root, and returns it float result = sqrt(a); return a; } int main() { float myAge = 29; float rootAge = sqrt(myAge); printf("My name is George, and I am %f years old.\n", myAge); printf("The square root of that is %.3f \n", rootAge); return 0; }
Implement a function that calculates the euclidean distance of two numbers. That is, it takes two numbers, squares each of them, adds them, and returns the square root.
Open terminal Ctrl + Alt + T New tab Ctrl + Shift + T End programs by running Ctrl+C Close by Ctrl + D
Manual to (almost) every terminal program can be found using man
:
$ man <program>
You shoud start working in linux terminal by asking, how to use manual
$ man man
To find out, where are you in the directory tree, the present working directory, use pwd
:
$ pwd
To list files in your directory, use ls
:
$ ls
There is also possibility to see a content of different directory
$ ls <relative/absolute address>
The useful parameters you should know are:
-a
do not ignore entries starting with ., usualy hidden files,
-A
the same as -a
but it does not list implied . and ..,
-l
uses a long listing format,
-p
to append / at the end of the name of directories to differentiate them from files,
-S
size, -t
time, etc.,
$ ls -Al
To change the directory use cd
:
$ cd <relative/absolute address>
Go to the parent directory
$ cd ..
Go to the parent's parent directory
$ cd ../../
Go to the parent's parent directory and then to its child directory
$ cd ../../some_directory/
Go to the child's child directory
$ some_directory/some_subdirectory/
You can use absolute address:
$ /home/my_account/my_files/my_video/
There is also trivial way to your home directory:
$ cd
The manual is not presented, therefore use parameter –help
to find out more
$ cd --help
For fast navigation, use keypad Tab. Use it frequently.
If you want to create a directory, use mkdir
:
$ mkdir <directory name>
and touch
for file creation:
$ touch <file name>
Please, do not use spaces in your names:
$ mkdir "I have come here from some advertising environment called Windows" $ mkdir and\ I\ really\ like\ to\ troll
and if necessary, use _
underscore instead:
$ touch I_love_linux
Use mv
for moving files or directories from one position in a directory tree to another:
$ mv <source> <destination> $ mv random_file.txt ~/random_directory/ $ mv random_directory/ ~/some_directory/some_subdirectory/
Note that character ~
stands for your home directory.
Use mv
also for renaming the files:
$ mv obsolete_name much_better_name
Copying files can be done using cp
:
$ cp <source> <destination> $ cp random_file.txt ~/random_directory/ $ cp random_file.txt ~/random_directory/better_name.txt
To copy whole directory, use -r
recursive option:
$ cp -r random_directory/ ~/other_directory/some_subdirectory/
You can delete file using rm
$ rm <file name>
Beware! It is very hard to undo!
Deleting whole directory and its content needs -r
recursive option:
$ rm -r obsolete_directory/
It is also possible to delete file (or directory) at different position in directory tree:
$ rm ~/random_directory/random_file.txt $ rm ../../some_system_directory/some_essential_file