0% found this document useful (0 votes)
14 views

Chap01 Linux

Uploaded by

BS GOURISARAN
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Chap01 Linux

Uploaded by

BS GOURISARAN
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

Numerical Seakeeping Analysis

Linux

Young-Myung CHOI

Dept. Naval Architecture and Ocean Engineering


Pusan National University
Linux Basics
Linux
➢ What is Linux ?
▪ Operating system like Windows or MacOS
▪ Operating system: Manages the relationship between hardware, software and
user interactions.

▪ Interaction with Linux machine via the shell


• Shell: Text-based interface for the computer, for Linux, “bash”
• The shell is run by the terminal

▪ Linux has a GUI interface too.

▪ Linux was built in C using open source licensing and philosophies.


Linux
➢ Linux is a family of open source Unix-like operating systems based
on Linux kernel
▪ First released on September 17, 1991, by Linus Torvalds
▪ It is an open-source operating system which is freely accessible to everyone.

➢ Remarks
▪ Linux is only the kernel, and is not the full system that is used.
▪ More than 90% of current Linux source code is composed by other developers.
▪ Nine out of top ten public clouds run on Linux.
▪ 99% of super-computer is using Linux system.
Linux
➢ Operating systems ?
▪ RPM: CentOS/RHEL, Fedora, openSUSE
• Red Hat Linux and SUSE Linux were the original major
distributions that used the .rpm file format, which today
is used in several package management systems.

▪ Debian based: Debian, Ubuntu, …


