[back to my home page]

This page contains some useful Linux commands and scripts that I often use.

Some of the individual commands/tricks that are below I found in various places in the Internet, such as mailing lists, blogs, etc. So please don't be suprised if you see them elswere. I am putting these things below for my pure convenience, and also with hope that they will be useful for people who use Linux in their research work.

GTK layout

By default, Eclipse IDE looks awful in Linux, because a lot of space is wasted between menu options and most graphical elements, such as buttons, are disproportionately large. The solution that I googled once is as follows:
  1. First, you put this file into your home directory.
  2. Your Eclipse profile has to take settings from the system, e.g., in Eclipse 3.6 (Helios) it is sufficient if Window->Preferences->General->Appearance->Current Theme is set to Default.
  3. gtk-chtheme is a useful tool especially when fluxbox is used
With this, Eclipse and other applications have a nice compact look and feel. First tested on Ubuntu 11.10.

Java in Ubuntu

This can be tricky. A good way to see the current Java that is used in the system is to use this command:
update-alternatives --verbose --query java
If a different version should be made default, this could be helpful:
sudo update-alternatives --install /usr/bin/java java /opt/jdk1.7.0_03/bin/java 1701
The same should be repeated for javac:
sudo update-alternatives --install /usr/bin/javac javac /opt/jdk1.7.0_03/bin/javac 1701
JAVA_HOME could be also set in /etc/alternatives or at least in ~/.bashrc.

Java plugin for Firefox and Chrome

It is sufficient to create the following symbolic link: /usr/lib/mozilla/plugins/libnpjp2.so -> /opt/jdk1.7.0_13/jre/lib/i386/libnpjp2.so. Also it may be useful to uninstall the icedtea java plugin.

Linux command line tools

  1. Sorting the text file with several columns of text or numbers. Let's say that we want to sort on the first column only. This could be done using:
    sort --stable -k1,1 file_name.txt
    If sorting numbers instead of text, -n should be added:
    sort -n --stable -k1,1 file_name.txt
  2. Fixing bash completion in Ubuntu 11.10. Open sudo vi /etc/bash_completion and in line 1587 replace -o defaults with -o filenames
  3. List open files for given process PID
    ls -l /proc/PID/fd
    or
    lsof -p PID
    lsof -p `pgrep firefox`
  4. find a string in files
    find . -type f -name "*.txt" -exec grep "text to find" /dev/null {} \;
  5. find a string in files; print line number of every match
    find . -type f -name "*.m" -exec grep -Hn --color='auto' "text to find" /dev/null {} \;
  6. run ls and print non-empty files
    ls -l | awk '{if ($5 != 0) print $9}'
  7. display UUID of every partition
    sudo blkid -o full -s UUID
  8. /etc/fstab line to mount fat32 partitions as a particular user; sudo mount -a remounts all partitions; see above for a command that displays UUIDs
    UUID=1EC7-98B6 /media/BACKUPFAT32 vfat users,rw,auto,umask=007,uid=1001,gid=1001 0 0
  9. reduce margins
    pdfcrop --margins 40 document.pdf
  10. multiple slides per page using pdfjam
    pdfjam --nup 2x3 --no-landscape --trim '-1cm -1cm -1cm -1cm' --frame true presentation.pdf
    pdfjam --nup 2x2 --landscape --trim '-1cm -1cm -1cm -1cm' --frame true presentation.pdf
  11. Display filename and match in grep
    grep -Hn 'pattern' file*.txt
  12. Print non-ASCII characters
    grep --color='auto' -P -n "[^[:ascii:]]" file.txt
  13. Show versions supported by an *.so library
    readelf -Wa /usr/lib64/libstdc++.so.6 | grep GLIBCXX_
    or a better option is to use
    strings /usr/lib64/libstdc++.so.6 | grep LIBCXX
  14. Download entire web-site without external links
    wget --recursive --no-clobber --page-requisites --html-extension --convert-links --restrict-file-names=windows --no-host-directories --domains pomdp.org --no-parent pomdp.org
    wget --mirror pomdp.org
  15. Check how long processes were running
    ps -eo pid,cmd,etime
  16. Extract all of the bib entries which are mentioned in a given .aux file
    sudo apt-get install bibtool
    bibtool -x document.aux -o new.bib
  17. Interleave lines from two or more files
    paste -d '\n' file1 file2 file3
  18. Information about CPU:
    lscpu
  19. Disable touchpad:
    synclient TouchpadOff=1
  20. Search for a pattern in pdf files:
    find /path -name '*.pdf' -exec sh -c 'pdftotext "{}" - | grep --with-filename --label="{}" --color "your pattern"' \;

