Linux Usage Tips

Linux shells

  • /bin/sh is the default login shell.
    • Edit $HOME/.profile to change interactive variables.
    • The $HOME/.bashrc file ''will not'' be run for non-interactive shells.
  • /bin/bash
    • Edit $HOME/.profile to change interactive variables.
    • The $HOME/.bashrc file ''will'' be run for non-interactive shells.
  • /bin/csh and /bin/tcsh
    • Edit $HOME/.login to change interactive variables.
    • The $HOME/.cshrc file ''will'' be run for non-interactive shells.

The change shell command, chsh, will not permanently change your shell. You must send a request instead.

The default login shell on linuxlogin is ''sh''. Be aware that in CentOS, /bin/sh is a soft-link to /bin/bash, so you are really using a variant of ''bash''. Accordingly, you will find that "man sh" brings up the man page (the help document) for ''bash''. In a way, then, you can think of your login shell as being ''bash'', too.

There are slight differences between ''sh'' and ''bash'', however. The "Invocation" section of the man page states: "If bash is invoked with the name sh, it tries to mimic the startup behavior of historical versions of ''sh'' as closely as possible." Therefore, you will find that ~/.profile is run at login, because this behavior is common to both ''sh'' and ''bash''; but any interactive ''sh'' shells you start thereafter will not run ~/.bashrc as you might expect from ''bash''. The way to get ''sh'' to do this is to "export ENV=~/.bashrc" beforehand (perhaps as part of your .profile).

Let's say you simply prefer to have ''bash'' as your default shell and be done with it. There are two ways to accomplish this. First, you can "export SHELL=/bin/bash" in your .profile; then all subsequent interactive shells will truly be ''bash''. Second, you can enter "chsh -s /bin/bash", which forces all login and interactive shells to be ''bash'' (because you have changed your default shell). The problem with the second method is it may well wreck your batch environment, too, because the scheduler sets it up under the assumption that the login shell is ''sh''.

The relationship between the ''csh'' and ''tcsh'' shells is similar to the one between ''sh'' and ''bash''. For instance, your ''csh'' shells are automatically endowed with the ''tcsh''-style ability to retrieve history through the up- and down-arrow keys. The best way to make ''tcsh'' into your everyday working shell is to run it on top of ''sh'' after you log in (again, you can do this as part of your .profile).


Compiling and linking code on Linux

How do you Install R packages in your home directory?
How do you Install Python packages in a Python virtual environment?
How do I determine my program's dependencies on shared library (.so) files?
  • ldd - see the man page.

If your program cannot find all the .so files it needs, you may need to add paths to the LD_LIBRARY_PATH shell variable.

How do I display an image file (such as jpeg or gif)?
  • display mypic.jpg - uses one of the many ImageMagick tools - see "man ImageMagick" for help on this and various file format converters.
  • firefox mypic.jpg - any decent Web browser can handle it.

Note, the image will show up only if you have X11 forwarding enabled.

How do I use revision control?
  • Git, Subversion, and CVS are examples of revision control (or version control or source control) software. These tools help you collaborate with others by allowing you to save and track successive versions of your source code as you modify it. Git is often used in conjunction with GitHub. Git is installed on linuxlogin: see the git man pages for for details. To check the installed version, type git --version.