Note that we used a different delimiter, @ for the substitution command. Sed permitsseveral delimiters for the s command including @%,;: these alternative delimiters aregood for substitutions which include strings such as filenames, as it makes your sedcode much more readable.
Author: admin
Open file and jump to a specific pattern in less
less -p pattern filaname
Creating indents in Confluence (Intranet)
{section} {column:width=5%} {column} {column} Text comes here {column} {section} Adding a ‘Table of content’ atht eh beginning of the cdocument h2. Table of content {toc:outline=true|indent=0px|maxLevel=3}
Creating debian binary packages from sources tar.gz
Install the following packages: checkinstall
Benchmarking and brute force testing of RAMs and CPU with STRESS
apt-get install stress $ stress –cpu 4 –vm 2 –vm-bytes 2G –timeout 60s $ stress –cpu 4 –vm 2 –vm-bytes 15G –timeout 1800s Belegt für 60s vier CPUs und 2 GB RAM. Funktioniert auch als normaler User, als root aber aggressiver, würde ich nach kurzem Test sagen. Hoffentlich lassen sich auch 16 GB belegen. Mit …
Creating a list of installed debian packages
PATH_TO_STORE=”/root/packages” FILE_TO_STORE=”installed_packages.txt” dpkg –get-selections | awk ‘{ if ( $2 == “install” ) print $1 ” ” $2 }’ > $PATH_TO_STORE/$FILE_TO_STORE
Grepping through zip files
zgrep -i affil -c web01-jadmin-2009-02-03-0006.log.gz
Maximum open files
The number of maximum files was reached, how do I fix this problem? Many application such as Oracle database server needs this range quite higher. So you can increase the maximum number of open files by setting new value in kernel variable /proc/sys/fs/file-max as follows (login as the root): # sysctl -w fs.file-max=100000 Above command …
Extract a part of a line using egrep
ls -l /home/helix/videos/* | cut -d’ ‘ -f8 | egrep -o ‘([^/]+$)’ In this example egrep starts from the back of the line and outputs only till ‘/’ appears This command can replace the basename command for multiple arguments
Using SSH to tunnel closed ports
ssh -2 sun.linux.local -L 7772:sun.linux.local:80
Testing a port on a remote host
echo x | telnet -e x hostname 22
Solving Delayed start of MC
This solves the trick by disabing the sub-shells. mc -u
SSH – Generating a host key
ssh-keygen -f /etc/ssh_host_rsa_key -N ”
UBUNTU – Selecting the standard java VM
update-alternatives –config java
Getting our own Internet IP from dyndns
wget -o /dev/null -O – http://checkip.dyndns.org | egrep -o ‘([[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3})’
Calculation with dates including chosen output format
date +’%d/%b/%Y:%H:%M’ -d “today +3 days +6 hours +15 minutes”
Generating consecutive numbers from start to end
eg. generating 1 2 3 4 5 …. till 100 > seq -w 1 100 (-w is for 01 02 03…. instead of 1 2 3 …. )
Send Output of program to a remote file (using compressed transmission)
cat /etc/motd | gzip | ssh remoteserver.com ‘cat | gunzip > /tmp/test_motd2’
MYSQL tools debian packages
maatkit and innotop maatkit as package is dependant to a perl module present in system maatkit as tar.gz can be installed independantly by a normal user
Export a gpg key
Use kgpg and right mouse click Export ….
Using DIG to resolve short (just the IP) of a (sub) domain
dig +short +tcp @79.171.206.20 www.jamba.de or dig +short +notcp @79.171.206.20 www.jamba.de
bash loops with miliseconds control
#!/bin/bash while true; do echo “Hello World!” perl -e ‘select( undef, undef, undef, 0.25 );’ done
bash loops with counter
for ((ip=1;$ip
To install Skype on AMD64 Linux system
AS ROOT: – Download the sykpe static version from: http://www.skype.com/go/getskype-linux-static and unpack it in /usr/local/skype cp /usr/local/skype/skype /usr/bin mkdir /usr/share/skype cp -a /usr/local/skype/avatars /usr/local/skype/icons /usr/local/skype/lang /usr/local/skype/sounds /usr/share/skype/ apt-get install ia32-libs AS USER: – Create a launch icon on desktop that runs: linux32 skype
Debian packages needed to compile software
apt-get install build-essential
Asking for Network status over snmp
snmpnetstat -v 2c -c public -t 330 -n -P tcp Hostname
a program that converts everything typed into it, into its backwards form
#!/usr/bin/perl print “Enter Anything: “; chomp($string = ); $string = reverse $string; print “$string\n”;
Logging all bash commands with user and timestamp
From: http://azio.org/2007/10/10/eternal-bash-history-super-duper-useful/ in /etc/profile and in /etc/bash.bashrc ———————————————————————– export HISTTIMEFORMAT=”(%d.%m.%Y) %H:%M ” export PROMPT_COMMAND=”${PROMPT_COMMAND:+$PROMPT_COMMAND ; }”‘echo “`date +’%d.%m.%y-%H:M:%S:’`” $USER “(“$ORIGINAL_USER”)” \ “COMMAND: ” “$(history 1 | cut -c8-)” >> /var/log/bash_eternal_history’ readonly PROMPT_COMMAND ———————————————————————– and then as root run the commands: touch /var/log/bash_eternal_history chmod 777 /var/log/bash_eternal_history chattr +a /var/log/bash_eternal_history
Preventing changes of variables through ssh session
– Make sure that the setting AcceptEnv is not set in /etc/ssh/sshd_config AcceptEnv Specifies what environment variables sent by the client will be copied into the session’s environ(7). See SendEnv in ssh_config(5) for how to configure the client. Note that environment passing is only supported for protocol 2. Variables are specified by name, which may …
Deleting a line in a file
eg. line 222 in known_hosts sed ‘222 d’ /home/tobias/.ssh/known_hosts > /tmp/1;cp /tmp/1 /home/tobias/.ssh/known_hosts
SSH Key forwarding
To be able to foreward an SSH key for ssh to server1 and from server1 ssh to server2 etc. 1) apt-get install keychain 2) use the following ssh command: > keychain -q id_rsa ; . ~/.keychain/$HOSTNAME-sh ; ssh -A user@servername 3) After logged in server1 always use: ssh -A user@servername
Advanced CRONTAB
There is an easy way to start a program during system boot. Just put this in your crontab: @reboot /path/to/my/program The command will be executed on every (re)boot. Crontab can be modified by running crontab -e Other available Options string meaning —— ———– @reboot Run once, at startup. @yearly Run once a year, “0 0 …
watch local network connections
———-Listen list————- netstat -ltpn lsof -i | grep LISTEN ———- Connection list ——- netstat -tpn lsof -i | grep ESTABLISHED
Filename with date_time in it
use this command inside the name $(date +%Y.%m.%d_%H:%M:%S)
Resuming an aborted scp transfer
Assume you have copied a file across the network using something like this: scp host:/path/to/file . Then assume something goes wrong, so the transfer is interrupted. To continue the transfer, do this: rsync –partial host:/path/to/file . (Or, rather, always use rsync as above when transferring very large files.) (Also note: I don’t know how frequently …
Install WAP-Browser on Firefox
1. Install WML-Browser: https://addons.mozilla.org/en-US/firefox/addon/62 2. Install User Agent Switcher: https://addons.mozilla.org/en-US/firefox/addon/59 3. Install XHTML Mobile Profile: https://addons.mozilla.org/en-US/firefox/addon/1345 4. Restart Firefox 5. Download this file to your desktop: http://techpatterns.com/downloads/firefox/useragentswitcher.xml (Right mouse button “Save Link As”) or http://techpatterns.com/downloads/firefox/useragentswitcher.xml 6. Go to: Tools -> User Agent Switcher -> Options -> Options 7. Click on Import and select the *useragentswitcher.xml* …
German keyboard layout on MACBook
Settings in Regional & Language -> Keyboad Layout ================================================= LAYOUT: setxkbmap -model macbook78 -layout de XKB OPTIONS: setxkbmap -option altwin:swap_lalt_lwin,compose:rwin,ctrl:nocaps,grp_led:caps,apple:badmap,eurosign:e setxkbmap -option apple:badmap Function keys reversal: ================ apt-get install pommed To inverse this behaviour, change fnmode = 1 to fnmode = 2 by editing /etc/pommed.conf Also to do: apt-get remove mouseemu To enable the Trackpad’s …