Linux
From SpenchWiki
Contents
- 1 ssh / autossh
- 2 Console shortcuts
- 3 Screen
- 4 Useful apps
- 5 Redirection
- 6 Counting files
- 7 find
- 8 Recording the screen
- 9 Prevent screen blanking
- 10 rsync
- 11 tcpdump with greater snarf size
- 12 Scripts
- 13 AWStats
- 14 SNMP
- 15 RRDTool Spike Removal
- 16 diff
- 17 HDD Recovery Resources
- 18 Notes on distributions/environments
- 19 Additional resources required by packages
- 20 git & ssh
ssh / autossh
autossh -M 0 -i .ssh/id_rsa-host -v -o "BatchMode yes" -o "ServerAliveInterval 10" -o "ServerAliveCountMax 3" -L 12875:127.0.0.1:12345 user@host
ssh -i .ssh/id_rsa-host -N -T -v -o "BatchMode yes" -L 12876:127.0.0.1:12345 user@host
Console shortcuts
- Ctrl + Z: stop (fg/bg)
- Ctrl + Y: stop only when process tries to read input from console
- Ctrl + S/Q: XON/XOFF (Shift + PgUp/PgDn to scroll)
- Ctrl + L: clear screen
- Ctrl + A/E: beginning/end of line
- Alt + F/B: forward/back one word
Screen
- -S <session name> Start session with name
- -e <program to start>
- -r Attach
- -R Attach if possible, otherwise start new
- -ls List sessions
- -x <session name> Attach to open session
- -d (-r) Detach the elsewhere running screen (and reattach here)
- -D (-r) Detach and logout remote (and reattach here)
- -D -RR Do whatever is needed to get a screen session
^A followed by
- d detach
- c new window
- A rename window
- w list windows
- " selectable window list
- 0-9 select window 0-9
- s split (new region)
- TAB change region focus
- Q make current region only one visible
- X kill region
- ^\ kill everything (including all processes)!
- M monitor window for activity
- _ monitor window for inactivity
- a send ^A to session
- p/n previous/next window
- N show window name
- A set window name
- k kill current window
- [ copy (space to mark, Esc to exit, / or ? for search, Ctrl + S/R for incremental, "ignorecase yes")
- ] paste
- ? list all possible commands
- : screen command prompt
- :sessionname <name>
- :multiuser on
- :aclchg <user> +r "#" Read perms on all windows
- :acldel <user>
Useful apps
Squid:
- squidtaild
- squidclient
- srg
- squidview
- calamaris
- sarg
Highlighter:
- ccze
Cleaning useless Debian items:
- localepurge
- deborphan
- debfoster
Monitoring:
- iptraf
- bmon
- atsar
- sysstat
- nmon
- mytop
Benchmarking:
- dbench
WebDAV:
- cadaver
- nd
HDD/ACPI monitoring:
- acpitail
- hddtemp
- fancontrol
- lm-sensors
- mbmon
- yacpi
Redirection
- stdout and/or stderr:
i>&j - send file descriptor i to j 1>&2 - send stdout to stderr 2>&1 - send stderr to stdout foo > bar 2>&1 - send stdout to bar, and stdout & stderr to terminal command >&file - send stdout AND stderr to file command &>file - send stdout AND stderr to file (Bash v4) foo 2>&1 | bar - pipe stdout AND stderr into bar command1 2> file1 - send stderr to file1
Counting files
find . -type f ¦ wc -l
find
From Code Coffee:
find defaults to current directory.
find / -name 'program.c' find /home/david -name 'index*' find /home/david -iname 'index*' - case-insensitive find /mp3collection -name '*.mp3' -size -5000k - less than 5MB find / -size +10000k - greater than 10M find /home/david -amin -10 -name '*.c' - access, minutes find /home/david -atime -2 -name '*.c' - access, 24-hour periods find /home/david -mmin -10 -name '*.c' - modified find /home/david -mtime -2 -name '*.c' find / -mount -name 'win*' - one file system find /mp3-collection -name 'Metallica*' -and -size +10000k - and find /mp3-collection -size +10000k ! -name "Metallica*" - not find /mp3-collection -name 'Metallica*' -or -size +10000k - or find / - name 'Metallica*' -exec ls -l {\}\ \; - execute command: substitution: {\}\ command end: \;
Recording the screen
Recording:
script -t 2> tutorial.timing -a tutorial.session
Playback:
scriptreplay tutorial.timing tutorial.session
Prevent screen blanking
setterm -blank 0
rsync
a archive mode v verbose h human-readable W whole file mode (don't use rsync algo) d transfer directories without recursing n dry run z compress X keep extended attributes P --partial --progress -e ssh use ssh with user@host:path
For local file comparisons:
rsync -avnhW "Desktop/My Passport/Mitsubishi090109_10" "/Volumes/My Passport"
Windows drive backup:
sudo rsync -avhWd --progress --ignore-existing --exclude='System Volume Information' --exclude='$RECYCLE.BIN' sdb1/ Dagron/
NOTE: Use sudo to ensure directory times are transferred. Will fail to transfer time of root directory.
tcpdump with greater snarf size
tcpdump -s 1500 -w out-file.pcap <expression>
Scripts
- lesspipe.sh
Use in conjuction with environment variables:
export LESS=-R
export LESSOPEN="|/usr/local/bin/lesspipe.sh %s"
Script:
#!/bin/sh
case "$1" in
*.log.[0-9]*.gz) gunzip -c $1 2>/dev/null | ccze -A
;;
*.log|*.log.[0-9]*) cat $1 | ccze -A
;;
*.gz) gunzip -c $1 2>/dev/null
;;
esac
- Nice terminal colours:
export PAGER='less -R -s -i'
# Blink
export LESS_TERMCAP_mb=$'\E[05;31m'
# Bold
export LESS_TERMCAP_md=$'\E[01;33m'
# End above modes
export LESS_TERMCAP_me=$'\E[0m'
# End standout
export LESS_TERMCAP_se=$'\E[0m'
# Stand out
export LESS_TERMCAP_so=$'\E[00;44;33m'
# End underline
export LESS_TERMCAP_ue=$'\E[0m'
# Underline
export LESS_TERMCAP_us=$'\E[04;32m'
- Log file viewers:
sudo tail -F -n 50 --max-unchanged-stats=5 /var/log/apache2/access.log | ccze sudo tail -F --max-unchanged-stats=5 -n 50 /var/log/squid/access.log | ccze -C sudo tail -F --max-unchanged-stats=5 -n 100000 /var/log/auth.log 2> /dev/null | grep --line-buffered -E "(sshd).*(Accepted)" | ccze sudo watch -d -t 'netstat -p -t | grep ESTABLISHED'
AWStats
- Correct permissions for generated statistics:
su -c "/usr/lib/cgi-bin/awstats.pl -update -config=<config> -LogFile=<log>" www-data
SNMP
- Gateway blocks BiPAC 7800N (RX, corrected, uncorrected, TX):
snmpget -v 2c -c public gateway .1.3.6.1.2.1.10.94.1.1.11.1.1.3 .1.3.6.1.2.1.10.94.1.1.11.1.3.3 .1.3.6.1.2.1.10.94.1.1.11.1.4.3 .1.3.6.1.2.1.10.94.1.1.11.1.2.3
RRDTool Spike Removal
- Traffic in/out:
su -c "/home/balint/bin/killspike2 traffic_in 1000000 gateway_traffic_in_32.rrd" www-data
- Gateway
su -c "/home/balint/bin/killspike2 snmp_data 1000 gateway_snmp_data_41.rrd" www-data su -c "/home/balint/bin/killspike2 snmp_data 1000 gateway_snmp_data_42.rrd" www-data su -c "/home/balint/bin/killspike2 snmp_data 1000 gateway_snmp_data_43.rrd" www-data su -c "/home/balint/bin/killspike2 snmp_data 1000 gateway_snmp_data_44.rrd" www-data
- Bug with Cacti: moving elements in graph template causes connection between actual graph and data source for each element to become corrupt, so necessary to re-edit graph item and re-select correct data source for appropriate graph elements.
diff
diff -u -r --strip-trailing-cr --unidirectional-new-file -X diff.ignores <orig> <new> > <patch>
diff.ignores:
Makefile *.o *.cmd *.ko compat_autoconf.h .* *.bk *.orig *.symvers *.mod.c *.order *.mk
HDD Recovery Resources
- To enumerate all partitions on all connected devices:
fdisk -l
- For GRUB version <= 1, after editing /boot/grub/device.map and /boot/grub/menu.list (this is updated by update-grub):
grub-install <device>
- Remember to mkswap on new linux-swap partition before swapon'.
- How to install GRUB via grub: [1]
- pivot_root for invoking older version of grub on recovered file system: [2]
- gparted will automatically call relevant file system resize programs (e.g. resize2fs)
- parted commands: [3]
- Calculating size for mkpart command in parted when creating new partition: [4]
- Ext2/3 file system information, and mounting using alternate superblock: [7] [8] [9] [10]
- May need to change order of arguments supplied to mount in order that it honours sb option, otherwise might try using usual superblock. Check output of dmesg or kern.log to see what file system driver reports.
Notes on distributions/environments
General
- Architecture mismatch (e.g. booting with 32-bit kernel, but loading 64-bit installation, or vice versa) binfmt-464c
Linux Mint
- MATE vs Cinnamon: [11]
- MATE (fork from GNOME 2)
- Cinnamon (fork from GNOME 3)
- LMDE 201204
Live USB
- Creating separate casper-rw partition
- Use noprompt boot argument to disable USB ejection prompt at shutdown/reboot: list of kernel live-boot arguments
- Use of live-media-path and ignore_uuid (presumably those in relevant files in .disk directory) [14]
Additional resources required by packages
- Google Earth
- Install additional fonts to correct default GUI font
apt-get install ttf-mscorefonts-install
git & ssh
~/.ssh/config
~/.git/config