Presentation is loading. Please wait.

Presentation is loading. Please wait.

Command line.

Similar presentations


Presentation on theme: "Command line."— Presentation transcript:

1 Command line

2 Folder structure Only a partial list of the default folders are shown
2018 Risto Heinsar

3 Terminal GUI is nice to have CLI is a must It’s intuitive (sometimes)
It’s user-friendly (sometimes) Multitasking is easy It doesn’t scare people away CLI is a must Fast Powerful Feature-rich Complicated Often the only way Only way – professional tools, developer tools, remote access to servers, network devices management, fixing broken things 2018 Risto Heinsar

4 The basics* You’re shown the current working directory
Tab autocompletes (program names, file names, some commands) Up/down arrows go through previous commands Ctrl + c will (most of the time) abort/exit the current action Ctrl + d sends end of file signal Ctrl + l will clear the screen Widely-accepted practices, work on most terminals 2018 Risto Heinsar

5 Basic commands ls list directory contents cp copy file mv move file
ls -l list directory with details ls -la list directory with details, show hidden files ls -lat list directory with details, show hidden files, order by time modified cp copy file mv move file rm remove file mkdir create directory rmdir remove directory 2018 Risto Heinsar

6 Navigating in directories
cd foldername move to a folder cd move to the parent folder cd ~ move to the home folder cd / move to the root folder cd ~/P/subjects/prog1 move to the folder specified (full path) cd ../.. move two folders up (relative path) cd ../Desktop move one folder up and then to Desktop (relative path) 2018 Risto Heinsar

7 Man pages man pow man cp 2018 Risto Heinsar

8 Viewing files cat filename less filename more filename head filename
cat -n filename less filename more filename head filename tail filename 2018 Risto Heinsar

9 Running programs Programs in the PATH can be run just by name
env list your environment, including PATH To run your own programs, you need to specify the path to it (either relative or full) ./myprog program in the same directory as current path ../myprog program in the parent directory /home/usr/Desktop/myprog program full path To run a program, you must have execute privileges to it 2018 Risto Heinsar

10 Privileges Each file has a set of privileges for
Owner Group All other users Most common privilege types: read, write, execute (rwx) ls -l to view privileges chmod to modify privileges 2018 Risto Heinsar

11 Compiling gcc the program -o filename set the output file name Flags
-Wall Show “all” warnings -Wextra Show additional warnings -Wconversion Show type conversion issues Etc gcc -o myprogram -Wall -Wextra -Wconversion mycode.c 2018 Risto Heinsar

12 Try it out Optional: download basic vim config file:
Go to home dir: cd ~ Download config: wget blue.pri.ee/ttu/files/.vimrc Start to write a code file vim mycode.c Press the letter i to enter insert mode Code hello world Press escape to exit insert mode Save and quit vim !?!?! Compile from command line Execute from command line 2018 Risto Heinsar

13 Let’s talk streams Three standard streams: stdin, stdout, stderr
The streams can be redirected from their default locations No need to change the code, works on OS level (win, linux, mac) Allows us to test our (any) programs Easier to store the output of any terminal program image: wikipedia 2018 Risto Heinsar

14 Redirecting input stream (stdin)
Typically the program gets input from the keyboard We can redirect this input so it would come from a file Linux: ./program < data_file Windows command prompt: program.exe < data_file.txt Windows Powershell: Get-Content data_file | ./program.exe Data file is just a normal plain text file! MS Word, Wordpad, Openoffice Writer etc don’t produce normal text files 2018 Risto Heinsar

15 Redirecting output stream (stdout)
Used to store the output of the program to a file The text will no longer be shown on the screen Linux: ./program > data_file Windows: program.exe > data_file.txt Both streams can be redirected at the same time ./program < input_data_file > output_data_file 2018 Risto Heinsar

16 Lab task #1 Take the code from last week (matrices) and use stream redirection on it. If necessary, change the code to accommodate it Sample input and expected output are given under lab materials Make sure the answers are correct Redirect both stdin and stdout (input and output) – this means your input data comes from a file and the result is written to another one Demonstrate it 2018 Risto Heinsar

17 Lab task #2 Create a program that could verify dates
Use this program with the stream redirection for testing Don’t forget to test the edge cases (e.g. leap year 29th Feb) The task description, test data, advanced additions and guide are posted on the website Use the UML as the basis for your code Do not forget to compile after each update! Reminders and examples on logic operators on the following slides 2018 Risto Heinsar

18 Logical operations Logical and, conjunction Logical or, disjunction
Logical negation, inversin A B A &&B F T A B A || B F T A !A F T 2018 Risto Heinsar

19 Examples if (day >= 1 && day <= 29 && leapYear)
if (sorted == 0) if (!sorted) if (input >= MIN && input <= MAX) if (input < MIN || input > MAX) if ((input >= MIN && input <= MAX) ||(ignoreLim == 1)) if (day >= 1 && day <= 29 && leapYear) if (month == 1 || month == 3 || month == 5) 2018 Risto Heinsar


Download ppt "Command line."

Similar presentations


Ads by Google