Showing posts with label UBUNTU. Show all posts
Showing posts with label UBUNTU. Show all posts

Saturday, 13 September 2014

How to Change Your Command Prompt in UNIX or Linux

If you do not like your command prompt in UNIX or Linux, you can change it with the export PS1= command. In the example below, I started off with a command prompt of UBUNTU > :

UBUNTU > 

... then I changed it to show the name of the directory I was in. Here is one way to do this:

UBUNTU > export PS1='`pwd` > '
/home/andrew > cd Java
/home/andrew/Java > cd /
/ >

... and here is another:

/ > export PS1='$PWD > '
/ > cd
/home/andrew > cd Java
/home/andrew/Java > 

Finally, I changed it to say Andrew's PC: 

/home/andrew/Java > export PS1="Andrew's PC: "
Andrew's PC:

Thursday, 9 January 2014

How to See your IP Address in UBUNTU

You can do this from the Linux prompt as follows. The value you want is in bold. I hope to be using this a lot in future posts:

UBUNTU: ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0c:6e:e7:f1:92 
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
          Interrupt:19 Base address:0x9800

lo        Link encap:Local Loopback 
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:2102 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2102 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:217564 (217.5 KB)  TX bytes:217564 (217.5 KB)

wlan0     Link encap:Ethernet  HWaddr 00:14:6c:8a:f4:72 
          inet addr:192.168.2.2  Bcast:192.168.2.255  Mask:255.255.255.0
          inet6 addr: fe80::214:6cff:fe8a:f472/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:39507 errors:0 dropped:0 overruns:0 frame:0
          TX packets:37777 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:39342715 (39.3 MB)  TX bytes:7605863 (7.6 MB)

UBUNTU:

Friday, 29 March 2013

ssh Connection refused on UBUNTU

I tried to ssh to localhost on my UBUNTU PC but the connection was refused:

UBUNTU > ssh localhost
ssh: connect to host localhost port 22: Connection refused
UBUNTU >

This was because ssh had not been set up on my machine. I set it up like this:

UBUNTU > sudo apt-get install openssh-server openssh-client
Reading package lists... Done
Building dependency tree    
Reading state information... Done
openssh-client is already the newest version.
Suggested packages:
  rssh molly-guard openssh-blacklist openssh-blacklist-extra monkeysphere
The following NEW packages will be installed
  openssh-server ssh-import-id
0 upgraded, 2 newly installed, 0 to remove and 576 not upgraded.
Need to get 348 kB of archives.
After this operation, 891 kB of additional disk space will be used.
Get:1 http://gb.archive.ubuntu.com/ubuntu/ precise/main openssh-server i386 1:5.9p1-5ubuntu1 [342 kB]
Get:2 http://gb.archive.ubuntu.com/ubuntu/ precise/main ssh-import-id all 2.10-0ubuntu1 [6.598 B]
Fetched 348 kB in 1s (288 kB/s)  
Preconfiguring packages ...
Selecting previously unselected package openssh-server.
(Reading database ... 153823 files and directories currently installed.)
Unpacking openssh-server (from .../openssh-server_1%3a5.9p1-5ubuntu1_i386.deb) ...
Selecting previously unselected package ssh-import-id.
Unpacking ssh-import-id (from .../ssh-import-id_2.10-0ubuntu1_all.deb) ...
Processing triggers for ureadahead ...
ureadahead will be reprofiled on next reboot
me time ...
CreaProcessing triggers for ufw ...
Processing triggers for man-db ...
Setting up openssh-server (1:5.9p1-5ubuntu1) ...
Creating SSH2 RSA key; this may take some time ...
Creating SSH2 DSA key; this may take soting SSH2 ECDSA key; this may take some time ...
ssh start/running, process 3144
Setting up ssh-import-id (2.10-0ubuntu1) ...
UBUNTU >


Then I was able to connect as follows:

UBUNTU > ssh localhost
The authenticity of host 'localhost (127.0.0.1)' can't be established.
ECDSA key fingerprint is 56:30:a1:d5:23:9b:3f:a4:3b:30:6c:2c:07:c5:8e:3e.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'localhost' (ECDSA) to the list of known hosts.
andrew@localhost's password:
Welcome to Ubuntu 12.04 LTS (GNU/Linux 3.2.0-23-generic-pae i686)

 * Documentation:  https://help.ubuntu.com/

The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.

No mail.
UBUNTU >

/etc/services

The /etc/services file specifies which port a program must use when it connects to a UNIX or Linux machine. I tested this example using UBUNTU on my stand-alone PC so the connections are made to localhost. According to /etc/services, you must connect via port 21 if you wish to use ftp: 

