Tag Archive for 'Linux'

Page 2 of 2

Sed replace text


I show you in this little example how to replace quickly text using sed:



1
2
cat examples.conf 
foo+bar=foo


1
sed -i 's/foo/foo_bar/g' examples.conf

foo in file examples.conf will be replaced with foo_bar
After replacement:

1
foo_bar+bar=foo_bar

Dry run without changes:

1
sed 's/192.168.0.1/nameserver.local/g' $domain

GIT Version Control System

GIT is one of the best systems for version control. I don’t want talk about benefits or other things now. I tell you how to work with GIT and do really useful things with it. Very simple installation and a list of frequently used commands:







Install GIT: (You see It’s very easy)

1
aptitude update ; aptitude install git-core

Create new git repository:

2
git init

Add all changes to repository:

3
git add .

Consolidation of all changes:

4
git commit -a

Consolidation of all changes with commit message:

5
git commit -a -m "Commit Message"

Revert last commit:

6
git reset --soft HEAD^

Current working directory status:

7
git status

Diff since last commit:

8
git diff

Add link to remote repository:

9
git remote add origin ssh://id@gitcher/opt/repository

Remove link to remote repository:

10
git remote rm origin

Get all new versions from source(remote repository):

11
git pull origin master

Push all new changes to source(remote repository):

12
git push origin master

Create new working tree(branch):

13
git branch branch_name

Change between branches:

14
git checkout branch_name

Merge braches:

15
git merge branch_name

Delete branch:

16
git branch -d branch_name

Remove branch force:

17
git branch -D branch_name





And more complicated examples
Create local working space and push all changes to remote repository:

1
2
3
4
5
6
git init
touch Initial_File
git add Initial_File
git commit -a -m "Initial commit"
git remote add origin ssh://id@gitcher/opt/repository
git push origin master



Create brach, edit and merge:

1
2
3
4
5
6
7
8
9
10
git init
git branch test
git checkout test
# ...
# add changes
# ...
git commit -a -m "Branch commit"
git checkout
git merge test
git branch -d test

Messed up the commit message? This will let you re-enter it:

1
git commit --amend

What run level am I in?

Q: How can I find out what run level a system is in at the moment?

1. The runlevel command tells you what run level is running
2. The who -r command also tells you the run level

1
2
firewall ~ # /sbin/runlevel
N 2

or

1
2
firewall ~ # who -r
         run-level 2  2010-05-28 23:13

Tcpdump to file

Very easy dumping of traffic with the w flag. You can use it for screen and later for wireshark analyses.

1
tcpdump -w http_traffic -n -i any port 80

Rsync with progress bar

1
rsync -azv --progress /opt/Samba/* root@server:

9142272 2% 2.86MB/s 0:01:48