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

Tuesday, April 28, 2015

Convert rmvb to avi

To convert rmvb to avi, you may try:


#!/bin/bash
cd /home/username/films
for file in *.rmvb; do
  mencoder "$file" -oac mp3lame -ovc lavc -o "/home/username/films/avifilms/${file%.rmvb}.a$
done

where, the videos you want to convert is in "/home/username/films"

LifeHacker - find/burn subtitle

To find and burn subtitles to a movie, you may try lifehacker

please follow the link:
http://lifehacker.com/how-to-get-subtitles-on-your-digital-movies-489535336

Friday, November 21, 2014

Kernel space and User Space


Linux/GNU History

  •  Unix was invented.
    • It was written in assembly (not portable)
    • When changing the target, the assembly instruction set is different, so porting of Unix was a long story
    • Inventors of Unix invented C, and wrote the Unix in C (Portable)
    • Now, all you need when changing the target, is to make its compiler, which map C instructions into assembly instruction
  • GNU


    • Richard Stallman, an activist who called for free SW, decided to make a Unix like OS, but open source.
      It is GNU (GNU Not Unix)
    • GNU project started with gcc (GNU C Compiler), gdb (GNU debugger), and other utilities.
    • GNU project made the GPL (GNU public license), which implies that any one that will use a GPL licensed SW shall make his product open source

  • Linux
    • Linus invented an open source kernel.
    • GNU decided no to build another kernel, just integrating Linus kernel with GNU tool chain (gcc, gdb, ..etc) and GNU apps and utilities (GIMP, gzip, ...etc), Linux OS is launched
  •  There are 2 GUIs for Linux:
      • KDE: better, but not open source
      • GNOME:
        Open Source.

Thursday, November 13, 2014

Torrents

I installed bit torrent lately, to download torrent videos.
This went as follows:

$sudo apt-get install bittorrent
$sudo apt-get install Deluge
$deluge

Where deluge is a native, full-featured bittorrent client for Gnome.

For more info, check the link

Saturday, November 1, 2014

Swap Memory

Swap memory is a partition in your hard disk, used as additional RAM.

Of course it is much slower than the RAM.

To create swap on Linux

  • create a partition for swap .. for ex it is sda6
  • in bash
    mkswap dev/sda6
    swapon -a

Make home in a separate partition

1. from gparted make a new "ext4" partition
2. in bash
mkdir /mnt/tmp
sudo mount /dev/sda2 /mnt/tmp
    assuming that sda2 is the new partition
3. copy your old home to /mnt/tmp
Now, your home is copied to the new partition
4. Delete your old /home
5. in your fstub, make a new entry that mounts the new partition to /home
6. apply fstab by making a restart

nano /etc/fstab
you will find a line that describes the path of your root "/"
add a similar line for home

Linux Shell

Shell:
the shell is a program that takes your commands from the keyboard and gives them to the operating system to perform.

Steve Bourne invented the shell, so its name is Bourne shell.

An enhanced version of Bourne shell is “Bourne Again SHell” (Bash).

xterm, rxvt, konsole,kvt, gnome-terminal, nxterm, and eterm. These all are terminal emulators that put a window up and let you interact with the shell.

Tree:
In windows, different partitions have different letters (C:, D:), hence different trees.
In Linux, only one tree, the first directory is the root directory “/”
Using the “mount” command, each partition is assigned to a certain path into this unique tree.