UBUNTU > cat /etc/services|grep ftp
ftp-data        20/tcp
ftp             21/tcp
tftp            69/udp
sftp            115/tcp
ftps-data       989/tcp             # FTP over SSL (data)
ftps            990/tcp
venus-se        2431/udp            # udp sftp side effect
codasrv-se      2433/udp            # udp sftp side effect
gsiftp          2811/tcp
gsiftp          2811/udp
frox            2121/tcp            # frox: caching ftp proxy
zope-ftp        8021/tcp            # zope management by ftp
UBUNTU > ftp localhost 21
Connected to localhost.
220 (vsFTPd 2.3.5)
Name (localhost:andrew):
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> pwd
257 "/home/andrew"
ftp>

… but if you try using a different port, you are rejected:
 
UBUNTU > ftp localhost 42
ftp: connect: Connection refused
ftp>

Wednesday, 23 January 2013

The UNIX and Linux banner Command

With the banner command, you can use the # symbol to create large messages:

UBUNTU > banner Andrew
   #
  # #    #    #  #####   #####   ######  #    #
 #   #   ##   #  #    #  #    #  #       #    #
#     #  # #  #  #    #  #    #  #####   #    #
#######  #  # #  #    #  #####   #       # ## #
#     #  #   ##  #    #  #   #   #       ##  ##
#     #  #    #  #####   #    #  ######  #    #

UBUNTU > 


If the message has two words, the second appears below the first:

UBUNTU > banner Red Rum
######
#     #  ######  #####
#     #  #       #    #
######   #####   #    #
#   #    #       #    #
#    #   #       #    #
#     #  ######  #####

######
#     #  #    #  #    #
#     #  #    #  ##  ##
######   #    #  # ## #
#   #    #    #  #    #
#    #   #    #  #    #
#     #   ####   #    #

UBUNTU >


But, if you put the message in quotes, the two words appear on the same line:

UBUNTU > banner 'Red Rum'
######                          ######
#     #  ######  #####          #     #  #    #  #    #
#     #  #       #    #         #     #  #    #  ##  ##
######   #####   #    #         ######   #    #  # ## #
#   #    #       #    #         #   #    #    #  #    #
#    #   #       #    #         #    #   #    #  #    #
#     #  ######  #####          #     #   ####   #    #

UBUNTU >

Sunday, 20 January 2013

chown

You can change the owner of a file with the chown command. Here is a file:

UBUNTU > ls -l
total 0
-rw-rw-r-- 1 andrew users 0 Aug 22 22:09 file1
UBUNTU >

The file is owned by andrew. If you want to change the owner to fred, you can do so as follows:

UBUNTU > sudo chown fred file1
UBUNTU > ls -l
total 0
-rw-rw-r-- 1 fred users 0 Aug 22 22:09 file1
UBUNTU >

Tuesday, 15 January 2013

How to Create a File of a Particular Size in UNIX or Linux

I needed a file with a size of 512 bytes for an Oracle test. I created it as follows:

UBUNTU > dd if=/dev/zero of=test1 bs=1 count=512
512+0 records in
512+0 records out
512 bytes (512 B) copied, 0.0140867 s, 36.3 kB/s
UBUNTU > ls -l test1
-rw-rw-r-- 1 andrew andrew 512 Aug 11 22:34 test1
UBUNTU >

To create a file with a size of 1000 bytes, you only have to change count=512 to count=1000:

UBUNTU > dd if=/dev/zero of=test2 bs=1 count=1000
1000+0 records in
1000+0 records out
1000 bytes (1.0 kB) copied, 0.0174102 s, 57.4 kB/s
UBUNTU > ls -l test2
-rw-rw-r-- 1 andrew andrew 1000 Aug 11 22:35 test2
UBUNTU >

Wednesday, 9 January 2013

UBUNTU Block Size

You can see the block size in UBUNTU as follows: 

UBUNTU > sudo dumpe2fs -h /dev/sda5|grep -i "block size"
dumpe2fs 1.42 (29-Nov-2011)
Block size: 4096
UBUNTU >

Disk Speed

You can use the following command to see the speed of a hard disk: 

UBUNTU > time dd if=/dev/zero of=large_file \
> bs=4096 count=2000000
2000000+0 records in
2000000+0 records out
8192000000 bytes (8.2 GB) copied, 192.95 s, 42.5 MB/s

real 3m13.102s
user 0m6.148s
sys 1m29.718s
UBUNTU >

hostname and uname -n

You can see the name of the machine you are using with the hostname command:

Linux > hostname
LUBUNTU-Laptop
Linux >

The uname -n command does the same thing:

Linux > uname -n
LUBUNTU-Laptop
Linux >