Saturday 13 December 2014

Mapping a Linux folder to another Linux folder

NFS is a protocol used to map a Linux drive to another Linux drive and treat the other drive as it was a local one.

The following is based on RedHat Linux.

First, on the remote machine that you want to have access to, you need to have installed the nfs service files from the installation disk:
system-config-nfs...  (GUI tool to manipulate the NFS configuration)
nfs-utils-lib...  (support library)
nfs-utils... (NFS utilities and daemons)
portmap-....(manager of RPC connections)

Next, open NFS in System -> Administration -> Server settings. This will edit the NFS configuration file through the GUI. You can do the same by manually editing the /etc/exports file, if you prefer.
So, once the configuration GUI tool is open, click Add to add info about the folder to be exported for external access.
This link http://www.centos.org/docs/5/html/Deployment_Guide-en-US/s1-nfs-server-export.html can help you here.


Next, run the NFS service from System -> Administration -> Server settings -> Services
Or, if it was already running, restart it for changes to take effect.
 /etc/init.d/nfs   restart

 Finally, execute this command on the other machine which will gain access to the one we just configured

mount -f nfs -o sync.dirsync.rw,rsize=32768,wsize=32768,noac,lookupcache=none 10.123.10.10:/home/path/to/export  /home/local/path

Now we expect that the local folder /home/local/path will be mounted to /home/path/to/export on the remote machine.


Change owner

To change owner of a folder and its content:

chown -R newOwner:newGroup  /path

How to attach in Eclipse the source code of Java language

If you need to browse the original code of the Java language, you need to attached its sources to the installed JRE preference page, as by default it is not attached when you specify your working JRE.

In Eclipse, select Windows -> Preferences -> Java -> Installed JREs , expands rt.jar, select “Source attachment” and find the src.zip from your disk drive.

That should be right under the JDK folder , for example:  C:\Program Files (x86)\jdk7

Wednesday 23 July 2014

Change display resolution in Linux

Change display resolution in Linux

This also reflects upon the display size in vSphere client, which was the reason I needed to changed the resolution, it was a bit too big and had to scroll the screen and wanted to reduce its size.

To change the VGA card display resolution in RHEL5

1) First check all the possible resolutions supported by your graphics card using the following command.

            "xrandr"

It will display all possible resolutions.


2) Change resolution.

Suppose your graphics card support 1024x768 resolution then you can change it using the following command.

"xrandr -s 1024x768"



If you don't have "1024x768" in that “xrandr” output, try below one this might be help to get “1024x768”.


In “/etc/X11/xorg.conf” file just check the entries


            SubSection "Display"
                        Viewport  0 0
                        Depth     24
                        Modes "1024x768"
            EndSubSection


Check the entry “Modes”. If it is not present just add this line and check.

Thursday 10 July 2014

Close port on Linux

sudo netstat -lpn | grep 8080
will list the process on port 8080
example:
tcp      0     0   :::8080      :::*      LISTEN   21026/java

kill 21026

Friday 4 July 2014

Copy a file

cp file file.bak
cp file /home/user/file.bak

Copy "file" and give the copy a name "file.back". Optionally place the copied file to another location by specifying a path.

Saturday 10 May 2014

More Linux shell commands

less  fileName => opens the file a page at a time.  SHIFT+G will move to the end of the file.


tail -3 fileName => open the file at the end showing just the last 3 lines that end with new line


mkdir  -p   a/b/c   => create empty directory structure in the current directory. If /a/b/c is used, then it will be created in the root of the system, if you have permissions.


rmdir -pv a/b/c  => remove the whole folder structure, starting from the bottom to top. The structure to delete must be explicitly described (a/b/c).
-p is the same option as above (parent)
-v is verbose output of all steps the command performs



ls -R folderName   => list recursively the content of the folder structure inside the folderName
ls -d  */     -> list only the directories in the current folder. * is all, / is just subfolders one level below.
                      To go deeper, add more */*/



u  user
g group
o other
chmod u+x file  -> set exec right to the owner (user)
chmod u=x file    -> set only exec right to the user (owner) of the file
chmod ugo=r  file   -> set only read rights to all three, user, group, others
chmod g=wx  file   -> set write and exec rights for the group
chmod a-rwx file   -> remove all three rights for all three kinds of users (owner,group,other)
chmod 000  file   -> same as above
chmod u+rwx,g+r,o+r  file  ->  set user all rights, group read and other read.
                                               No space around the comma.




Friday 7 February 2014

Some batch file commands

Funny but I've tried to change directory in a command prompt by simply typing:

CD D:\
and sure enough this does not work.
To change to new directory add /D  (case insensitive)
 
cd /d  d:\
 or just
D:

Some reserved variables:

%~dp0  -> this will contain the path to the script
%0      -> this will hold the path+the name of the script

%1 up to %9   -> this in the script will pick up arguments that may have been passed to the script when it was launched from command line


Wednesday 15 January 2014

df and du

'du' - Finding the size of a directory

$ du
Typing the above at the prompt gives you a list of directories that exist in the current directory along with their sizes. The last line of the output gives you the total size of the current directory including its subdirectories. The size given includes the sizes of the files and the directories that exist in the current directory as well as all of its subdirectories. Note that by default the sizes given are in kilobytes. 



$ du / -h --max-depth 1 list the same info in GB/MB for the root directory and go only one level in depth/down

$ du /home/deyan
The above command would give you the directory size of the directory /home/deyan


$ du -h
This command gives you a better output than the default one. The option '-h' stands for human readable format. So the sizes of the files / directories are this time suffixed with a 'k' if its kilobytes and 'M' if its Megabytes and 'G' if its Gigabytes.


$ du -ah

This command would display in its output, not only the directories but also all the files that are present in the current directory. Note that 'du' always counts all files and directories while giving the final size in the last line. But the '-a' displays the filenames along with the directory names in the output. '-h' is once again human readable format.


$ du -c
This gives you a grand total as the last line of the output. So if your directory occupies 30MB the last 2 lines of the output would be

30M .
30M total

The first line would be the default last line of the 'du' output indicating the total size of the directory and another line displaying the same size, followed by the string 'total'. This is helpful in case you this command along with the grep command to only display the final total size of a directory as shown below.


$ du -ch | grep total
This would have only one line in its output that displays the total size of the current directory including all the subdirectories.


$ du -s
This displays a summary of the directory size. It is the simplest way to know the total size of the current directory.


$ du -S
This would display the size of the current directory excluding the size of the subdirectories that exist within that directory. So it basically shows you the total size of all the files that exist in the current directory.

-

'df' - finding the disk free space / disk usage

$ df
Typing the above, outputs a table consisting of 6 columns. All the columns are very easy to understand. Remember that the 'Size', 'Used' and 'Avail' columns use kilobytes as the unit. The 'Use%' column shows the usage as a percentage which is also very useful.


$ df -h
Displays the same output as the previous command but the '-h' indicates human readable format. Hence instead of kilobytes as the unit the output would have 'M' for Megabytes and 'G' for Gigabytes.


Monday 6 January 2014

Remove a symbolik link in Linux

Symbolik link is one that points to a file or directory, a kind of shortcut.
When it needs to be removed and you use the auto fill in of commands in the shell (TAB key) and you type rm then the name of the link, it will automatically add the name of the link and add a slash. This slash must be deleted in the command in order to be able to delete the symlink.

# correct way 
rm mySymLink
# incorrectly added slash
rm mySymLink/
 
The first one means you delete a file (which actually is the symlink) while the second is you want to delete a directory.
That's why you will get error you try to delete directory.
Also file permissions might be needed to be set up.