svn

  1. Add a directory, while ignoring all of the files it contains:
    svn add --depth=empty dir-name
  2. svn diff for specific revisions
    svn diff -r num1:num2 file.txt
  3. svn update to a specific revision
    svn update -r REVNUMBER
  4. change repository path
    svn switch --relocate svn+ssh://old-repo https://new-repo .

bash

  1. A nice prompt for bash: PS1="\[\033[32m\][\h:\w]\[\033[0m\]\n\[\033[1;36m\]\u\[\033[1;31m\]: \[\033[0m\]"

Gimp

  1. How to brighten white elements & darken black and grey elements in GIMP
    Click "Tools" followed by "Color Tools" and "Levels." Drag the slides to adjust the image.
  2. Converting coulour images to B&W
    Select Image -> Mode -> Grayscale

KDE

  1. How to get rid of single click in KDE applications? Open ~/.kde/share/config/kdeglobals and add:
  2. [KDE]
    SingleClick=false
  3. ...

Security

  1. Disable root access in ssh. Set PermitRootLogin no and LoginGraceTime 60 in /etc/ssh/sshd_config.
  2. gufw - user friendy and simple to use GUI interface to Linux firewall
  3. Use iptables to limit to 3 attempts per minute:
    iptables -I INPUT -p tcp --dport 22 -i eth0 -m state --state NEW -m recent --set
    iptables -I INPUT -p tcp --dport 22 -i eth0 -m state --state NEW -m recent --update --seconds 60 --hitcount 4 -j DROP


screen

Key Action
Ctrl+a c new window
Ctrl+a n next window
Ctrl+a p previous window
Ctrl+a " select window from list
Ctrl+a Ctrl+a previous window viewed
   
Ctrl+a S split terminal horizontally into regions
Ctrl+a | split terminal vertically into regions
Ctrl+a :resize resize region
Ctrl+a :fit fit screen size to new terminal size
Ctrl+a :remove remove region
Ctrl+a tab Move to next region
   
Ctrl+a d detach screen from terminal
Ctrl+a A set window title
Ctrl+a x lock session
Ctrl+a [ enter scrollback/copy mode
Ctrl+a ] paste buffer
Ctrl+a > write paste buffer to file
Ctrl+a < read paste buffer from file
   
Ctrl+a ? show key bindings/command names
Ctrl+a : goto screen command prompt

VPN using Cisco anyconnect client in Ubuntu 12.04

Create a file called:

GlobalSignOrganizationValidationCA-G2.pem

in

/opt/.cisco/certificates/ca/

Within that file paste the PEM from :

http://www.globalsign.com/support/root-certificate/root-globalsign.php

Make sure your editor doesn't add extra characters and it is formatted properly.

Then restart the Anyconnect Client and attempt to connect.

OpenOffice

  1. Setting tab stops and indents
    The horizontal ruler shows both the default tab stops and any that you have defined. To set the measurement unit and the spacing of default tab stops, go to Tools -> Options -> OpenOffice.org Writer -> General.

PDF Files

  1. xournal for annotations, allows adding images

Latex

  1. Math mode documentation

Latex to OpenOffice

  1. Install tex4ht
  2. latex file.tex
  3. bibtex file.aux
  4. mk4ht oolatex file.tex (you may need to do this more than once)
  5. After 4) is done, file.odt should exist.
The above procedure was found here: source

Latex to HTML

  1. latex2html -dir html -split 0 file.tex
  2. a much better conversion can be obtained using
    mk4ht htlatex file.tex
    (bibtex has to be executed before mk4ht)
  3. fn-in is required to have footnotes in the main document
    htlatex file.tex "xhtml,fn-in"

HTML to PDF

  1. wkhtmltopdf http://www.page.html output.pdf

Encrypted USB drive in Ubuntu

  1. sudo apt-get install cryptsetup
  2. Follow this link http://www.liberiangeek.net/2012/04/encrypt-your-external-usb-drives-in-ubuntu-12-04-precise-pangolin and use "disk utility". The process is trivial with this GUI application.

Brightness Control in Ubuntu 12.04

  1. Create a new file: /usr/share/X11/xorg.conf.d/10-nvidia-brightness.conf Don't edit /etc/X11/org.conf
  2. Paste the following content to /usr/share/X11/xorg.conf.d/10-nvidia-brightness.conf:
    Section "Device"
    Identifier "Default Device"
    Driver "nvidia"
    VendorName "NVIDIA Corporation"
    BoardName "Quadro K1000M"
    Option "RegistryDwords" "EnableBrightnessControl=1"
    EndSection
  3. Reboot the system and brightness control should work. It works fine on my Lenovo Thinkpad running Fluxbox and xfce4-power-manager
  4. A word of caution: when you copy the above content to the file on your system, make sure that all characters are pure ASCII characters. If the browser will copy the text with some unicode trash, your X system won't start and you will need to fix the file using failsafe mode or connecting via ssh from another computer assuming the ssh server is running.

