Linux Tools

From Healthcare Robotics Wiki
Jump to: navigation, search

Linux Tutorials

vim tips and tricks


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/

Then secure shell copy to another host as authorized_keys

$ scp ~/.ssh/ <machine name>:~/.ssh/authorized_keys

Additional keys can be named authorized_keys2 or put below the existing keys in authorized_keys or authorized_keys2.


handy tool to crop images etc.

  1. 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.

combining, extracting pages etc. from PDF documents

  • sudo apt-get install gs pdftk sam2p
  • Extract pages from a pdf:
  • Combine multiple pdfs:
    • gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=combinedpdf.pdf -dBATCH *.pdf
  • Reduce the file size of a 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

The find command is pretty nifty:

  1. find all directories whose name does not contain svn: find . ! -path "*.svn*" -type d
  2. remove .svn folders, e.g. after copying a directory which is a local copy of a subversion repository: rm -rvf `find . -name "*.svn"`
  3. recursively remove all the .pycs: alias rmpyc='rm -vf *.pyc; rm -vf `find . -name *.pyc`'
  4. remove the pesky .pycs from the repository: svn rm `find . -name "*.pyc"`
  5. list all pkl files with the word grasp but not the word choose: find . -name '*grasp*.pkl' -and ! -name '*choose*.pkl'
  6. avoid initial ./ in file name: find * -name "pull_trajec*.pkl"

So is sed:

  1. 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"`
  2. look at the script in gt-ros-pkg for some more examples of using sed.

And rename:

  1. Rename JPG to jpg for all the files in a folder: rename 's/JPG/jpg/' *

Use netcat to test ports

  1. nc -l 1234
  2. nc 1234

bash scripting

  1. padding zeros before file or directory names: mkdir `printf "%03d %04d" 5 6`
  2. counters in bash scripts: N=1 ... let N=$N+1
  3. listing only the directory names: ls */ -d

udev for persistent device naming

Steps in brief

  1. Identify device name (i.e. /dev/ttyUSB0, /dev/ttyACM0, etc):
    1. ls /dev without and with device plugged in.
  2. Get device information using udevadm (similar info can also be gained via lsusb):
    1. sudo udevadm info --name=/dev/DEVICE_OF_INTEREST --query=property
  3. Create a udev .rules file in /etc/udev/rules.d/.
    1. Files are evaluated in order by number, low numbers first.
    2. Start with 80-[your_device_name].rules (should run after system rules)
    3. Change number if this doesn't seem to work. Earlier rules may interfere.
    4. Each file can have multiple rules, but each rule must be it's own, single line.
    5. Specify the device uniquely, based on data from the udevadm info command above
    6. Specify the action for that device (add symlink, set permissions/owner, etc.)
  4. Restart udev (and check that your rule applied properly
    1. sudo /etc/init.d/udev restart

Sample files

An example (80-skin.rules), used to assign consistent device names to Arduino devices on PR2's for fabric-based skin:

SUBSYSTEMS=="usb", ACTION=="add", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", ATTRS{serial}=="AD02CTDZ", MODE="666", SYMLINK+="robot/skin_arduino_upperarm"
SUBSYSTEMS=="usb", ACTION=="add", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", ATTRS{serial}=="AD02CP1N", MODE="666", SYMLINK+="robot/skin_arduino_forearm"

An older sample file (10-ROBOT.rules) used on EL-E. Adds consistently named symlinks, runs drivers, sets permissions:

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"

More information

Linux & Mac Hardware

  • fix mac function keys in ubuntu: link