Wednesday, June 22, 2016

Apt-Get To Install Package

From Ubuntu Documentation

Introduction to APT

"In the beginning there was the .tar.gz. Users had to compile each program that they wanted to use on their GNU/Linux systems. When Debian was created, it was deemed necessary that the system include a method of managing the packages installed on the machine. The name dpkg was given to this system. Thus the famous 'package' first came into being on GNU/Linux, a while before Red Hat decided to create their own 'rpm' system.
 
A new dilemma quickly took hold of the minds of the makers of GNU/Linux. They needed a rapid, practical, and efficient way to install packages that would manage dependencies automatically and take care of their configuration files while upgrading. Here again, Debian led the way and gave birth to APT, the Advanced Packaging Tool, which has since been ported by Conectiva for use with rpm and has been adopted by some other distributions."
-- From Debian APT HOWTO

Commands

IconsPage/info.png All these commands except the search commands must be run as root or with superuser privileges, see sudo for more information.
  • IconsPage/example.png
    sudo apt-get install ubuntu-desktop 

Installation commands

  • apt-get install <package_name> 
    This command installs a new package.
  • apt-get build-dep <package_name> 
    This command searches the repositories and installs the build dependencies for <package_name>. If the package is not in the repositories it will return an error.
  • aptitude install <package_name>
    Aptitude is an Ncurses viewer of packages installed or available. Aptitude can be used from the command line in a similar way to apt-get. See man aptitude for more information.
  • APT and aptitude will accept multiple package names as a space delimited list. For example:
    apt-get install <package1_name> <package2_name> <package3_name>

