Computer Notes/One Liners
From Rob86Wiki
(Redirected from Tricks)
|
Contents |
Platform: Windows
Command Line
- Convert *.mkv files in folder B:\Videos to *.mp4 files in current folder[1]:
- for /r "B:\Videos" %i in (*.mkv) do ffmpeg -i "%i" "%~ni.mp4"
- Commands for ripping Dragon Ball DVDs:
- for %i in (t*.mkv) do mkvmerge.exe -o _%i --default-track 2:no --default-track 3:yes --default-track 5:yes -a 2,3 -d 1 -s 5 %i --track-order 0:1,0:3,0:2,0:5
- for %i in (t*.mkv) do mkvmerge.exe -o _%i --default-track 2:no --default-track 3:yes --default-track 4:yes -a 2,3 -d 1 -s 4 %i --track-order 0:1,0:3,0:2,0:4
- grep TimeStart source.txt |sed -ne "1~5p" |sed -e "1d" |cut -d" " -f7 |tr "\n" ","
PuTTY[2]
- Window
- Lines of scrollback: 2000000
- Check only:
- Display scrollbar
- Reset scrollback on keypress
- Push erased text into scrollback
- Window/Appearance
- Font quality: ClearType
- Window/Translation
- Character set: UTF-8
- Use Unicode line drawing code points
- Connection
- Seconds between keepalives: 25
- Connection/Data
- Terminal-type string: xterm-color
- Connection/SSH
- Enable compression
Videos to DVD
- Install:
- AVStoDVD 2.4.1
- Configure AVStoDVD Labels.ini:
- TitleFontSize: 30
- ThumbsFontSize: 15
- Configure AVStoDVD Preferences:
- DVD Output/Assets Path
- DVD Video Standard
- Create DVD ISO:
- Set DVD Label in "Settings".
- Add files to Source Titles.
- Set Output to "ISO UDF Image"
- Create DVD Menu:
- Still Pictures.
- Set relevant aspect ratio.
- Text Based Titles.
- 5 titles per page.
- Enable "Play All" Button.
- Start.
- If ISO is greater than 4450 MB:
- Use DVD Shrink once or twice on the ISO.
Platform: Linux
Command Line
- ip a
- sshfs
- knockd
- ssh-copy-id
- strings
- at
- service iptables save
- netstat -tulpn
- mutt
- alternatives --config
- /etc/aliases
- grep --color
- shopt -s histappend
Flush DNS Cache
- service nscd reload
- This fixed the weird problem where ping couldn't resolve hostnames but dig/host/wget could.
Dump HTTP Payload
- tcpdump -i eth0 -s 0 -A 'tcp dst port 80 and (tcp[((tcp[12:1] & 0xf0) >> 2):4] = 0x504f5354)'
Convert TIFs to JPGs
- mkdir convert &>/dev/null; for file in $(ls *.tif); do file_new="./convert/$(echo $file |sed "s/tif$/jpg/g")"; convert $file $file_new; exiftool -tagsFromFile $file $file_new; done
Find Duplicate Files
- data=$(find . -type f -exec cksum {} \; |sort); data_uniq=$(echo -e "$data" |cut -d" " -f1 |uniq -d); for line in $(echo -e "$data_uniq"); do echo; echo -e "$data" |grep $line; done
Bash Colors[3]
txtblk='\e[0;30m' # Black - Regular txtred='\e[0;31m' # Red txtgrn='\e[0;32m' # Green txtylw='\e[0;33m' # Yellow txtblu='\e[0;34m' # Blue txtpur='\e[0;35m' # Purple txtcyn='\e[0;36m' # Cyan txtwht='\e[0;37m' # White bldblk='\e[1;30m' # Black - Bold bldred='\e[1;31m' # Red bldgrn='\e[1;32m' # Green bldylw='\e[1;33m' # Yellow bldblu='\e[1;34m' # Blue bldpur='\e[1;35m' # Purple bldcyn='\e[1;36m' # Cyan bldwht='\e[1;37m' # White unkblk='\e[4;30m' # Black - Underline undred='\e[4;31m' # Red undgrn='\e[4;32m' # Green undylw='\e[4;33m' # Yellow undblu='\e[4;34m' # Blue undpur='\e[4;35m' # Purple undcyn='\e[4;36m' # Cyan undwht='\e[4;37m' # White bakblk='\e[40m' # Black - Background bakred='\e[41m' # Red badgrn='\e[42m' # Green bakylw='\e[43m' # Yellow bakblu='\e[44m' # Blue bakpur='\e[45m' # Purple bakcyn='\e[46m' # Cyan bakwht='\e[47m' # White txtrst='\e[0m' # Text Reset
MD
Replace RAID Disk
In this example, the scenario is /dev/sdd will be replaced with a larger capacity drive. NOTE: To see drive sizes: cat /proc/partitions |grep sd.1$
- fdisk drive and partition as fd (Linux raid auto)
- To get current state: mdadm --detail /dev/md0
- Add the newly formatted partition to the array: mdadm /dev/md0 -a /dev/sdd1
- Array will rebuild in the background: watch -n1 sudo mdadm --detail /dev/md0
Add RAID Disk
The scenario is that a new disk (5) will be added to the array, the device is /dev/sde.
- fdisk drive and partition as fd (make sure all devices are the same type with fdisk -l)
- Add the newly formatted partition to the array: mdadm /dev/md0 -a /dev/sdd1 (this will add it as a hot spare)
- Find out the current number of active disks: mdadm --detail /dev/md0 (Active Devices)
- Increment the number of active devices by one: mdadm --grow -n5 /dev/md0 (was 4, now 5) (with 5x1TB drives, this took 24 hours)
- Update /etc/mdadm.conf by replacing the ARRAY line with the output of mdadm -Es
Grow RAID Device
NOTE: This section assumes you have the following drive layout: MD (linux software raid) -> LUKS (linux software full disk encryption encompassing the entire MD device) -> LVM (sitting directly on top of LUKS/dm-crypt).
After increasing the size of all hard disks, or adding another hard disk, do the following. The encrypted file system name was obtained from PV Name (/dev/mapper/luks-[...]) in /usr/sbin/pvdisplay
- Grow the multi-disk device: mdadm --grow --size=max /dev/md0 (not necessary but doesn't hurt if md0 is already max)
- Grow the encrypted file system: cryptsetup resize luks-5c9f9294-5a3c-4e5a-8180-f00821fecc46
- Resize the LVM PV: pvresize /dev/mapper/luks-5c9f9294-5a3c-4e5a-8180-f00821fecc46
- Run vgdisplay to verify the new VG Size, and get the current Free PE. In this example you see: Free PE / Size 95 / 2.97 GB
- Expand the home logical volume: lvresize -l +95 /dev/vg0/home
- Verify vgdisplay has 0 free PE, and lvdisplay shows /dev/vg0/home with the new size
- Finally, expand the /home file system: resize2fs /dev/mapper/vg0-home (resizing from 3 TB to 4 TB took about an hour)
Platform: SunOS
Non-Truncated PS
- /usr/ucb/ps auxwww
Platform: VMware ESX 3.5
Kill VM with vmid
- killvm() { for a in "$@"; do /usr/lib/vmware/bin/vmkload_app -k 9 $(perl -ne 'print if s/.*vm\.(\d*).*/\1/' /proc/vmware/vm/$a/cpu/status); done; }
Get VMX path from vmid
- function getvmx() { sed 's/.*cfgFile="\([^"]*\)".*/\1/' /proc/vmware/vm/$1/names ;}
Language: Python
Sorting a list by string length
mylist.sort(cmp=lambda x,y: len(x)-len(y))
Getting # of CPUs
- os.sysconf('SC_NPROCESSORS_ONLN')
Dict string substitution[4]
LIGHT_MESSAGES = {
'English': "There are %(number_of_lights)s lights.",
'Pirate': "Arr! There be %(number_of_lights)s lights."
}
def lights_message(language, number_of_lights):
"""Return a language-appropriate string reporting the light count."""
return LIGHT_MESSAGES[language] % locals()
Misc
- urls = [line.rstrip('\n\r') for line in f.readlines()]
- self.COLS = curses.tigetnum('cols')
- self.LINES = curses.tigetnum('lines')
- struct.unpack('hh',fcntl.ioctl(0,termios.TIOCGWINSZ,'1234'))
- return True if self.result[0] == 0 else False #python >= 2.5
- return (self.result[0] == 0 and [True] or [False])[0] #python < 2.5
VIM
vimrc
- colorscheme ron
- set tabstop=4
- set shiftwidth=4
- set expandtab
Misc
- Pretty XML:
- %!xmllint --format -
- Revert to last save:
- :e!
- Tabs to spaces:
- retab
References
- ↑ http://stackoverflow.com/questions/659647/how-to-get-folder-path-from-file-path-with-cmd
- ↑ http://dag.wieers.com/blog/content/improving-putty-settings-on-windows
- ↑ https://wiki.archlinux.org/index.php/Color_Bash_Prompt
- ↑ http://stackoverflow.com/questions/56011/single-quotes-vs-double-quotes-in-python