• Debian Linux is a distribution that emphasizes free software.
It supports many hardware platforms. Debian and distributions
based on it use the .deb package format and the dpkg package
manager and its frontends (such as apt or synaptic).
Linux
Linux
➢ Microsoft also released the WSL.
▪ WSL: Windows Subsystem for Linux
▪ Now: WSL version 2 is released.
WSL: Windows Subsystem for Linux
➢ For windows user
▪ https://docs.microsoft.com/en-us/windows/wsl/install
▪ Install Ubuntu from Windows Store
Raspberry PI
➢ Raspberry PI
▪ Single board computer to activate the education of computer science
▪ Raspberry PI OS Installer (https://www.raspberrypi.com/software/)
• SD Card & SD Card reader are necessary

Raspberry PI 5 Raspberry Pi OS Installer


Ubuntu Installation in Raspberry PI
➢ Raspberry PI OS Installer
▪ Choose Device → Rasbpberry Pi 5

▪ Choose OS → Other general-purpose OS

▪ Choose Storage → SD card to be installed

▪ Click “Next” and Install Ubuntu OS in SD Card


Ubuntu Installation & Cinnamon
➢ Ubuntu installation and user (from https://www.youtube.com/watch?v=5CBYGz_mO9U)

▪ System configuration: English only (No Korean !!)

➢ Cinnamon Desktop Environments


▪ Easy and Suitable for Windows familiar users
$ sudo apt update

$ sudo add-apt-repository universe

$ sudo apt install cinnamon-desktop-environment


Commands in the Shell
➢ Commands are pre-existing programs

$ <command> <options> <input/output>

➢ To get information of individual command use


▪ “man” (Short for manual page)
▪ “--help”

$ man echo
Useful commands
Command Operation Example
ls See folder contents ls -l
cd <folderName> Move into given folder cs Downloads
cp <source> <destination> Make a copy of given file in given destination cp file.txt myDir/
mv <oldName> <newname> Rename or move given existing file to given mv fil.txt file.txt
name/destination
cat <fileName> Print file contents to terminal window cat file.txt
touch <filename> Create empty file with given name touch file.txt
echo <string> Print given string to terminal window echo “hello world”
pwd Print working directory pwd
mkdir <directoryName> Create an empty directory at location specified mkdir ~/newDir
find –name <filename> Search for file
grep –nR <string> Search string recursively
exit Exit the shell exit
Example
➢ Make directory “tmp”

➢ Create a single file “file1.txt” in “tmp”

➢ Change the name of “file1.txt” to be “file2.txt”

➢ Remove the file “file2.txt”

➢ Create a single file “.hidden.file” in “tmp”

➢ How we can check the hidden file exist?


Linux File Permissions
➢ Permission Groups ➢ Change Mode : chmod <group><+|-><permission> <file>
▪ u – owner, g – group, o – others, a – all users ▪ chmod a-rw file1 : remove read and write permissions on file1 for all users
▪ chmod a+rw file1 : add read and write permissions on file1 for all users

➢ Permission Types
➢ Useful chmod / chown
▪ r – read: Ability to read the contents of the file/directory
▪ chmod +x <file>: give a permission to execute the file
▪ w – write: Ability to write the contents of the file/directory
▪ chown –R <user name> <dir. path>: change the owner of directory.
▪ x – execute: capability to execute a file or view contents of directory

➢ Example
▪ _rw_rw_rw = owner, group and all users have read & write permissions
▪ first character is either a - or a d : d means “directory”, “-” means file

$ ls -la
: List(ls) all(-a) file/directory in
a long(-l) format
File system
➢ Linux file system branching out from the root “/” forming a tree-like
hierarchy.
➢ Paths starting with “/” are called absolute paths.
▪ Start searching from the root
of the file system
➢ Paths that do NOT start
with “/” are called
relative paths
▪ Starts searching from current
directory

$ pwd
Linux file system
File system
Directory Description
/bin The /bin directory contains user executable files.
/boot Contains the static bootloader and kernel executable and configuration files required to boot a Linux computer.
/dev This directory contains the device files for every hardware device attached to the system. These are not device drivers, rather
they are files that represent each device on the computer and facilitate access to those devices.
/etc Contains the local system configuration files for the host computer.
/home Home directory storage for user files. Each user has a subdirectory in /home.
/lib Contains shared library files that are required to boot the system.
/media A place to mount external removable media devices such as USB thumb drives that may be connected to the host.
/mnt A temporary mountpoint for regular filesystems (as in not removable media) that can be used while the administrator is
repairing or working on a filesystem.
/opt Optional files such as vendor supplied application programs should be located here.
/root This is not the root (/) filesystem. It is the home directory for the root user.
/sbin System binary files. These are executables used for system administration.
/tmp Temporary directory. Used by the operating system and many programs to store temporary files. Users may also store files here
temporarily. Note that files stored here may be deleted at any time without prior notice.
/usr These are shareable, read-only files, including executable binaries and libraries, man files, and other types of documentation.
/var Variable data files are stored here. This can include things like log files, MySQL, and other database files, web server data files,
email inboxes, and much more.
Bash Basics
Shell States
➢ Each new instance of the bash shell maintains a “state”
➢ Bash rc file
▪ A shell script that is automatically run whenever Bash starts up
▪ Used to initialize your shell state

➢ Example
▪ vi ~/.bashrc
▪ How we can set “color_prompt” ?
Shell variables
➢ Declare variables in the terminal with a name and a string value

$ myvar=“myvalue” - Note: no white space allowed on either side of the “=“

➢ Refer to your variable using the “$” symbol before the variable name

$ echo $myvar

➢ Alias
▪ Rename a bash command, create your own shortcut
▪ Only exists within the currents state of your shell
▪ Can store alias in bashrc file to preserve alias across all shells

alias hello=“echo hello world!”


Environment Variables
➢ $HOME: A path to user’s home directory
$ echo $HOME

➢ $PATH: A list of specifying directories of executable programs

$ echo $PATH

➢ $LD_LIBRARY_PATH: A list of directories of libraries


$ echo $LD_LIBRARY_PATH
dirlist1;dirlist2
• Executable/libraries will be searched from the beginning to end.
• Orders could be important
What executables/library ?
➢ which <executable name>

$ which bash

➢ ldconfig –p | grep <library name>

$ ldconfig -p
Shell scripts
➢ Loop: While, For, Until

If operator
➢ If

➢ Numeric operation

➢ Function

➢ Input from user


SED (Stream editor) command
➢ Substitution of string

$ sed ‘s/string1/string2/g’ file.txt Change string1 to be string2

$ sed ‘s/\t/\/g’ file.txt Change tab to be enter

➢ Delete
$ sed ‘/TD/d’ file.txt Delete line including TD
$ sed ‘/src/!d’ file.txt Delete line not including src
$ sed ‘1,2d’ file.txt Delete the first and second line
$ sed ‘/^$/d’ file.txt Delete blank line
Example
➢ Create the shell script “print.sh” which prints out “Hello world !”

➢ Generate directories from 000 to 100, automatically

➢ Copy the shell script “print.sh” into each directory

➢ Change the word “Hello world !” to be “Hello world from <directory number>!”
in each “print.sh” in sub-directory, recursively.

➢ Run shell script “print.sh” from 000 to 100, recursively.


Useful Linux commands/tools for developers
➢ awk: A domain-specific language designed for text processing and typically
used as a data extraction and reporting tool

➢ grep: A command-line utility for searching plain-text data sets for lines that
match a regular expression

➢ vim/nvim: A free and open-source, screen-based text editor program

➢ meld: the visual diff and merge tool of GNOME, targeted at developers
Useful tools
➢ Vim & Vim Environments
▪ Vim Installation
$ sudo apt update
$ sudo apt install vim

▪ Vim settings (~/.vimrc)


➢ VS Code (download the recent version
<.vimrc Example>
▪ VS Code download (.deb for Ubuntu)
$ cd ~/Downloads
$ sudo apt install ./<vs_apt>

➢ Other tools
▪ Terminator (terminal emulator)
▪ dophin(File browser) – konsole (Terminal Emulator)
▪ evince (pdf viewer), meld (Comparison) <VS Code Download>

You might also like