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 >

Monday, 21 January 2013

The UNIX pwd Command

With the pwd command, you can see the name of the directory you are currently using: 

[andrew@localhost ~]$ cd /home/andrew
[andrew@localhost ~]$ pwd
/home/andrew
[andrew@localhost ~]$

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 >

Thursday, 17 January 2013

Memory Size on a Linux Machine

You can see how much memory there is on a Linux machine with the following command. Then you need to look at the value (131047424) in the column called total and the line called Mem:

Linux > cat /proc/meminfo
        total:    used:    free:  shared: buffers:  cached:
Mem:  131047424 81170432 49876992 23453696 23302144 33415168
Swap: 139788288  8556544 131231744
MemTotal:    127976 kB
MemFree:      48708 kB
MemShared:    22904 kB
Buffers:      22756 kB
Cached:       32632 kB
BigTotal:         0 kB
BigFree:          0 kB
SwapTotal:   136512 kB
SwapFree:    128156 kB
Linux >

You can see the same details (in bytes) with free -b. If you want to have the answer in kilobytes, which is the default option, you can do it with free -k. If you want to have the result in megabytes, you can do it with free -m:

Linux > free -b
             total       used       free     shared    buffers     cached
Mem:     131047424   81235968   49811456   23449600   23302144   33480704
-/+ buffers/cache:   24453120  106594304
Swap:    139788288    8556544  131231744
Linux > free -k
             total       used       free     shared    buffers     cached
Mem:        127976      79332      48644      22900      22756      32696
-/+ buffers/cache:      23880     104096
Swap:       136512       8356     128156
Linux > free
             total       used       free     shared    buffers     cached
Mem:        127976      79332      48644      22896      22756      32696
-/+ buffers/cache:      23880     104096
Swap:       136512       8356     128156
Linux > free -m
             total       used       free     shared    buffers     cached
Mem:           124         77         47         22         22         31
-/+ buffers/cache:         23        101
Swap:          133          8        125
Linux >

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 >

Monday, 14 January 2013

How to Tell if a UNIX User is Locked

You can check if a UNIX user is locked with the passwd -s command, followed by the username. If the letters LK appear at the start of the output, after the username, the user is locked:

Solaris root user > passwd -s oracle
oracle    LK    06/15/12     7    56     7
Solaris root user >

You can unlock a user with the passwd -u command, followed by the username:


Solaris root user > passwd -u oracle
passwd: password information changed for oracle
Solaris root user>

After unlocking the user, the letters PS replace the letters LK in the output of the passwd -s command. This simply means that the user has a password:


Solaris root user > passwd -s oracle
oracle    PS    06/15/12     7    56     7
Solaris root user >

In Spanish / en espaƱol

Saturday, 12 January 2013

Examples Using wc

Here is a file:

Linux > cat file1
Increase productivity across your entire Oracle stack
with access to unique on-line tools and support
communities - all part of your Oracle Premier Support
service.
Use Oracle proactive support to reduce risks and
lower your organisations costs through preventive
maintenance. Benefit from health services, intelligent
fault management and timely, personalized advice,
backed by Oracle support experts.
Linux >

You can count the number of lines, words and characters in the file like this:


Linux > wc file1
      9      56     403 file1
Linux >

If you only need the number of lines, here is what you must do:


Linux > wc -l file1
      9 file1
Linux >

The following example counts the words in the file:


Linux > wc -w file1
     56 file1
Linux >

With wc -c you can count the number of characters in the file:

Linux > wc -c file1
    403 file1
Linux >

You can find the length of the longest line like this:


Linux > wc -L file1
     54 file1
Linux >

Here is another file:

Linux > cat file2
The 2012 threat landscape is one of constant and rapid
change.
Where new website vulnerabilities are tirelessly sought
and exploited.
Where new social engineering techniques can increasingly
circumvent external security measures and infect from
within.
And where hackers now employ multiple attack
methodologies and vectors to penetrate defences and
steal information.
Linux >

You can give more than one filename as follows:

Linux > wc -lc file1 file2
      9     403 file1
     10     369 file2
     19     772 total
Linux >

In the next example, cat is used to see the result without the filename:

Linux > cat file1|wc -L
     54
Linux >

If you give the name of a file which does not exist, wc replies with an appropriate error message:


Linux > wc file3
wc: file3: No such file or directory
Linux >

Friday, 11 January 2013

Case Sensitivity in UNIX and Linux

In UNIX and Linux, names are case sensitive. Here is an example. We start in an empty directory. Then we create 4 files with the same name. One filename is in lower case. One file name is in upper case. The other filenames have a combination of upper and lower case letters: 

UBUNTU > ls
UBUNTU > touch fila1 Fila1 FiLa1 FILA1
UBUNTU > ls
fila1 Fila1 FiLa1 FILA1
UBUNTU > 

You can do the same thing with directories:

UBUNTU > ls -l
total 0
-rw-r--r-- 1 andrew users 0 Aug 27 20:54 fila1
-rw-r--r-- 1 andrew users 0 Aug 27 20:54 Fila1
-rw-r--r-- 1 andrew users 0 Aug 27 20:54 FiLa1
-rw-r--r-- 1 andrew users 0 Aug 27 20:54 FILA1
UBUNTU > mkdir dir1 Dir1 DiR1 DIR1
UBUNTU > ls -l
total 16
drwxr-xr-x 2 andrew users 4096 Aug 27 21:00 dir1
drwxr-xr-x 2 andrew users 4096 Aug 27 21:00 Dir1
drwxr-xr-x 2 andrew users 4096 Aug 27 21:00 DiR1
drwxr-xr-x 2 andrew users 4096 Aug 27 21:00 DIR1
-rw-r--r-- 1 andrew users    0 Aug 27 20:54 fila1
-rw-r--r-- 1 andrew users    0 Aug 27 20:54 Fila1
-rw-r--r-- 1 andrew users    0 Aug 27 20:54 FiLa1
-rw-r--r-- 1 andrew users    0 Aug 27 20:54 FILA1
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 >