auto-apt

  • auto-apt run <command_string>
    When invoked, the auto-apt command automatically installs packages upon missing file access. If a program tries to access a file known to belong in an uninstalled package, auto-apt will install that package using apt-get. This feature requires apt and sudo to work.

  • Auto-apt keeps databases which need to be kept up-to-date in order for it to be effective. This is achieved by calling the commands auto-apt update, auto-apt updatedb and auto-apt update-local. 
  • Usage example
    • IconsPage/example.png You're compiling a program and, all of a sudden, there's an error because it needs a file you don't have. The program auto-apt asks you to install packages if they're needed, stopping the relevant process and continuing once the package is installed.
           # auto-apt run ./configure
      It will then ask to install the needed packages and call apt-get automatically. If you're running X, a graphical interface will replace the default text interface.
    • Maintenance commands

    • apt-get update
      Run this command after changing /etc/apt/sources.list or /etc/apt/preferences . For information regarding /etc/apt/preferences, see PinningHowto. Run this command periodically to make sure your source list is up-to-date. This is the equivalent of "Reload" in Synaptic or "Fetch updates" in Adept.
    • apt-get upgrade
      This command upgrades all installed packages. This is the equivalent of "Mark all upgrades" in Synaptic.
    • apt-get dist-upgrade
      The same as the above, except add the "smart upgrade" checkbox. It tells APT to use "smart" conflict resolution system, and it will attempt to upgrade the most important packages at the expense of less important ones if necessary.
      IconsPage/note.png "apt-get dist-upgrade" does not perform distribution upgrade. See [http://www.ubuntu.com/getubuntu/upgrading upgrading] for more information.
    • apt-get check
      This command is a diagnostic tool. It does an update of the package lists and checks for broken dependencies.
    • 
      
    •  
    • apt-get -f install
      This command does the same thing as Edit->Fix Broken Packages in Synaptic. Do this if you get complaints about packages with "unmet dependencies".

    • apt-get autoclean
      This command removes .deb files for packages that are no longer installed on your system. Depending on your installation habits, removing these files from /var/cache/apt/archives may regain a significant amount of diskspace.

    • apt-get clean
      The same as above, except it removes all packages from the package cache. This may not be desirable if you have a slow Internet connection, since it will cause you to redownload any packages you need to install a program.
      • The package cache is in /var/cache/apt/archives . The command
        du -sh /var/cache/apt/archives
        will tell you how much space cached packages are consuming.
      •  
    • dpkg-reconfigure <package_name>
      Reconfigure the named package. With many packages, you’ll be prompted with some configuration questions you may not have known were there.
      • IconsPage/example.png For example:

List of Basic Commands in Ubuntu

sudo: Executing Commands with Elevated Privileges

  • Most of the following commands will need to be prefaced with the sudo command. This elevates privileges to the root-user administrative level temporarily, which is necessary when working with directories or files not owned by your user account. When using sudo you will be prompted for your password. Only users with sudo (administrative) privileges will be able to use this command. You should never use normal sudo to start graphical applications as root. (Please see RootSudo for more information on using sudo correctly.)

File & Directory Commands

  • The tilde (~) symbol stands for your home directory. If you are user, then the tilde (~) stands for /home/user
  • pwd: The pwd command will allow you to know in which directory you're located (pwd stands for "print working directory"). Example: "pwd" in the Desktop directory will show "~/Desktop". Note that the GNOME Terminal also displays this information in the title bar of its window. A useful gnemonic is "present working directory."
  • ls: The ls command will show you ('list') the files in your current directory. Used with certain options, you can see sizes of files, when files were made, and permissions of files. Example: "ls ~" will show you the files that are in your home directory.
  • cd: The cd command will allow you to change directories. When you open a terminal you will be in your home directory. To move around the file system you will use cd. Examples:
    • To navigate into the root directory, use "cd /"
    • To navigate to your home directory, use "cd" or "cd ~"
    • To navigate up one directory level, use "cd .."
    • To navigate to the previous directory (or back), use "cd -"
    • To navigate through multiple levels of directory at once, specify the full directory path that you want to go to. For example, use, "cd /var/www" to go directly to the /www subdirectory of /var/. As another example, "cd ~/Desktop" will move you to the Desktop subdirectory inside your home directory.
  • cp: The cp command will make a copy of a file for you. Example: "cp file foo" will make an exact copy of "file" and name it "foo", but the file "file" will still be there. If you are copying a directory, you must use "cp -r directory foo" (copy recursively). (To understand what "recursively" means, think of it this way: to copy the directory and all its files and subdirectories and all their files a
    • and subdirectories of the subdirectories and all their files, and on and on, "recursively")
    • mv: The mv command will move a file to a different location or will rename a file. Examples are as follows: "mv file foo" will rename the file "file" to "foo". "mv foo ~/Desktop" will move the file "foo" to your Desktop directory, but it will not rename it. You must specify a new file name to rename a file.
      • To save on typing, you can substitute '~' in place of the home directory.
      • Note that if you are using mv with sudo you can use the ~ shortcut, because the terminal expands the ~ to your home directory. However, when you open a root shell with sudo -i or sudo -s, ~ will refer to the root account's home directory, not your own.
    • rm: Use this command to remove or delete a file in your directory.
    • rmdir: The rmdir command will delete an empty directory. To delete a directory and all of its contents recursively, use rm -r instead.
    • mkdir: The mkdir command will allow you to create directories. Example: "mkdir music" will create a directory called "music".
    • man: The man command is used to show you the manual of other commands. Try "man man" to get the man page for man itself. See the "Man & Getting Help" section down the page for more information.
    • sudo: The sudo command is used to perform file operations on files that the Root User would only be allowed to change. An example would be trying to move one of your documents that another user accidentally moved to / back to your documents directory. Normally, to move the file, you would type mv /mydoc.odt ~/Documents/mydoc.odt, but you are not allowed to modify files outside of your home directory. To get around this, you would type sudo mv /mydoc.odt ~/Documents/mydoc.odt. This will successfully move the file back to its correct location, provided that you are not a standard user, who has less (administrative) ability than an administrator. Be aware, though, that by using the sudo command, you need to be extra careful. It is easier to damage your system by using the sudo command. For more information about the sudo command, click here

      Running a File Within a Directory

      So you've decided to run a file using the command-line? Well... there's a command for that too!
    • ./filename.extension
    After navigating to the file's directory, this command will enable any Ubuntu user to run files compiled via GCC or any other programming language. Although the example above indicates a file name extension, please notice that, differently from some other operating systems, Ubuntu (and other Linux-based systems) do not care about file extensions (they can be anything, or nothing). Keep in mind that the 'extension' will vary depending upon the language the source code is written in. Also, it is not possible, for compiled languages (like C and C++) to run the source code directly -- the file must be compiled first, which means it will be translated from a human-readable programming language to something the computer can understand. Some possible extensions: ".c" for C source, ".cpp" for C++, ".rb" for Ruby, ".py" for Python, etc. Also, remember that (in the case of interpreted languages like Ruby & Python) you must have a version of that language installed on Ubuntu before trying to run files written with it.
    Finally, the file will only be executed if the file permissions are correct -- please see the FilePermissions help page for details.

    System Information Commands

  • df: The df command displays filesystem disk space usage for all mounted partitions. "df -h" is probably the most useful - it uses megabytes (M) and gigabytes (G) instead of blocks to report. (-h means "human-readable")
  • du: The du command displays the disk usage for a directory. It can either display the space used for all subdirectories or the total for the directory you run it on. Example:
user@users-desktop:~$ du /media/floppy
1032    /media/floppy/files
1036    /media/floppy/
user@users-desktop:~$ du -sh /media/floppy
1.1M    /media/floppy/
  • -s means "Summary" and -h means "Human Readable"
  • free: The free command displays the amount of free and used memory in the system. "free -m" will give the information using megabytes, which is probably most useful for current computers.
  • top: The top ('table of processes') command displays information on your Linux system, running processes and system resources, including CPU, RAM & swap usage and total number of tasks being run. To exit top, press "q"

    • uname -a: The uname command with the -a option prints all system information, including machine name, kernel name & version, and a few other details. Most useful for checking which kernel you're using.
    • lsb_release -a: The lsb_release command with the -a option prints version information for the Linux release you're running, for example:
    user@computer:~$ lsb_release -a
    No LSB modules are available.
    Distributor ID: Ubuntu
    Description:    Ubuntu 11.10
    Release:        11.10
    Codename:       oneiric
  • ip addr reports on your system's network interfaces.

Adding A New User

  • "adduser newuser" command will create a new general user called "newuser" on your system, and to assign a password for the newuser account use "passwd newuser".

Options

The default behaviour for a command may usually be modified by adding a --option to the command. The ls command for example has an -s option so that "ls -s" will include file sizes in the listing. There is also a -h option to get those sizes in a "human readable" format.
Options can be grouped in clusters so "ls -sh" is exactly the same command as "ls -s -h". Most options have a long version, prefixed with two dashes instead of one, so even "ls --size --human-readable" is the same command.

"Man" and getting help

Warning /!\ man command, info command and command --help are the most important tools at the command line.
  • Nearly every command and application in Linux will have a man (manual) file, so finding them is as simple as typing "man "command"" to bring up a longer manual entry for the specified command. For example, "man mv" will bring up the mv (move) manual.
    Move up and down the man file with the arrow keys, and quit back to the command prompt with "q".
    "man man" will bring up the manual entry for the man command, which is a good place to start!
    "man intro" is especially useful - it displays the "Introduction to user commands" which is a well-written, fairly brief introduction to the Linux command line.
    There are also info pages, which are generally more in-depth than man pages. Try "info info" for the introduction to info pages.
    Some software developers prefer info to man (for instance, GNU developers), so if you find a very widely used command or app that doesn't have a man page, it's worth checking for an info page.
    Virtually all commands understand the -h (or --help) option which will produce a short usage description of the command and it's options, then exit back to the command prompt. Try "man -h" or "man --help" to see this in action.
    Caveat: It's possible (but rare) that a program doesn't understand the -h option to mean help. For this reason, check for a man or info page first, and try the long option --help before -h.

    Searching for man files

    If you aren't sure which command or application you need to use, you can try searching the man files.
  • man -k foo will search the man files for foo. Try "man -k nautilus" to see how this works.
    • Note that this is the same as doing apropos command.
  • man -f foo searches only the titles of your system's man files. Try "man -f gnome", for example.
    • Note that this is the same as doing whatis command.

Friday, May 20, 2016

Numpy for Signal and Image Processing

Open jupyter notebook in conda

 %matplotlib inline  #enable matplotlib for interactive plotting,  in a same notebook (inline)

 import matplotlib.pyplot as plt # for plotting

import numpy as np    # for array processing

  1. To plot a Ramp Signal
  
         x=np.linspace(0,3,20)
         y=np.linspace(0,9,20)
          plt.plot(x,y)
          plt.plot(x,y,'o')

 

Cosine Signal Generation:

    time=np.linspace(0,2*np.pi,100)
    cosine=np.cos(time)

    plt.plot(time,cosine)
   
 

Tuesday, May 17, 2016

Anaconda


1. First Check List of packages Installed in Anaconda Typing : conda list, in the  terminal.

2. To install a new package, type, conda install packagename

3.Use Spyder IDE to develop a code