-Linux Academy Notes-
User Guide:
red = command
Purple= command options
figure=figures with respective file name, located inside Figure folder
Lecture: Setting up Linux Academy server:
ssh ess
yes
123456 pw
user@hostname
change pw: passwd
Current pw: 123456
New Pw:
Change root pw
Super user command: su –
Takes to root prompt
Root pw: 123456
Change root pw:
root@hostname
exit
user@hostname
LS command: ls
Vncpasswd command: vncpasswd
Password:
Verify:
To Reboot: go to root: su –
root@hostname
reboot server: reboot
Lecture: Free Software Foundation (FSF) and Open Source Initiative (OSI)
GPL: General public license is license used by Linux Kernel.
FSF: Free Software Foundation, driving force behind Gnu’s Not Unix (GNU) project.
Freedom 0:Free to use software, SW for any purpose.
Freedom 1: Free to examine the source code and modify.
Freedom 2: Free to redistribute.
Freedom 3: Free to redistribute modified SW.
2 versions of GPL used today: GPLv2 and GPLv3
Lesser GPL. LGPL. Library GPL are blocks of codes that can be used by other program eg: dialogue box etc.
OSI: Is a process for SW development through peer review and transparency.
catconcatenate: link things together in a series, to display text file on screen
Lecture: Desktop Skills Hands-On
KDE: K desktop environment for Linux, default for Mandriva and SUSE (Prn: Suza).
GNOME (prn: Nom): Popular desktop environment default for Linux distributions like Red Hat, CentOS
LXDE: Lightweight X11 Desktop Environment,for using less resources, used for old computers
UNITY: Canonical, publisher of Ubuntu distributions, created this
XFCE: modeled as commercial desktop
Terminal: Provides text-mode user interface
Lecture: Industry uses of Linux, Cloud Computing and Virtualization
Industry uses of Linux OS: Web Servers, Mobile app servers (some games servers), SQL DB servers (e.g. MySQL)
Linux is a contender Cloud computing. Eg. Gmail, Evernote, Dropbox Clouds is backed by Linux based back-end OS.
Virtualization is the creation of virtual OS through a virtualization SW that is known as hypervisor. This allows us to virtualize an OS in another computer/OS known as host. The virtualized OS that live upon this host are known as guest OS or Virtual Machines.
Virtualization SW examples: VirtualBox, VMWare, KVM/QEMU, XEN allows us to virtual in machines like Windows Laptop.
Lecture: Basic Shell
Shell: DOS is command line Shell
Linux is a command line Shell, but we can choose Shells from:
Sh – Bourne shell
Bash – Bourne again shell (default for most Linux distributions)
Csh – C shell (similar to C language)
Tsch –tsch shell
Zsh – Z shell
Ksh – Korn shell
Echo $SHELL– to show text in a command
To change shell- zsh
Sudo yum install (to install zsh shell)
cat /etc/passwd – shows which shell we are default.
Control+alt+F2-F6 (go in and out of other shells/new sessions) and,
Alt-F1come back to original session
Lecture: Command Line Syntax – ls
(L) ls- list (gives listing of files and folders).
ls –a shows all hidden files
ls –l shows long string of details of files with dates
ls –p shows folders file name with ‘/’ at the end of file name
ls -Rlists the directory and folders and what files live in files1, 2
Make directory mkdir dirtest1
Change directory cd dirtest1/
Lecture: Command Line Syntax- $PATH, Case Sensitivity
Every variable starts with ‘$’ sign.
echo $PATH shows path
cp copy
Lecture: Command Line Syntax- Basic Commands
halt shuts down Linux OS
reboot (Root) shuts down Linux and restarts back up
init o (Root) Shuts down OS, init 6 (shuts and back up, reboot)
shutdown(must be root)
shutdown –H Halt the machine
shutdown –P power off machine
shutdown –R Reboot machine
shutdown –h just power off, like halt command
shutdown –c Cancel power off
exit close terminal session from (public IP)
su - substitute user or super user from user to root, or vice versa
env shows all environment variable in system
top shows list of application & processes running in the system with process id
q quit
clear clear screen
which halt shows full path of where application lives
which reboot
which su
whoami shows which user you are
netstat shows status of network and current counteractions
route views routing table
ifconfig show net configuration in network card and modify settings (root)
ip addr shows all the ip address
Lecture: Command Line Syntax- uname
uname shows what OS we using
uname –s display linux Kernel name
uname –n displays system host name
uname –r displays Kernel release number
uname –v version number for Kernel
uname –m hardwarearchitecture
uname –p shows processor type
uname –i hardward platform
uname -o shows OS
uname –a shows all info at once
Lecture: Command Line Syntax- Command History, Command Completion
Every time we hit command, its saved in the .bash_history file
ls –a shows hidden file
cat .bash_history
cat ^ shows last entry
export HISTFILESIZE=99999
echo $HISTFILESIZE
Type: tar –zxvf +te(can’t remember the whole file name) + Tabmultiple types), it will auto complete
Then you can start to type the rest of the file name from the list and it will auto complete typing the full name
P.S: Tar is used to zip/unzip files
Lecture: Command Line Syntax –cd and pwd
cd change directory, will bring to home folder/directory i.e. to user@drbindash1
pwd Print working directory (user/root)
If you want to move to a specific folder:
cd dirtest1 takes us to test1 folder
Lecture: Shell Configuration Files
Login shell, unlike terminal, looks black like DOS
cat /etc/bashrc contains shells functions and aliases
cat /etc/profile (etc pronunced et-c)
ls –a all hidden files
alt f2-f6 to move into Login Shell
Lecture: Variables- Environment/System Variables and user defined variable
Variable is a place holder for another value, that are stored in RAM that is reserved to store whatever value you want to put in it. It’s a container within a memory. There is user defined and system defined variable.
An Environment is a set of variables that are used in configuring system computing environments by the system itself.
eg: we used Tilda key (~) after cd command, it will take us to home. How does cd knows this?
Some commonly used environment ENV variables of Linux systems:
BASH and SHELL variable /bin/bash
CPU i686 specs of your system
DISPLAY location of X windows
EUID user id of current user
HISTFILE stores no. of command saved in our files
HISTSIZE how many commands history saved eg. 9999
HOME path to current home user directory
HOST and HOSTNAME
LOGNAME username of current user
MAIL path to mailbox file
OLDPWD stores path to prior current directory
OSTYPE type of OS currently being run, usually Linux
PATH
PWD path to current working directory
PSI stores characters used to do shell prompt
USER & USERNAME store name of current user
env shows all variables
set shows all variable in alphabetical order
cd /var/opt/
$PATH=$PATH:/var/opt/ Add new path
vim to edit file
Lecture: Variable- User Defined
Recreate customized user defined variable:
AWESOME=”stephen”
echo $AWESOME (Shows Stephen)
export awesome (other Shells get this).
Cannot contain hyphens or underscore. Always use all CAPS. Variable names cannot contain space.
Lecture: Globbing
Wild card character to find names from the system. Global Command = Globbing. Built into bash shell now.
ls *.txt find any file name with .txt at the end.
If we know beginning of a wild card name but not the end, then:
ls test* shows file with name ‘test’ and ‘*’ meaning anything that follows that.
ls ?.txt ‘?’ means 1 character.
If we know 9 characters, then:
ls ?????????.txt shows files with 9 characters.
If I know my file name starts with Monday and ends with file. Then:
ls Monday-file?.txt
To find specific range of letters then,
ls [F]*.txt Shows file with name begins with F and is a .txt file.
ls [f].txt shows file with starting lower case f.
ls –al shows all the files.
ls f[igh][lfz]e*txt 1stletter certainly is f but 2nd could either be i or g or h and the 3rdwith l/f/z and certainly ends with e. We use ‘*’ because we don’t know the number, it is used for any character/set of character/ or nothing.
Lecture: Quoting
Double Quote to substitute values or command.
eg: echo “Username is $USER”
This will print what the current Username: Username is drbindash
Single quote: preserves the literal meaning of each character of a given string and will turn off the (special) meanings of all character.
eg: echo ‘Username is $USER’. This will print/echo the literal Username of $USER. Username is $USER
Backslash: Takes away or removes the (special) meaning from a single character and can be used as an escape character. If we did not have the \ character before $5.00 here it would try and interpret the following command as variable.
$ echo “The cheeseburger is going to cost you $5.00”Will be printed: The cheeseburger is going to cost you .00
But if we used the \ we can negate our special character $echo “The cheeseburger is going to cost you \$5.00”. Printed: The cheeseburger is going to cost you $5.00.
Lecture: Formatting Commands
\ backslash can be terminator too. We can use \ and go to the next line with prompting the command.
Lecture: Working with Options
Linux command parameters can be divided into 2 types>
Parameter with a dash (-) are called options and with no leading dash are called arguments.
ls –al are two options (a= all, l =long listing),
we can use this as ls –a –l
Formatting commands conceptually looks like this:
command – what to do?
options – How to do it?
arguments- What to do with it?
Using the Command Line to Get Help:
Lecture: Man
The Linux MAN (Manual) pages or Manual Page Systems. Meant to be used only for quick remainder, not as tutorial. It’s for only someone who knows the basics.
Man Pages are organized into 9 sections. We use section 1 the most.
Section 1. Executable programs and shell commands.
2 System calls provided by kernel
3 library calls
4 device files usually stored in /dev
5 file formats
6 games
7 Miscellaneous (macro packages, conventions, and so on)
8 system admin commands (programs run mostly or exclusively by root)
9 Kernel routines
man cp learn about copy files and directory
man cal learn about calendar
man rm remove
man vim
man passwd
man 5 passwd Pulls up section 5 and specific file formats about passwd
What if we don’t the man page or what command?
whatis passwd shows 3 diff possible man (manual) pages with keyword passwd
apropos man Find everything about manual (man)
Easier way by using K flag:
man –k man Anything about manual
man –k passwAnything about password
man –k network Anything about network
man –k mv Anything about move
MAN pages are organized like to:
Name, Synopsis (flags), Description, Options (or flag sections), Files, See Also, Bugs, History, Author
mv test.sh logs/ Move test.sh file to logs file
mv Monday-file1.txt newfilename.txt Moves Monday-file1 and renames it simultaneously too
Using less key commands to navigate MAN pages:
H or h displays help
Page down, spacebar, ctrl V, Ctrl F moves down 1 screen
Page Up, Esx V, Ctrl B moves up one screen
n or / repeats the previous search
Q or ZZ quits
/Options Searches ‘Options’ in Man page, Works like Ctrl-F
Man less Shows all about less
Lecture: Info
Info Page: Similar to man but the goal is to support functions which man cannot. E.g.: Hyperlinks.
info info to learn about info system itself
Navigate info:
?Displays help info
Nnext
P back
U up
Arrow Up down
L displays last page
Entermoves to new node once you have selected it
Tdisplays top page
Qexits from system
Lecture: locate, find, whereis, and using/usr/share/doc/
Other ways to get help:
README files, readme.txt
The downloaded README for unzipped source files are usually found in:
/usr/doc/packagename
/usr/share/doc/packagename
/usr/share/doc/packages/packagename
Some programs have configuration files located in:
/etc
If we are using RPM-based Linux distribution we can use the RPM tool to locate documentation for a package.
Eg: rpm-ql packagename | grep doc
rpm –ql passwd | grep doc (|) is called piping out
To find readme file for the Yum application manager:
rpm –ql yum | grep README
Most packages use best practice naming convention.
Other ways to find:
find/usr/share/doc –name “*passwd*”
locate passwd
whereis passwd
Utilities to read different file formats:
file extensions:Programs to read them with
.1- .9man, info, less
.gz or .bz2gunzip, bunzip2, less
.txt less and any text editor vi, vim
.html .htmany web browser
.odtLibreOffice, OpenOffice.org, any word processor app
.pdfxpdf, Adobe reader
.tif, .png.,.jpgGimp
Using Directories and Listing Files:
Lecture: The Linux File System
File system is where data is saved. You can save a file somewhere and find it later.
Linux file system used a hierarchy(FSH- File System Hierarchy) standard to organize and store data. At the top of the tree there is root directory. Under it are sub directories.
ls
bin dev home lib64 mnt proc run srv tmp usr
boot etc lib media opt toot sbin sys users var
bin directory: contains files to run the Linux shell.
Next is boot directory, contains boot file to boot file system.
Dev (Device) has various file hard drive system we can install. Block devices: pen drive.
Next is etc (prn: 8c). Services running in the system.
Eg: /etc/aliases contains a table used to redirect all to local users
/etc/exportsconfigured file systems to be exported to remove NFS clients
/etc/hosts a list of hostname to IP address mappings
/etc/passwdour Linux systems user accounts file
/etc/shadow contains encrypted passwords for our user accounts
/etc.X11where X windows configuration files are
/etc/fstab, /etc/groups, .etc/grub.conf and so on.
Home folder or directory contains sub directory. We have user called user and drbindash.
Lib (library) folder contains code library used for programs.
Media directory is used by open source or fedora for USB.
Mnt (mount) used to mount external drives.
opt (option) files for installing some programs manually.
proc (process) has numbered folders for various processes.
rootdirectory is the root user’s home directory.
run
sbinis similar to bin folder. Has system manager files.
srv (services)
sysinfo about systemhardware.
tmpinfo about temporary files
users
usr
varLinux variable data including log files.
Linux disk files systems contain file system format. Disk file system is for reliability of file system in a system. Linux have wide variety of disk file system like: ext2 (oldest and fastest file system, max 2TB file, 255 characters long, system itself 4TB), ext3 (updated ext2, allows journaling, records transactions in journals, in event of power outage it can replay system when power is back on unlike ext2 file system), Reiser file system (uses journaling too but different internal structure, 16TB itself, 8TB biggest file), ext4 (1XB volume, 1TB file).
Lecture: Files, Directories
pwd power print working directory shows which directory we are at
ls shows various directory and suppose we want to go to media directory
cd media/ change directory to media
pwd shows we are in media directory
cd just cd will take us to home and it shows tilda (~) i.e. Home
cd .. takes us up one directory
cd user/
If we want to move two directories up:
cd ../ ..
We can use ls to list contents:
ls
ls/var/logShows contents in log folder
ls/home/user shows contents in user
ls –l Long listing of the folders.
ls –R displays content of current directory and sub directories
Lecture: Hidden Files and Hidden Directories
Linux OS need to hide so that we don’t accidently edit or mess it up. Any file beginning with period (.) is hidden. eg: .local
If we want to create a hidden file. touch .testfile.txt (file with period in front).
To create new folder (directory): mkdir .testfolder (with period in front).
Lecture: Absolute and Relative Paths
pwd prints working directory, which is /home/user which is the relative path i.e. path we are currently in.Absolute path: We provide the long and complete path. Eg: ls /home/user/testdir2/ or use relative path: ls testdir2/
Creating, Moving and Deleting Files
Lecture: Files and Directories
root@dr touch file.txt created a file.txt
ls –al see details of file
touch file.txt will update the time stamp of file.txt
touch –d “February 1 2015” file.txt File.txt will be dated February 1st
cp file.txt file1.txt will copy file.txt
cp file.txt newdir1/ will copy file.txt to newdir1 folder
ls
copy file.txt newdir1/newfilename.txt will have a brand new file newfilename.txt at newdir1
-f f flag force
-p flag preserving original file ownership on file
-i flag interactive flag, copy (cp) will ask before overwriting a file that already exists
-R recursive will copy all directories recursively
-a archive, same as –R, preserves ownership of the older files as well
-s symbolic links
-u update, copy file only if original file is new than old file
root@dr mv file1.txt file2.txt moves file1 and simultaneously renames it
mv file2.txt testdir2/ moves file2 to new directory testdir2
Let’s check testdir2 and check contents: cd testdir2/
To move and rename file while taking to new location:
mv file.txt testdir2/newname.txt
Let’s see folder testdir2: cd testdir2/
ls
To delete file:
rm newname.txt removes or deletes the file
y type yes for confirmation
check: ls
root@ dr: Let’s create few files:
touch file1 file2 file3 file4
ls shows files
rm file1 file2 file3
Are you sure? y y y