Showing posts with label Ubuntu. Show all posts
Showing posts with label Ubuntu. Show all posts

Friday, August 10, 2012

Cat and Terminal

Here's a spiffy little command that can be used to combine files, look at the contents of a file and do limited text editing.

The Linux cat command at first seems so simple as to be unnecessary. In actuality, it is an excellent example of the Unix philosophy: create programs which do one thing and do it well. The thing cat does well is display the contents of a file or files. Many other utilities can handle this task, but none have all the options cat does. First, let's look at the simplest case:

cat /etc/motd

This command will display the contents of the motd (messages of the day) file to your screen. Unlike more (or less), cat will not stop when the screen is full. This is a feature, not a bug. You don't want pauses when redirecting (using the > operator) cat's output to a device, e.g., a printer or modem:

cat /etc/motd > /dev/modem

cat comes from the word conCATenate, which describes one of its best uses: to concatenate or “glue together” two or more files. If you have several individual files about animals you would like to collect together into one file, cat will do the work for you. For example:

cat tiger lion cougar > bigcats

would redirect the concatenation output, containing the three feline files in the specified order, into a new file named bigcats. If you find another file, panther, that needs to be added to the bigcats file, use cat with the append (>>) operator in the following way:

cat panther >> bigcats

Using >> ensures any prior content of bigcats is preserved. The content of panther is appended to bigcats. If you were to use the > operator here, you would replace the contents of bigcats with the contents of panther. Always use >> when you wish to add to the end of an existing file.

Be careful not to use the same file name when redirecting the output of the cat command, or you could lose one of the files. For example, don't do the following:

cat myfile yourfile > yourfile

In this case yourfile gets overwritten by myfile.

Another surprisingly handy use for cat is to redirect standard input like this:

cat > newfile
some notes I want to save in newfile.
CTRL-D

This creates a new file (named newfile). You type as much text as you wish, then type ctrl-D to save the file. You can backspace over mistakes, but you cannot go to a previous line after you press the enter key. I often teach this particular option of cat to novice Unix users, who occasionally need to create simple files, but don't want to learn vi or other simple editors. There may be Unix systems without vi or your favorite editor, but cat is always there.

The operator >> can also be used to append notes to the end of newfile:

cat >> newfile
Adding another note to newfile.
CTRL-D

cat Switches

Like most Unix commands, the behavior of cat can be modified by command line switches. If you use the diff command to compare files, it will show you the numbers of lines that differ between the files. However, most files don't have line numbers. Use cat with the -n switch to number each line of a file:

cat -n kittens > num_kittens

The file num_kittens is kittens with a number in front of each line, including blank lines. Use the -b switch to number only lines that are not blank.

One last cat trick: using the -v switch will show you “hidden” characters, such as control characters that may not show up in your editor. Try this experiment:

cat > catestv
CTRL-v testing CTRL-O Testing esc-b
CTRL-D

If we use cat to view the file, we see only the normal text:

cat catestv
Testing Testing

To see what's actually in the file, use the -v option:

