Showing posts with label Linux Commands. Show all posts
Showing posts with label Linux Commands. Show all posts

Thursday, 9 October 2014

mkdir command

 

This command is used to create a new directory. The various formats of the command are as follows

mkdir <directory_name> ......

This will create a new directory with the name “directory_name” in the current directory.

mkdir <path/directory_name> .....

This will create a new directory with the name “directory_name” in the specified path. The parent directories should exist for this to work properly. Otherwise it will throw error.

mkdir -m <MODE> [other options] <directory_name> ... | <path/directory_name> ...

OR

mkdir -m<MODE> [other options] <directory_name> ... | <path/directory_name> ...

This will create a new directory with the name “directory_name” in the current directory or specified path with the permission as specified by the “MODE” value. If other options (except –help and –version) are specified “mkdir” will take care of that also while creating directories.

mkdir -p [other options] <path/directory_name> ...

This will create a new directory with the name “directory_name” in the specified path with the creation of parent directories as needed. If the parent directory already exists, there is no problem. If it doesn't the command will create the directory. If other options (except –help and –version) are specified “mkdir” will take care of that also while creating directories.

mkdir -v [other options] <directory_name>... | <path/directory_name>...

A message is outputted for each of the created directories. If the directory already exists no message is shown.

mkdir –-help

Shows the help for the command

mkdir –-version

Shows the version of the command

Creating multiple directories at a stretch

mkdir <directory1> <directory2> <path/directory3> ....

This will create all the directories. You can use any options (except –help and --version) of the “mkdir” command along with this.

Examples

Creating a directory named “test” in the current directory.

mkdir test

Creating a directory named “test” in the directory “/tmp/testabc/”. The directories “/tmp” and “/tmp/testabc” already exists.

mkdir /tmp/testabc/test

Creating a directory named “test” in the current directory with permission 644

mkdir -m644 test

Creating a directory named “test” in the directory “/tmp/testabc/” with permission 555. The directories “/tmp” and “/tmp/testabc” already exists.

mkdir -m555 /tmp/testabc/test

Creating a directory named “test” in the path “/testabc/hai/monday/week/day”. None of the directories in the path exists, except “/”

mkdir -p /testabc/hai/monday/week/day/test

Creating a directory named “hello” in the path “/hai/month/week/day” with permission 700. None of the directories in the path exists, except “/”

mkdir -pm700 /hai/monday/week/day/hello

Saturday, 15 February 2014

Creating a desktop shortcut for FTP access in Ubuntu


Create a “<filename>.desktop” file with the following entries. Replace “<filename>” with suitable name.




[Desktop Entry]
Name=FTP
Exec=nautilus --new-window ftp://<FTP Site Address>
Icon=system-file-manager
Type=Application






Give the file executable permission. On double clicking the file now the FTP site will be opened in nautilus.

Thursday, 13 February 2014

Ubuntu Server Setting IP Address by Editing “Interfaces” File


First login to Ubuntu server. Ubuntu server stores the configuration of network interfaces in the file “/etc/networks/interfaces”. To view the content of the file use the command “cat /etc/networks/interfaces”. So let see and example file in the below picture.

Here as can be seen there are two interfaces. The one with the name “lo” is the loopback interface. The other with the name “eth0” is the real interface connected to this machine. Here it is set to “DHCP” as shown by the line “iface eth0 inet dhcp”.
Now let us check the IP obtained by the machine. For this we have to use the command “ifconfig”. The ip as shown by the command is depicted in the picture below.

Now let us edit the file “/etc/networks/interfaces” to set the IP address to static. We will set the IP address to “192.168.56.105”. Here we assume the network interface is taken as “eth0”. For this you have to add the following lines as shown in the picture below:
[Use the command “sudo vi /etc/networks/interfaces” to edit the file]
auto eth0
iface eth0 inet static
address 192.168.56.105
netmask 255.255.255.0
gateway 192.168.56.1

After this save the file. (Hope you are familiar with vi editor).  Now to have the settings take effect you need to restart the service named “networking”. For this use the command “sudo service networking restart”. After that let us check the ip again using the “ifconfig” command”". See the picture below:

Now the IP has changed. Now let us ping to “google.com” and see the result. [I have Internet access from this system. Otherwise this ping won’t work. You can ping to your domain computers if yours is internal network]

My God no ping. I had set the network interface with IP, so what is the problem. Oh! I forget to set dns entries. OK let us add the same to the file “/etc/networks/interfaces”. For this you have to add the line “dns-nameservers <ip1> <ip2>”. Normally two ips for dns that is why. You can any number of ips separated by spaces.

Now restart the “networking” service again. Let us check the content of “/etc/resolv.conf” file by using the command “cat /etc/resolv.conf”.

You can see the dns server entries are now in this file. Don’t edit this file directly as it is generated dynamically on every reboot.
Now let us again ping to ”google.com”.

Got the ping. Now everything is working fine.

Monday, 9 December 2013

Finding Ubuntu and Kernel Version and other details


Finding kernel details
You can use the “uname” command to find the kernel details in Ubuntu. The command has got various options which is described below
uname –v
This will show the kernel-version. When executed in Ubuntu 13.10 the result is as follows

uname –r
This command helps one to find the kernel release version. Please see the result of the same in Ubuntu 13.10 below

uname –s
This command helps one to list the kernel name.

uname –n
This command helps one to list the node name i.e the machine name or name you have given to your system.

uname –m, uname –p and uname –i
These variants help one to find the machine hardware name, the processor type and the hardware platform type.

Now if you want to see all these information at once you can use the following variant of the command
uname –a


Finding Ubuntu version details
Using the command “lsb_release” one can find some information about the Ubuntu version. Let us go through different variants of the command
lsb_release –r
This variant will help you to get the Ubuntu release version

lsb_release –i
This command will show the distribution ID of the Ubuntu release

lsb_release –d
Helps to get the description attached with the distribution

lsb_release –c
This command helps to find the codename assigned to the release

Now if you want to see all these information at once you can use the following variant of the command
lsb_release –a


Thank you all………….

Monday, 25 November 2013

Finding Disk Space using command line in Ubuntu


Let see how we can use the “df” command to find the disk space and partitions in Ubuntu
First open a terminal. Now type the command “df –h”. This will show an output as shown in the picture below. Here the option “-h” is used to produce the output in human readable form

 
As you can see the output will have 6 columns. First one is the “Filesystem”, second showing the total size, third the used space, fourth the remaining space, fifth the space usage in percentage and the last column shows where it is mounted.
Now if we want to get the total also just add one more option to the command. The option is “- -total”. Now the command become “df –h - -total”. As shown below it will show the total disk space, total usage, total free and the total usage percentage.