The Meaning of dot slash for Running an Executable in Linux

The dot refers to the current directory. The forward slash “/” is the directory path separator.

So, when you type in ./filename at the shell, you prefix the filename with the path to the current directory.

Why do we need to do this when running any executable file?

When you run a command in the shell, it either runs it as a built-in command, or as an executable.

If it isn’t a built-in command, the shell tries looking for the executable in all the directories specified by the PATH environment variable – you can see what this contains by typing in echo $PATH in the terminal.

So if your file is in the current directory, the shell won’t find it – because the current directory is not included in the PATH by default. If you prefix the dot and the slash, the path to the file is passed to the shell, which looks for it exactly at the specified location. In fact, the shell doesn’t search the PATH at all when an absolute or relative path (other than just the filename) is specified.

Here’s something to try, but make sure you immediately undo it by exiting the terminal: Add the current directory to the PATH variable in your current shell by typing in

export PATH=$PATH:.

Now, you can run your executable without the dot slash!

WARNING: As noted in the comments below, this change has security implications. The above command will last only for the current terminal session – the changes to the PATH variable will be lost when you exit the terminal. Make sure you do not make this change permanent.

How about using the absolute path?

Since the dot slash helps the shell find the executable by specifying the directory, providing the absolute path without the dot prefix also works.

People might think you always need the dot to be prefixed, even when using absolute paths, but that doesn’t work because you end up prefixing the path to the current directory in addition to the complete path.

Note that you can also execute files using a relative path, in the form of <sub-dir>/<executable>, for example.

Remotely Working Together on a Terminal Session in Linux

I often get a chance to work from home, and this has given me opportunities to look for ways to share sessions with my colleagues. Windows XP used to have the excellent NetMeeting tool, but I recently switched to Ubuntu and haven’t yet found an equivalent.

Yes, I’ve heard of VNC and used it a lot too, but I wasn’t happy with its remote desktop sharing performance. Ekiga is interoperable with NetMeeting calls, but doesn’t support screen sharing. Even Skype’s screen sharing does not seem to support remote screen controlling.

However, Linux’s power is at the command line, and this is true even in the case of remote sharing. So here comes screen to the rescue – this magical command allows you to flawlessly resume lost sessions and share them with multiple users at the same time.

Starting screen

Start screen using

screen -d -R session_tomcat

Replace session_tomcat with any other helpful name for the session you’re about to create.

Sharing your Session

Ask your friend to connect using (assuming they are logged in using the same user account):

screen -x session_tomcat

Now it’s simply magical. Multiple persons can type and work on the same terminal – it works best when you’re coordinating over the phone. Note that the dimensions of your terminal output will be the same for every user – to change it, press CtrlA and then capital F. This will make the screen output fit your current terminal size, and change it to that size for every connected user.

Detaching from a Screen Session

Important: To detach from the screen session so that you can resume later, simply close the window. If you type exit, you’ll end up terminating the screen session and the processes running within.

Why screen is better than nohup and tail

Here’s a comparison. Consider a hypothetical example in which you need to find a file that contains the word “cat” in its name. You know it will take long, so you run the following combination of commands:


$ nohup find / -name *cat* &
$ tail -f nohup.out

The nohup command is a request to not kill (nohup stands for “no hangup”) the process that you are just about to run in case you lose connection. The & at the end sends the process to the background, so that the prompt returns immediately. The tail -f follows the output of the command executed through nohup. If you do lose connection, simply run tail -f nohup.out again to see the running output.

To do the equivalent in a screen session, you’ll only need run the find command in an open screen session. If you need to reconnect after a lost connection, run screen -d -R <session_name> again, and you’ll be back in your session as though you never left it.

Far more neat, isn’t it? Of course, screen has much more to offer than being a simple replacement for nohup and tail -f. For example, it’s very easy to resume a CLI session running remotely – you’d simply reconnect without having to re-initialize.

Other Advanced Usages

CtrlA has a special meaning when running screen – it allows you to execute special screen commands.

To see the list of available commands, type CtrlA and then ?.

For example, one interesting feature of screen is its support for multiple windows. To create a window, type CtrlA and then c.

To switch to a window, use CtrlA and then the window number (from 0 to 9).

To see the list of available windows type CtrlA and then ".

The man page of screen reveals a great deal more to explore!

Which features of the screen command in Linux do you find the most useful?

List of Shortcuts for the Eclipse Java IDE

Here’s a cheat sheet of Eclipse shortcuts I’ve put together to help me work really fast with the IDE. The shortcuts have been categorized into two sections – one that most people know about, and another section that contains the lesser known ones. You should be able quickly scan through the first section, and learn any of the ones that you don’t currently know.

The second section might take longer, and you may want to bookmark this page for future reference.

Easy Shortcuts

Search in files

Use CtrlH to search in all files across the workspace or project.

Search Dialog in Eclipse Juno

Open Resource

CtrlShiftR opens a resource quickly – without the time it spends for indexing. This makes it especially fast when you’ve just opened a workspace, in comparison to the Open Type shortcut below.

Open Resource Dialog in Eclipse Juno

Open Type

Use CtrlShiftT to open a Java type.

Open Type Dialog in Eclipse Juno

While I prefer CtrlShiftR to search for files, CtrlShiftT works better if you want to search for Java classes or interfaces.

Open the Type Hierarchy

Use CtrlT to get a popup window with the type hierarchy for the type under your cursor.

Type hierarchy popup - Eclipse Juno

This is tremendously useful to see inherited types, sub-types, and implemented interfaces.

Press CtrlT again to toggle between super-types and sub-types.

Display members and inherited members