cat -v catestv
^V Testing ^O Testing ^[b

Here, a ^ in front of a character signifies a control character. (CTRL-[ is the same as ESC).

Courtesy : Linux Journal 
Read Rob Pike's Unix programming Environment! Buy one its cheap and good!

Thursday, March 8, 2012

Transfer files between PC and Android device over WiFi

Transferring files between your Android and PC over wifi

To do this over WiFi I recommend you to download and use SwiFTP .

Connect to your PC using wifi (This may be using a router to a network where your PC is also connected or simply connect it ).

Install SwiFTP from the market

Open the SwiFTP application in your android.


Setup the settings for connections in SwiFTP


  • Set a username.
  • Set a password
  • Set a IP be careful not to assign an IP which is already active in your network and preferably assign an IP which you have been already using in your device while connecting over network.
  • Set a proxy random 4 digit (use 2121)
  • Check the first two of other options.
  • Save  your settings 

Now Click the start button you will see something like this, note the Wifi URL



To connect to a PC you will have to follow the following steps.

For Linux based OS 

  • Open nautilus (your default file manager)
  • Click on the file menu
  • Click " Connect to sever "


  • Now fill in all the details as shown in the screenshot change the IP, username,port etc as you have given in SwiWifi

Once you click connect you can easily avail all your content of a android phone in your PC

Saturday, January 7, 2012

Running your first Assembly Language program using NASM.

Netwide Assembler (NASM) is an assembler and dissembler for the Intel x86 architecture and is commonly used to create 16-bit, 32-bit (IA-32) and 64-bit (x86-64) programs. It is available for multiple operating systems like Linux or Windows, for example.
An assembler can assemble the assembly code.


Here is a sample code(assembly language) which I copied from Nasm website.Now lets try to compile and run it using nasm.

section .data
 hello:     db 'Hello world!',10    ; 'Hello world!' plus a linefeed character
 helloLen:  equ $-hello             ; Length of the 'Hello world!' string
                                    ; (I'll explain soon)

section .text
 global _start

_start:
 mov eax,4            ; The system call for write (sys_write)
 mov ebx,1            ; File descriptor 1 - standard output
 mov ecx,hello        ; Put the offset of hello in ecx
 mov edx,helloLen     ; helloLen is a constant, so we don't need to say
                      ;  mov edx,[helloLen] to get it's actual value
 int 80h              ; Call the kernel

 mov eax,1            ; The system call for exit (sys_exit)
 mov ebx,0            ; Exit with return code of 0 (no error)
 int 80h

 

Compiling and Linking

  1. If you don't have a terminal or console open, open one now.
  2. Make sure you are in the same directory as where you saved hello.asm.
  3. To assemble the program, type
    nasm -f elf hello.asm
    If there are any errors, NASM will tell you on what line you did what wrong.
  4. Now type 
    ld -s -o hello hello.o

    This will link the object file NASM produced into an executable file.
  5. Run your program by typing ./hello
    (To run programs/scripts in the current directory, you must always type ./ before the name, unless the current directory is in the path.)
You should see     Hello world!    printed to the screen. Congratulations! You have just written your first assembly program in Linux!

Courtesy : Nasm website.

Thursday, July 7, 2011

Installing Drupal/LAMP in Ubuntu

Drupal

Drupal is a free and open source content management system (CMS) and content management framework (CMF) written in PHP and distributed under the GNU General Public License.It is used as a back-end system for at least 1.5% of all websites worldwide ranging from personal blogs to corporate, political, and government sites including whitehouse.gov and data.gov.uk.

Drupal runs on any computing platform that supports both a web server capable of running PHP (including Apache, IIS, Lighttpd, and nginx) and a database (such as MySQL, MariaDB, PostgreSQL, SQLite, MongoDB or Microsoft SQL Server) to store content and settings. So Drupal requires PHP, Apache/IIS/Lighttpd/ngix and MySQL/MariaDB/PostgreSQL/SQLite/MongoDB/Microsoft SQL Server (web server and database can be any one of the above listed as per your requirement and interest).

Now lets install Drupal, I can tell you that there are many methods to install and configure Drupal in Ubuntu, so I will suggest you one which I found very easy and working.

  • For installing Drupal(in Ubuntu/ linux mint) you have to install Lamp first ( ie Linux-Apache-Mysql-Php)

    • sudo apt-get install tasksel

    • sudo tasksel install lamp-server

    • Running these two commands in your terminal will install Lamp,during installation select your server as lamp server, apache and you will be asked to enter your database password for root user.

  1. Download the Drupal core file from Drupal.org you can download any of the desired version of Drupal available.
  2. Now unzip and copy the contents of the downloaded zip file to the location

    /var/www/Drupal

    using the command unzip your downloaded file

    sudo tar xvf (filename i e name of the downloaded zip file)

    eg sudo tar xvf Drupal-6.tar.gz

    now move the contents to

    /var/www/Drupal


    use the command

    sudo mv (source destination) (desired destination)

    eg sudo mv drupal-6 /var/www/drupal

  3. Now access local drupal website usinghttp://localhost/drupal

  4. You will be asked to change the privileges of file /var/www/drupal/sites/default/settings.php

    cd var/www/drupal/sites/default


    sudo cp settings.php default.settings.php

    sudo chmod a+w settings.php

    sudo mkdir files

    sudo chmod a+w files/


  5. Your Website is ready now. Learn Drupal from online resources or from books, to know more about resources click here.

You should now install Phpmyadmin (recommended)

phpMyAdmin is an open source tool written in PHP intended to handle the administration of MySQL with the use of a Browser. It can perform various tasks such as creating, modifying or deleting databases, tables, fields or rows; executing SQL statements; or managing users and permissions.

Here i will tell you how to install phpmyadmin from package.....
  • Go to your terminal window now enter
    • sudo apt-get install phpmyadmin
    • You will be asked to select your web-server select apache 2
    • Once phpMyAdmin is installed point your browser to http://localhost/phpmyadmin to start using it. You should be able to login using any users you've setup in MySQL. If no users have been setup, use admin with no password to login.
    • Your phpmyadmin is installed now
  • In case if your browser displays an error "404 not found" kind then try to reinstall your phpmyadmin and configure it to apache
    • sudo dpkg-reconfigure -plow phpmyadmin
  • If your browser is still displaying some error message enter these two commands given below to include the phpMyadmin-shipped Apache configuration into Apache
    • sudo ln -s /etc/phpmyadmin/apache.conf /etc/apache2/conf.d/phpmyadmin.conf
    • sudo /etc/init.d/apache2 reload

If you have any kind of doubt please feel free to post them here