Chap01 Linux
Chap01 Linux
Linux
Young-Myung CHOI
➢ 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.
$ 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”
➢ 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
➢ 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
$ echo $PATH
$ which bash
$ ldconfig -p
Shell scripts
➢ Loop: While, For, Until
If operator
➢ If
➢ Numeric operation
➢ Function
➢ 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 !”
➢ Change the word “Hello world !” to be “Hello world from <directory number>!”
in each “print.sh” in sub-directory, recursively.
➢ grep: A command-line utility for searching plain-text data sets for lines that
match a regular expression
➢ 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
➢ Other tools
▪ Terminator (terminal emulator)
▪ dophin(File browser) – konsole (Terminal Emulator)
▪ evince (pdf viewer), meld (Comparison) <VS Code Download>