Network

  1. Add a second IP address to a network interface that is already in use
    sudo ifconfig eth0:1 192.168.1.1 netmask 255.255.255.0 up

When DNS servers of your ISP fail

This is a simple way to connect to the Internet (in Ubuntu 12.04) when ISP DNS servers fail.
  1. sudo vim /etc/resolvconf/resolv.conf.d/head or sudo vim /etc/resolvconf/resolv.conf.d/tail
  2. add Google open dns to that file: nameserver 8.8.8.8 and/or any other DNS server that is accessible
  3. run: sudo resolvconf -u
  4. you may need to run also: sudo service network-manager restart
  5. Another way is to use Network Manager and define static DNS server for your connection (go to edit connection). cat /var/run/nm-dns-dnsmasq.conf shows which servers are used by the local dnsmasq dns server; servers defined in the Network Manager should show up here

Hybernate and Lock the Screen using Command Line

  1. Make pm-suspend executable using sudo without password
  2. in /etc/sudores, at the end, add <username> ALL = (ALL) NOPASSWD: /usr/sbin/pm-suspend
  3. after that the following command sudo pm-suspend && xscreensaver-command -lock does hybernation and locks the screen

Install Sun Grid Engine on a Single Local Machine

  1. sudo apt-get install gridengine-master gridengine-exec gridengine-client gridengine-qmon gridengine-common
  2. select automatic configuration and choose cell name and the host name; your local host name has to be defined in /etc/hosts; ping to localhost or any other local name should print the same name as the one given through the command line to ping (it cannot be a different name); that name has to much also the hostname of your local host
  3. Initializing cluster with the following parameters:
    => SGE_ROOT: /var/lib/gridengine
    => SGE_CELL: zubrcell
    => Spool directory: /var/spool/gridengine/spooldb
    => Initial manager user: sgeadmin
    Initializing spool (/var/spool/gridengine/spooldb)
    Initializing global configuration based on /usr/share/gridengine/default-configuration
    Initializing complexes based on /usr/share/gridengine/centry
    Initializing usersets based on /usr/share/gridengine/usersets
    Adding user sgeadmin as a manager
  4. ssh -X localhost and then sudo qmon and do: define a queue (add your local host to the host list and allowed user sets), in host configuration add the submission host, add users to user sets
  5. you can restart processes using: sudo /etc/init.d/gridengine-exec restart and sudo /etc/init.d/gridengine-master restart
  6. after that you can submit your job: echo "ls -l > /tmp/test.txt" | qsub
  7. qstat -s z wil show the recently completed jobs

Overall Sun Grid Engine works nice, but it is annoying because its qsub command is not compatible with other implementations.

Digital Cameras

  1. Download all photos: (1) go to the directory where you wish to have your files to be downloaded, (2) execute gphoto2 --get-all-files
  2. Download selected photos: gphoto2 --get-file 98-1102
  3. Another option is to use digikam or gtkam. The second one is the official GUI client for gPhoto

Tools for images

  1. inkscape t.svg --export-pdf=t.pdf

Gdb and STL containers

This procedure works with Netbeans C++ interface for gdb.
  1. Check out the following project:
    svn co svn://gcc.gnu.org/svn/gcc/trunk/libstdc++-v3/python
  2. Add the following to your ~/.gdbinit
    python
    import sys
    sys.path.insert(0, '/home/maude/gdb_printers/python')
    from libstdcxx.v6.printers import register_libstdcxx_printers
    register_libstdcxx_printers (None)
    end
  3. Print /r is for raw printing as if the printers library was not loaded

External monitor on fluxbox

  1. How to turn off the laptop monitor when the external monitor is on? Type xrandr --output LVDS-0 --off
  2. Type xrandr to see names of available monitors if LVDS-0 is not your laptop monitor. This command shows possible resolutions as well.
  3. How to turn off the internal monitor and use the external one? Type xrandr --output VGA-0 --mode 1680x1050 --output LVDS-0 --off
  4. xrandr --output LVDS-0 --mode 1440x900 --output VGA-0 --off to do opposite
  5. duplicate display: xrandr --output LVDS-0 --auto --output VGA-0 --auto --same-as LVDS-0
  6. the second streen to the right: xrandr --output VGA-0 --mode 1680x1050 --right-of LVDS-0
  7. another option is to use: unity-control-center (Ubuntu 14.04)

Mouse

  1. Left handed mouse in Fluxbox. Type the following command:
    xmodmap -e "pointer = 3 2 1 4 5"


Use at your own risk. I do not bare any responsibilty for any loss incured when anything mentioned above is used.

[back to my home page]