Difference between revisions of "Linux Tools"
From Healthcare Robotics Wiki
Advaitjain (Talk | contribs) m (→combining, extracting pages etc. from PDF documents) |
Advaitjain (Talk | contribs) (→combining, extracting pages etc. from PDF documents) |
||
| (One intermediate revision by one user not shown) | |||
| Line 1: | Line 1: | ||
| + | == Linux Tutorials == | ||
| + | * For beginners, skip tutorial 7: http://www.ee.surrey.ac.uk/Teaching/Unix/ | ||
== vim tips and tricks == | == vim tips and tricks == | ||
* http://www.cs.swarthmore.edu/help/vim/home.html | * http://www.cs.swarthmore.edu/help/vim/home.html | ||
| Line 39: | Line 41: | ||
*** One of the comments mentioned dropping the -dPDFSETTINGS=/screen option. This worked for Advait. | *** One of the comments mentioned dropping the -dPDFSETTINGS=/screen option. This worked for Advait. | ||
** gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf | ** gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf | ||
| + | * converting pdf to grayscale: | ||
| + | ** gs -sOutputFile=gray.pdf -sDEVICE=pdfwrite -sColorConversionStrategy=Gray -dProcessColorModel=/DeviceGray -dCompatibilityLevel=1.4 -dNOPAUSE -dBATCH everyday_mechanics.pdf | ||
== command line tools: find, sed, rename == | == command line tools: find, sed, rename == | ||
Latest revision as of 20:08, 23 July 2012
Contents |
[edit] Linux Tutorials
- For beginners, skip tutorial 7: http://www.ee.surrey.ac.uk/Teaching/Unix/
[edit] vim tips and tricks
[edit] ssh-keygen
To be able to ssh to another machine without needing to type your passwd:
Generate keys: $ ssh-keygen -t rsa -b 1024
Use the default file name and empty pass phrase for password less authentication. This will generate keys in
$ .ssh/id_rsa.pub
Then secure shell copy to another host as authorized_keys
$ scp ~/.ssh/id_rsa.pub <machine name>:~/.ssh/authorized_keys
Instructions copied from: http://pr.willowgarage.com/wiki/GB_ssh-keygen
Additional keys can be named authorized_keys2 or put below the existing keys in authorized_keys or authorized_keys2.
[edit] Imagemagick
handy tool to crop images etc.
- convert -crop 700x500+550+200 8.png 8_cropped.png - crops an image to a size of 700x500 with an offset of 550, 200 from the top left.
[edit] combining, extracting pages etc. from PDF documents
- sudo apt-get install gs pdftk sam2p
- Extract pages from a pdf:
- http://www.linuxjournal.com/content/tech-tip-extract-pages-pdf
- pdftk A=full_document.pdf cat A1-7 output first_seven_pages.pdf
- Combine multiple pdfs:
- gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=combinedpdf.pdf -dBATCH *.pdf
- Reduce the file size of a pdf:
- http://www.ubuntugeek.com/ubuntu-tiphowto-reduce-adobe-acrobat-file-size-from-command-line.html
- Advait found that the vanilla command on the website degraded the image quality by a lot.
- One of the comments mentioned dropping the -dPDFSETTINGS=/screen option. This worked for Advait.
- gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf
- converting pdf to grayscale:
- gs -sOutputFile=gray.pdf -sDEVICE=pdfwrite -sColorConversionStrategy=Gray -dProcessColorModel=/DeviceGray -dCompatibilityLevel=1.4 -dNOPAUSE -dBATCH everyday_mechanics.pdf
[edit] command line tools: find, sed, rename
The find command is pretty nifty:
- find all directories whose name does not contain svn: find . ! -path "*.svn*" -type d
- remove .svn folders, e.g. after copying a directory which is a local copy of a subversion repository: rm -rvf `find . -name "*.svn"`
- recursively remove all the .pycs: alias rmpyc='rm -vf *.pyc; rm -vf `find . -name *.pyc`'
- remove the pesky .pycs from the repository: svn rm `find . -name "*.pyc"`
- list all pkl files with the word grasp but not the word choose: find . -name '*grasp*.pkl' -and ! -name '*choose*.pkl'
- avoid initial ./ in file name: find * -name "pull_trajec*.pkl"
So is sed:
- replace update_path with load_manifest. (-i is doing an in-place replace, Advait believes): sed -i 's/update_path/load_manifest/' `find . -name "*.py"`
- look at the insert_license.sh script in gt-ros-pkg for some more examples of using sed.
And rename:
- Rename JPG to jpg for all the files in a folder: rename 's/JPG/jpg/' *
Use netcat to test ports
- nc -l 1234
- nc 127.0.0.1 1234
[edit] bash scripting
- padding zeros before file or directory names: mkdir `printf "%03d %04d" 5 6`
- counters in bash scripts: N=1 ... let N=$N+1
- listing only the directory names: ls */ -d
- http://tldp.org/LDP/abs/html/refcards.html
[edit] udev for persistent device naming
[edit] Steps in brief
- sudo lsusb -v >pre # with device being unplugged
- sudo lsusb -v >post # with device being plugged in
- diff pre post (or use meld for a nicer graphical tool for comparing files) # you can read the Serial Number on the line "iSerial" etc.
- Now edit the udev rules in /etc/udev/rules.d/10-ROBOT.rules
- sudo /etc/init.d/udev restart
- ls /dev/robot -- to check whether the devices appear.
[edit] Sample file
Here is a sample 10-ROBOT.rules file that we use on our robot.
BUS=="usb", KERNEL=="ttyUSB*", SYSFS{idVendor}=="0403", SYSFS{idProduct}=="6001", SYSFS{serial}=="A7003N1b", SYMLINK+="robot/servo0"
BUS=="usb", KERNEL=="ttyUSB*", SYSFS{idVendor}=="0403", SYSFS{idProduct}=="6001", SYSFS{serial}=="ftDXR6FS", SYMLINK+="robot/zenither"
SUBSYSTEMS=="usb", KERNEL=="ttyACM*", PROGRAM="/home/advait/ros/pkgs/ros-pkg-trunk/stacks/laser_drivers/hokuyo_node/bin/getID /dev/ttyACM%n q", ATTRS{manufacturer}=="Hokuyo Data Flex for USB", ATTRS{product}=="URG-Series USB Driver", SYMLINK+="robot/hokuyo_%c"
BUS=="usb", SYSFS{idVendor}=="0403", SYSFS{idProduct}=="e729", SYSFS{serial}=="00000215", SYMLINK+="robot/segway_front"
BUS=="usb", SYSFS{idVendor}=="0403", SYSFS{idProduct}=="e729", SYSFS{serial}=="00000201", SYMLINK+="robot/segway_back"
SUBSYSTEM!="usb", GOTO="robot_rules_end"
ACTION!="add", GOTO="robot_rules_end"
ATTRS{idVendor}=="0403", ATTRS{idProduct}=="e729", MODE="0660", GROUP="plugdev"
LABEL="robot_rules_end"
[edit] More information
- http://www.reactivated.net/writing_udev_rules.html#why
- detailed info about writing udev rules: http://www.reactivated.net/writing_udev_rules.html
[edit] Linux & Mac Hardware
- fix mac function keys in ubuntu: link