Skip to content

Latest commit

 

History

History
175 lines (134 loc) · 7.96 KB

Introduction to Linux.md

File metadata and controls

175 lines (134 loc) · 7.96 KB

Introduction to Linux

author: Ouso D. O.

date: 09-08-2018

autosize: true

Sensei penguin!

======================================================== The Penguin teacher!

Objectives

  • Understand basic Linux terminologies
  • Reasons to adopt Linux
  • Understand basic Linux filesystem
  • Differentiate between relative and absolute paths
  • Learn to make dirs and common operations with directories
  • Be able to explain the "ls" output
  • Know how to manipulate files and file contents
  • Basics of shell scripting

Basic Terminologies

  • Kernel - the core functionality of an operating system, translates commands from other software directly to the hardware interfaces.

  • Distributions - operating systems based on the Linux kernel, eg. Ubuntu (Deb), CentOS (Fedora) & openSUSE (SUSE)

  • CLI/Terminal - a method of interaction with the computer based on text commands entered at the prompt

  • GUI - a method of interaction with the computer that makes use of visual representations of elements

Why Linux?

  • It is FLOSS-based
  • World's largest and most prevalent open source
  • Long Term Support (LTS)
  • Many developers around the world contribute to it
  • Most secure
  • Customizable
  • Multi-user, multi-tasking (servers)
  • A Major force in computing, eg. supercomputers, phones, stock exchanges etc

File System

  • Partition - a logical part of a disk
  • Filesystem - a method of storing/finding files on a hard disk Linux uses '/' to separate paths, windows uses ''.

Below is the partial Linux FS representation

Linux File System

Linux

A comparison between Win and Linux filesystems is illustrated in the image below Windows-Linux FS Comparison

  • For more details see the Linux Filesysytem Hierarchy Standard
  • A new terminal will land you in the home directory
  • While on the terminal you will be associated to one directory at a time called working dir/current dir

Paths

  • The command pwd (present working directory) returns the absolute path to your working dir

Two types of paths exist:

  • Absolute path - describe the path of a file/dir from the root (/) all the way to it
  • Relative path - describe the path to a file/dir from the current working dir

Let's illustrate the two paths with a fig

Dir Tree

What is the absolute path to "README.md"? /home/oface/Git/Images/README.md

What is the path to "LinuxFS.png" assuming my current working directory is PythonCoding? ./../Images/LinuxFS.png

Directories and associated commands

  • In Linux "Directories" are equivalent to Windows "Folders"

Some of the commands associated with directories include:

  • To create a dir use mkdir <dirName>
  • To remove a dir use rmdir <dirNmae>
  • To move from one dir to another, use cd <dirPath>
  • To list dir content, use ls while inside the dir or ls <dirPath> from a different dir
  • To rename a dir, use mv <oldName> <newName>

Output of the ls -lh Cmd

ls -lh output

  1. File(-) or Directory(d) or Symlink(l)
  2. Owner file permissions
  3. Group file permissions
  4. Global user file permissions
  5. Number of links
  6. Owner name
  7. Owner group
  8. File size
  9. Date and time of last modification
  10. File/Directory name

"total BLOCKS" means the total disk allocations of the dir content listed

Some shortcuts

  • cd~ or cd: takes you to home dir from wherever
  • cd -: takes you to previous dir
  • cd ..: takes you to parent dir
  • Ctrl+L: clears terminal
  • Ctrl+C: cancels a running program
  • Crtl+D: exit terminal
  • Tab: auto complete
  • Tab Tab: display possibities for autocomplete

Manipulating files

  • touch: to create, modify and change timestamp of a file; syntax touch <fileName>
  • gedit: to create a text file; syntax gedit <fileName>
  • wget: is a free utility for non-interactive download of files from the Web. It supports HTTP, HTTPS, and FTP protocols, as well as retrieval through HTTP proxies; syntax wget <option(s)> <URL>
  • cp: copy file/dir; syntax cp <origiLocation> <finalLocation>
  • rm: delete files; syntax rm <file>
  • mv: move file/dir; syntax mv <origiLocation> <finalLocation>

To figure out the many possible options of a command use man <command> to get a summary manual of how to use that command. Linux commands generally follow the syntax command <option(s)> <argument(s)>

Accessing file contents

  • cat: to view content of a small file in stdout; syntax cat <file>
  • more: to view a large file in stdout by scrolling unilaterally - downwards; syntax more <file>. Use keyboard "Spacebar" to scroll page by page
  • less: to view a large file in stdout by scrolling bilaterally - up/downwards; syntax more <file>. Use keyboard "Spacebar" to scroll page by page
  • head: explore, by default, ten top lines of a file: syntax head <file>
  • tail: explore, by default, ten last lines of a file: syntax tail <file>
  • wc: word count, to explore number of lines, words and characters of a file: syntax wc <file>

Manipulating file contents

  • sort: re-order file content alphabeti/numeri-cally; syntax sort <file>
  • uniq: remove redundancies; syntax uniq <file>
  • join: compare content; syntax join <file1> <file2>. Output common entries
  • diff: compare content; syntax diff <file1> <file2>. Output the differences
  • grep: Global Regular Expression Pattern, search for patterns; syntax grep <pattern> <file>

Wildcards: special characters used as patterns to help with quick targeting of files or file sections/dirs, see document on wildcards starting from page 23

Shell scripting

What is a script? A short program written in the programming languages used for automation, especially when handling huge amounts of data which require similar treatment. A shell script file basically contains a set of instructions in a shell language to be performed on files

What is shebang? Begins a shell script, to set the interpreter environment to be used to execute the set of instructions that follow, "bash" is such an interpreter, several others exist. Syntax #!AbsolutePathOfInterpreter eg. #!/bin/bash or #!/usr/bin/python

After writing your script you will need to make it executable by using the chmod command before you can run it

Let's try out a short script that prints out a sentence. . .

TestScript

AdvancedScript

=============================================================================================

Thank You

email: [email protected]

twitter: @ousodanos