Shell Commands:
pwd: print working directory
ls: list all the files and directories
    • ls
  • List the files in the working directory
  • ls /bin
  • List the files in the /bin directory (or any other directory you care to specify)
  • ls -l
  • List the files in the working directory in long format
  • ls -l /etc /bin
  • List the files in the /bin directory and the /etc directory in long format
  • ls -la ..
  • List all files (even ones with names beginning with a period character, which are normally hidden) in the parent of the working directory in long format

  • cd “path”: change working directory to “path”
      • cd: change working directory to “home directory”, which is usually “/home/your_user_name”
      •     cd .. : change directory to the parent directory
      •     cd ~user_name: change working directory to the home directory of this user.
    less: view text files, while viewing the file:
      • Page Up or b
  • Scroll back one page
  • Page Down or space
  • Scroll forward one page
  • G
  • Go to the end of the text file
  • 1G
  • Go to the beginning of the text file
  • /characters
  • Search forward in the text file for an occurrence of the specified characters
  • n
  • Repeat the previous search
  • q
  • Quit

  • file: classify a file's contents
    ln: create a symbolic link file
    a symbolic link file is a file that points to another file
    Ex: ln [OPTION]... TARGET [LINK_NAME]

    File/Dir Commands:
    cp: copy files and directories
    mv: move or rename files and directories
    rm: remove files and directories
    mkdir: create directories

    IO redirection:
    Redirect the output to a file:
      • “>” to overwrite
      • “>>” to append
    Redirect output to be input of a command:
      • “|”: pipe. The following commands (Filters) are commonly used with pipes
        • sort: sort the lines of the input alphabetically
        • uniq: remove duplicate lines from input
        • fmt: format the input into neat paragraphs
        • pr: split the input into pages
        • lpr: send the input to the printer

    Permissions:
    • Permissions:

    permissions_diagram.gif
    • chmod: modify file access rights
      • chmod 644 filename_or_directoryname
      • 6 4 4: 110 100 100: rw- r-- r--: owner can read and write - grp and others can read only
    • su: temporarily become the superuser (superuser can change the file owner)
    • sudo: Super User Do command:
      • sudo stop lightdm: exit the X server
      • sudo start lightdm: start the X server
      • ctrl+alt+F1: Go to terminal
      • ctrl+alt+F7: Go to X server
    • chown: change file ownership
    • chgrp: change a file's group ownership
    Ex on file permissions:
      • type: less -l /bin/bash.exe
        you will get the following line on the shell:
        -rwx------    1 Ahmad    UsersGrp    651264 Sep  6 16:11 /bin/bash.exe
        permissions        |owner  |  owner group   |         | modification date|file name   

    Job Control:
    • ps: list the processes running on the system (like: ctrl+alt+del)
    • kill: send a signal to one or more processes (usually to "kill" a process)
    • jobs: an alternate way of listing your own processes
    • bg: put a process in the background
    • fg: put a process in the foreground
    • Ex: how to kill a process:
      • get the process PID through ps command
      • type: kill pid
      • if still not killed use: kill -SIGKILL pid

    Install ".tar.gz" file

    1. Extract the zipped file
    2. Open the terminal, and change the directory to the directory where you extracted the zipped file.
    3. search for a file named “install”, “install.txt” or “readme”.
      Open it.
      It will contain the steps of installation.
    4. Usually the steps of installation are:
      1. ./configure
      2. make
      3. sudo make install

    Shell Script

    What are shell scripts?
    Scripts are collections of commands that are stored in a file. The shell can read this file and act on the commands as if they were typed at the keyboard.

    To successfully write a shell script, you have to do three things:
    1. Write a script
    2. Give the shell permission to execute it
    3. Put it somewhere the shell can find it

    1. Write the script

    The first line of the script is important. This is a special clue given to the shell indicating what program is used to interpret the script. In this case, it is /bin/bash.

    #!/bin/bash
    # My first script

    echo "Hello World!"

    2. Setting permissions:

    chmod 755 my_script

    The "755" will give you read, write, and execute permission. Everybody else will get only read and execute permission.

    3. Put it somewhere the shell can find it

    instead of calling the script via its complete path, you may do the following:
    A. put all your scripts in a directory called "bin", under your home directory
    B. add this directory to your PATH variable, by typing:
    export PATH=$PATH:/home/bin

    The PATH variable contains some paths, when a command is typed, the shell search these paths for the program with the name you typed.

    Type of commands:

    To know the type of a command you can use:

    Type command_name

    We have 4 types of commands:
    1. Commands implemented in the shell. (Pwd - ls - ...)
    2. Executables
    3. Aliases
    You can create an alias by typing:
    Alias l = "ls -l"
    Then you can use this alias by typing:
    l
    This will make the same output like "ls -l"
    4. Shell functions

    function today {
       echo "Today's date is:"
       date +"%A, %B %-d, %Y"
    }

    The above function is a shell function that can be executed by typing:
    today

    Aliases and shell functions can be defined in the shell by typing the definition as above. They will be undefined when you close the shell.
    They also can be defined in the file ".bash_profile" which is executed each time you log in. And the aliases and functions defined in it will not be undefined. This file exists in your home directory.
    The better practice than defining your aliases and functions in ".bash_profile" is to define them in ".bashrc", which is in your home directory and is included inside ".bash_profile".

    Variables vs Environment Variables:

    Variables are defined as follows:
    var_name=value
    And used as follows:
    $var_name
    A variable will be undefined when the shell is closed.

    Environment variable is a variable that is defined by some shell scripts that run when the user log on. They are not undefined when you close the shell.
    You can list the env vars by typing:
    printenv

    When a variable is not expected to be changed (expected to be a constant) the convention is to write its name in uppercase. Environment variables names are usually written in uppercase as their values are rarely changed.

    To know more about a command:

    1. man command
    2. command --help
    3. Get the path of the script and read it
    which command (the path will appear)
    strings comd_path (returns the readable parts of the file content)
    And you can read the file itself

    Substitution:

    1. $var_nam
    This will tell the shell to substitute the variable name with the variable value
    2. $(command)
    This will tell the shell to substitute the command with its result (output)

    Quoting:

    Single quotes limit the substitution:
    echo "My host name is $HOSTNAME."
    My host name is linux box.

    echo 'My host name is $HOSTNAME.'
    My host name is $HOSTNAME.

    While double quotes limit the wildcards. Try (echo *) and (echo "*").

    A backslash is a special quoting character that ignores special characters. It is also called escape character.

    sudo vs gksudo:

    sudo is a command that allows a permitted user to perform some root processes, by entering the password of the root.
    This is to guarantee that no one except the root will make critical processes such as changing permisions, install/uninstall applications.

    gksudo is a front end for sudo, that opens gui apps, that needs superuser rights, without running X terminal emulator


    How to send email from bash?

    sudo apt-get install mutt

    Edit and add this to your ~/.muttrc file:


    set imap_user = "username@gmail.com"
    set imap_pass = "password"

    set smtp_url = "smtp://username@smtp.gmail.com:587/"
    set smtp_pass = "password"
    set from = "username@gmail.com"
    set realname = "Your Real Name"

    set folder = "imaps://imap.gmail.com:993"
    set spoolfile = "+INBOX"
    set postponed="+[Gmail]/Drafts"

    set header_cache=~/.mutt/cache/headers
    set message_cachedir=~/.mutt/cache/bodies
    set certificate_file=~/.mutt/certificates

    set move = no


    Start mutt once and send a message, setting accepting certificates to "always"

    Then you can send a message via the command line:

    echo "Message body" | mutt -s "Subject" phonenumber@carrier.com