Ark Linux (original) (raw)
'sed' for Search & Replace in Single or Multiple Files
sed stream editor - A Powerful Text Stream Editor
sed 'search-text'/replace-text'
$ sed -i 's/AnanovaSitegeek/g' /home/ananova/index.php
This command would open index.php and line-by-line would replace all the occurrences of Ananova with Sitegeek.
Search & Replace in Vim
'-i' in-pace edit, i.e., no need to redirect the output from sed to new file
'g' global replacement to replace all occurrences once per line
Replacing nth occurrence
Use the '/1', '/2' instead of '/g' flags to replace the first or second occurrence of the pattern in a line.
's,' to specify the range, when the scale is determined 'g' option omitted
$ sed '1,3 s/AnanovaSitegeek/g' /home/ananova/index.php
The sed command replaces the lines with a range from 1 to 3.
'%' for the entire document
'$' indicates last line in the file
$ sed '2,$ s/AnanovaSitegeek/g' /home/ananova/index.php
The sed command replaces the text from the second line to the last line in the file.
Esc Press Shitft : and provide the following command to provide one tab before line
:s/^/\t/
Parenthesize first character of each provide provided as on output of echo command through the pipe:
echo "Web Hosting Industry Demystified" | sed 's/\(\b[A-Z]\)/\(\1\)/g'
(W)eb (H)osting (I)ndustry (D)emystified
To replace the string on a specific line number
$ sed '3 s/AnanovaSitegeek/g' /home/ananova/index.php
The above sed command replaces the string only on the third line.
Deleting Lines from File
Delete the last line
$ sed '$d' index.php
Delete a particular line say n
$ sed 'nd' index.php
$ sed '3d' filename.txt
Delete line from range x to y
$ sed 'x,yd' index.php
$ sed '12,15d' index.php
Delete from nth to the last line
$ sed 'nth,$d' index.php
$ sed '10,$d' filename.txt
Delete pattern matching line
$ sed '/pattern/d' index.php
$ sed '/flowentry/d' index.php
World of Text Editing with Vi & Vim
'vi' written in 1976, become the part of BSD UNIX in 1978. According to the Linux Journal survey, even without GUI, it is the most popular editor, and GUI GNOME editor comes second. The reason behind its popularity is its permissiveness, convenience, performance, and speed.
Vim (vi Improved) released in 1991 by Bram Moolenaar, targeting Amiga systems. It is distributed as a vim-enhanced package with GUI frontend. The most notable improvement over 'vi' is its syntax highlighting feature for languages such as PHP, PERL, and PYTHON.
$ alias | grep vi alias vi='vim'
Vim needs 'vim-XII' package for the graphical interface. You can install it with the following command:
$yum install vim-XII
Edit file using vi or vim
$vi
$gvim
$vimx -g (without -g option it starts normal vim program)
Control Functionalities & Customize Appearance
/etc/vimrc for all users i.e., system-wide settings
~/.vimrc for each user
By Default Values in /etc/vimrc
if v:lang =~ "utf8$" || v:lang =~ "UTF-8$"
set fileencodings=ucs-bom,utf-8,latin1
endif
set nocompatible " Use Vim defaults (much better!)
set bs=indent,eol,start " allow backspacing over everything in insert mode
"set ai " always set autoindenting on
"set backup " keep a backup file
set viminfo='20,\"50 " read/write a .viminfo file, don't store more
" than 50 lines of registers
set history=50 " keep 50 lines of command line history
set ruler " show the cursor position all the time
" Only do this part when compiled with support for autocommands
if has("autocmd")
augroup redhat
autocmd!
" In text files, always limit the width of text to 78 characters
" autocmd BufRead *.txt set tw=78
" When editing a file, always jump to the last cursor position
autocmd BufReadPost *
\ if line("'\"") > 0 && line ("'\"") <= line("$") |
\ exe "normal! g'\"" |
\ endif
" don't write swapfile on most commonly used directories for NFS mounts or USB sticks
autocmd BufNewFile,BufReadPre /media/*,/run/media/*,/mnt/* set directory=~/tmp,/var/tmp,/tmp
" start with spec file template
autocmd BufNewFile *.spec 0r /usr/share/vim/vimfiles/template.spec
augroup END
endif
if has("cscope") && filereadable("/usr/bin/cscope")
set csprg=/usr/bin/cscope
set csto=0
set cst
set nocsverb
" add any database in current directory
if filereadable("cscope.out")
cs add $PWD/cscope.out
" else add database pointed to by environment
elseif $CSCOPE_DB != ""
cs add $CSCOPE_DB
endif
set csverb
endif
" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has("gui_running")
syntax on
set hlsearch
endif
filetype plugin on
if &term=="xterm"
set t_Co=8
set t_Sb=^[[4%dm
set t_Sf=^[[3%dm
endif
" Don't wake up system with blinking cursor:
" http://www.linuxpowertop.org/known.php
let &guicursor = &guicursor . ",a:blinkon0"
Turn Line Numbering ON/OFF
To enable line numbering add the following command in a file:
vi ~/.vimrc
set number
and to set line numbering off
set nonumber
Turn Off Argument Highlighting
You can provide search arguments to vi, and it will take directly to the first appearance of the word in the file or on a particular line number.
vi +55 index.php
vi +/copyright index.php
The word searched is highlighted in color, if not desirable, can be turned off by adding:
set nohlsearch
Toggle Line Numbering ON/OFF
Navigate to particular line number by typing:
G
or
gg
Like 3G or 3gg to navigate to line number 3. If we don't wish to provide 'G' and with to reach directly to a line by providing line number, followed by 'Enter' key, then type the following line in ~/.vimrc file.
nmap G
We provide a command
vi +235 index.php
to reach that 235 line number. Press Shift g to reach the end of file and gg to the first line of the file.
Linux Trickery Shortcuts
Double pipe || between two commands - if the first command fails, then second will execute.
||
Double && between two commands - the second command would run only when first succeeds.
&&
Example:
cd joininternet || mkdir joininternet && cd joininternet
The above command changes directory to join-internet, and suppose if does directory does not exists, then the command would fail, but as we have provided another after ||, then the second would execute and create the directory join-internet. After that, as change directory command is also given after &&, it would also get completed. Finally, we reach to directory join-internet.
Command History - If we press up arrow keyboard key, the lastest command executed in the history gets displayed.
Last command argument with !$
mkdir join-internet
cd !$ Here, i$ = join-internet
cd join-internet || mkdir !$ && cd !$
!v would look in the history for a command which starts with letter 'v'. Similarly, if we provide !?75, it would look for 75, anywhere as an argument or its part.
date --date "75 days ago"
Linux the topmost choice of business organizations
Linux is authoritative and accessible as it is dependable, reliable, and resilient. It has a vast community which takes ownership to Linux distributions and helps to develop services, applications and provide remedies to bugs.
Linux Enterprise Disributions
Cent OS (Communition Enterprise Operating System)
https://wiki.centos.org/Download
It's free and open to use under the terms of GPL license.
Red Hat, Debian, SUSE Enterprise
Home or Enthusiast-oriented Distributions
Fedora, Open SUSE
Benefits
- The administrators modify the GRUB menu to make it more secure, furthermore use the command line to debug and repair boot issues.
- For Linux files and directories are just different file types. With the BTRFS (Better FS) enterprise file system is blown away with power and ease in comparison to early traditional file system designs like LVM.
- Administrators can download packages for distribution with no requirement for their installation.
- Easy to manage processes and control services.
- Managing users require less time.
- Naginx - a performance-centric web server, is rapidly taking share market from Apache and has already surpassed IIS.
- PAM (Pluggable Authentication Module) helps to manage when and how users connect.
- Administrators can harden the Linux system to gain best.
Important for Administrators
Change the Port of the server
vi /etc/ssh/sshd_config
change #Port 22
to Port 8022
/etc/init.d/sshd restart
Creating Domain Entry
vi /etc/named.conf
cd /var/named/
Checking Error Logs
tail -f /usr/local/apache/logs/error_log
Business Web Hosting on Dedicated Servers
Most branded businesses opt for a dedicated server or cloud hosting for their website.
Why dedicated-Server?
- Host-only the customer's website who have rented the Server
- Provides total control on bandwidth, space, and security
- Dedicated equipment leased from the provider is often reliable
- Most companies offer excellent customer services
Discounts
Most companies offer attractive discounts when payment mode is quarterly, half-yearly, or annually. The businesses choose a monthly way, as they don't want to be stuck for more extended periods.
Dedicated Server Customers
- Large businesses or websites having substantial traffic
- The websites collecting credit card information, name, address, or other private or confidential details like shopping carts, forums.
- Online gaming or casino websites
Benefits Over
Shared Hosting
- Mostly hosting business starters or personal websites devoted to celebrity or resume web page.
- Limited or otherwise capped space and bandwidth
Free Server
- Mostly hosting personal web pages.
- The provider puts ads on web pages to compensate for the cost.
Drawbacks
Costliest: cost run a couple of hundred dollars
Find the best-dedicated server providers on Ananova, where quality companies listed with the monthly rate, space, and bandwidth they are offering.