Pressing CtrlO displays the class members, pressing it again displays the inherited members too!

Eclipse class members popup

Focusing on the tooltip

Press F2 to get the tooltip for the item currently under the cursor.

F2 Tooltip Eclipse Juno

Correcting Indentation of Selected Text

Use CtrlI to correct indentation.

Debuggging

Use F5 to Step into, F6 to Step over, F7 to step out, and F8 to resume. See below for more shortcuts on debugging.

New File Wizard

Use CtrlN to start the new File Wizard.

New File Wizard - Eclipse Juno

Lesser Known Shortcuts

CtrlTab to Switch Between Windows

Go to General->Keys to see all shortcuts.

Setting Eclipse Juno shortcut for switching between editor windows

Change the binding of Next Editor and Previous Editor to use Tab instead of F6 – this makes it incredibly easy to switch between open editors. I often dislike changing keyboard shortcuts so that it’s easy to work on someone else’s machine too, but I couldn’t resist this one.

Cycle through tabs in the current view

Similar to the above, but still slightly different: Use CtrlPgUp and CtrlPgDn to switch between tabs in your current viewwithout showing you the complete list of available tabs.

Scroll without using the mouse

Use CtrlUp and CtrlDown to scroll, while keeping your cursor in the same position!

Move a line or lines

Use AltUp and AltDown to move selected lines, or the current line.

Jump to matching bracket

CtrlShiftP on a bracket, brace or parenthesis moves the cursor to its matching bracket, brace or parenthesis.

Progressively Select Blocks

Use ShiftAltUp / ShiftAltDown to progressive select blocks.

Find references

CtrlShiftG will find references to the item under the cursor.

Find declarations (Only C++/Javascript)

CtrlG finds declarations of the item under the cursor.

Open Declaration

F3 opens the declaration for the item under the cursor.

Find previous and next, based on selection

Use ShiftCtrlK and CtrlK to find the previous and next occurrences of the item under the cursor.

I had to set CtrlK for “Find next” in Preferences->General->Keys, but the shortcut for “Find previous” was there by default.

CamelCase Code Completion

If you have a class that has a VeryLongName, simply type VLN and press CtrlSpace to see VeryLongName as one of the suggestions.

Automatically Insert Braces and Semicolons at the correct position

This isn’t a shortcut – but a useful productivity boost. Setting semicolons and braces to be automatically inserted in the correct position allows you to type them in from anywhere but they actually appear at the end of the line. Escaping text in string literals is another useful option.

Eclipse Juno preferences - automatic insertion of braces and semicolons at correct position and escaping pasted strings

Quick Access Menu

Quickly access any menu, command, editor, etc by typing in Ctrl3 and then the initial letters of the item you want.

Eclipse Juno quick access menu

History

Use AltLeft and AltRight to navigate between your editor history items. This is equivalent to using the history icons on the toolbar.

Eclipse Juno history toolbar buttons

Quick Fix

Use Ctrl1 to get to the quick fix menu and quickly fix compile-time issues.

Eclipse Ctrl-1 quick fix menu

Debugging

Use CtrlR to run to the current line. Use CtrlShiftB to toggle a breakpoint. F11 debugs the last run program, while CtrlF11 runs it.

Refactoring

ShiftAltR renames an item and updates all references. Use ShiftAltL to extract code to a local variable, and ShiftAltM to move code to a method.

The Best of them all!

And finally, which one’s the greatest shortcut of all? Use CtrlShiftL to get a list of all available shortcuts!!

Eclipse Juno list of shortcuts

\

How to enable Java in Chrome and Firefox on Ubuntu

To enable Oracle’s Java plugin in your Linux browsers, just copy these lines into a script, and run it!

JAVA_HOME=/usr/lib/jvm/jdk1.7.0
MOZILLA_HOME=~/.mozilla
mkdir $MOZILLA_HOME/plugins
ln -s $JAVA_HOME/jre/lib/i386/libnpjp2.so $MOZILLA_HOME/plugins

Note: You may need to change the value of JAVA_HOME so that it correctly points to your installation of the JDK. 64-bit users will need to change the final line to:
ln -s $JAVA_HOME/jre/lib/amd64/libnpjp2.so $MOZILLA_HOME/plugins

If you’re a newbie, here’s how to run the script:

  1. Using your favorite editor, paste the contents of the script into a new file.
  2. Find out where Oracle Java is installed. This location has the directories “bin”, “lib”, and “jre”, among others. Replace the value of JAVA_HOME with the path to this folder, and save the file. This step applies if you’re using the JDK. If you’re only using the JRE, let JAVA_HOME point to the jre installation directory (which contains the folders “bin”, “lib” and “plugin”), and modify the last line in the script to remove “jre” from the path.
  3. Make the script executable, by typing in chmod +x <filename>
  4. Run the script using the command ./<filename>
  5. Restart your browser, and confirm your installation as shown in the next section

The above script will enable Java support in both Chrome/Chromium and Firefox, since they both use the ~/.mozilla/plugins directory to scan for available plugins.

Confirming Installation

After you’ve restarted your browser, if you see a message below detailing your installed Java version and operating system, you’ll know it’s working successfully.

You can also look up the address “about:plugins” in Chrome or Firefox to get the list of plugins installed in your browser.

Alternatively, look up Oracle’s How do I test whether Java is working on my computer? to confirm the version of Java your browser is using.

Troubleshooting

If you’re facing problems with your Java plugin not working correctly on certain sites, you might want to try updating Java to the latest version. Also, you could try switching to Oracle’s version (in case you’re running the OpenJRE or IBM’s JRE), since that’s what’s best supported on the web.