Linux for newbies, free pdf download
Check my slides about the introduction to gnu/linux OS in pdf file!
Check my slides about the introduction to gnu/linux OS in pdf file!
There is no .exe equivalent in linux. Executables are denoted by file permissions, not extensions. In directories such as /etc, many files do not use a file extension because it is in /etc it is assumed to be a configuration (ASCII text) file.
Ex. “RELEASE NOTE” is the correct name for a file (remember that it’s case sensitive).
The following list shows the most commons file extensions for linux:
.a : a static library ;
.au : an audio file ;
.bin : a) a binary image of a CD (usually a .cue file is also included); b) represents that the file is binary and is meant to be executed ;
.bz2 : A file compressed using bzip2 ;
.c : A C source file ;
.conf : A configuration file. System-wide config files reside in /etc while any user-specific configuration will be somewhere in the user’s home directory ;
.cpp : A C++ source file ;
.deb : a Debian Package;
.diff : A file containing instructions to apply a patch from a base version to another version of a single file or a project (such as the linux kernel);
.dsc: a Debian Source information file ;
.ebuild : Bash script used to install programs through the portage system. Especially prevalent on Gentoo systems;
.el : Emacs Lisp code file;
.elc : Compiled Emacs Lisp code file;
.gif : a graphical or image file;
.h :a C or C++ program language header file;
.html/.htm : an HTML file;
.iso : A image (copy) of a CD-ROM or DVD in the ISO-9660 filesystem format;
.jpg : a graphical or image file, such as a photo or artwork;
.ko : The kernel module extension for the 2.6.x series kernel;
.la : A file created by libtool to aide in using the library;
.lo : The intermediate file of a library that is being compiled;
.lock : A lock file that prevents the use of another file;
.log : a system or program’s log file;
.m4 : M4 macro code file;
.o : 1) The intermediate file of a program that is being compiled ; 2) The kernel module extension for a 2.4 series kernel ; 3)a program object file;
.pdf : an electronic image of a document;
.php : a PHP script;
.pid : Some programs write their process ID into a file with this extention;
.pl : a Perl script;
.png : a graphical or image file;
.ps : a PostScript file; formatted for printing;
.py : a Python script;
.rpm : an rpm package. See Distributions of Linux for a list of distributions that use rpms as a part of their package management system;
.s : An assembly source code file;
.sh : a shell script;
.so : a Shared Object, which is a shared library. This is the equivalent form of a Windows DLL file;
.src : A source code file. Written in plain text, a source file must be compiled to be used;
.sfs : Squashfs filesystem used in the SFS Technology;
.tar.bz2 , tbz2, tar.gz : a compressed file per File Compression;
.tcl : a TCL script;
.tgz : a compressed file per File Compression. his may also denote a Slackware binary or source package;
.txt : a plain ASCII text file;
.xbm : an XWindows Bitmap image;
.xpm : an image file;
.xcf.gz, xcf : A GIMP image (native image format of the GIMP);
.xwd : a screenshot or image of a window taken with xwd;
.zip :extension for files in ZIP format, a popular file compression format;
.wav : an audio file.
Although rar and zip files are supported, linux has its on archive file extensions too.
When you’re looking for software or when you need to save yourself some space, you can find files with the following extension:
A tarball is a bunch of files (and possibly directories) packaged together in a .tar file and compressed using the gzip utility; the
tarball then contains the .tar.gz extension.
.tar : A bunch of files bundled together
.tar.bz2 : A tarball (a .tar file inside a .bz2 file. )
.tar.gz : A traditional tarball, which is a .tar file inside a .gz file.
Program (shell command): tar, bzip2, gunzip,gzip.
Other archive extensions are: .deb, and .rpm
.deb : All the files related to an application bundled together using a Debian-specific format, used in Ubuntu and gOS.
Program (shell command): dpkg, apt-get, zipper (for open suse distributions).
.rpm : All the files related to a single application bundled together using a format designed by Red Hat and used in Fedora.
Program (shell command): rmp, yum
Let’s analyze the following perl scripta “cinema.pl”, to create and populate a simple database about movies, and “query_hollywood.pl” to execute a simple SELECT-FROM-WHERE query on it.
—————————————cinema.pl————————————————————
#!/usr/bin/perl -w
use DBI;
use strict;
# CONFIG VARIABLES
my $platform = “SQLite”;
my $database = “hollywood.db”;
my $host = “localhost”;
my $port = “3306”;
my $user = “username”;
my $pw = “password”;
# DATA SOURCE NAME
my $dsn = “dbi:$platform:$database:$host:$port”;
# PERL DBI CONNECT
my $dbh = DBI->connect($dsn, $user, $pw) or die “Cannot connect: $DBI::errstr”;
# creating the “hollywood” database
$dbh->do(“CREATE TABLE IF NOT EXISTS actors(aid integer primary key, name text)”);
$dbh->do(“CREATE TABLE IF NOT EXISTS movies(mid integer primary key, title text)”);
$dbh->do(“CREATE TABLE IF NOT EXISTS actors_movies(id integer primary key, mid integer, aid integer)”);
#populating “actors” table
$dbh->do(“INSERT INTO actors(name) VALUES(‘Philip Seymour Hofman’)”);
$dbh->do(“INSERT INTO actors(name) VALUES(‘Kate Shindle’)”);
$dbh->do(“INSERT INTO actors(name) VALUES (‘Kelci Stephenson’)”);
$dbh->do(“INSERT INTO actors(name) VALUES(‘Al Pacino’)”);
$dbh->do(“INSERT INTO actors(name) VALUES(‘Gabrielle Anwar’)”);
$dbh->do(“INSERT INTO actors(name) VALUES(‘Patricia Arquette’)”);
$dbh->do(“INSERT INTO actors(name) VALUES(‘Gabriel Byrne’)”);
$dbh->do(“INSERT INTO actors(name) VALUES(‘Max von Sydow’)”);
$dbh->do(“INSERT INTO actors(name) VALUES(‘Ellen Burstyn’)”);
$dbh->do(“INSERT INTO actors(name) VALUES(‘Jason Miller’)”);
#populating “movies” table
$dbh->do(“INSERT INTO movies VALUES(1,’Capote’)”);
$dbh->do(“INSERT INTO movies VALUES(2,’Scent of a woman’)”);
$dbh->do(“INSERT INTO movies VALUES(3,’Stigmata’)”);
$dbh->do(“INSERT INTO movies VALUES(4,’Exorcist’)”);
$dbh->do(“INSERT INTO movies VALUES(5,’Hamsun’)”);
#populating “actorsMovies” table
$dbh->do(“INSERT INTO actors_movies VALUES(1,1,1)”);
$dbh->do(“INSERT INTO actors_movies VALUES(2,2,1)”);
$dbh->do(“INSERT INTO actors_movies VALUES(3,3,1)”);
$dbh->do(“INSERT INTO actors_movies VALUES(4,4,2)”);
$dbh->do(“INSERT INTO actors_movies VALUES(5,5,2)”);
$dbh->do(“INSERT INTO actors_movies VALUES(6,6,3)”);
$dbh->do(“INSERT INTO actors_movies VALUES(7,7,3)”);
$dbh->do(“INSERT INTO actors_movies VALUES(8,8,4)”);
$dbh->do(“INSERT INTO actors_movies VALUES(9,9,4)”);
$dbh->do(“INSERT INTO actors_movies VALUES(10,10,4)”);
$dbh->do(“INSERT INTO actors_movies VALUES(11,8,5)”);
print qq{“Hollywood” database created! \n };
$dbh->disconnect;
—————————————————query_hollywood.pl———————————————
#!/usr/bin/perl -w
use DBI;
use strict;
# CONFIG VARIABLES
my $platform = “SQLite”;
my $database = “hollywood.db”;
my $host = “localhost”;
my $port = “3306”;
my $user = “username”;
my $pw = “password”;
# DATA SOURCE NAME
my $dsn = “dbi:$platform:$database:$host:$port”;
# PERL DBI CONNECT
my $dbh = DBI->connect($dsn, $user, $pw) or die “Cannot connect: $DBI::errstr”;
# EXECUTE THE QUERY
my $query = “SELECT actors.name , movies.title FROM actors,movies,actors_movies WHERE actors.aid=actors_movies.aid and
movies.mid=actors_movies.mid”;
my $sth=$dbh->selectall_arrayref($query);
print “Actor Movie \n” ;
print “====================== ====================\n”;
foreach my $row (@$sth) {
my ($name, $title) = @$row;
### Print out the table metadata…
printf “%-23s %-23s \n”, $name, $title;
}
$dbh->disconnect;
—————————————————————————————–
Make the perl scripts executable like:
$ sudo chmod +x script.pl
And run them liket:
$ ./script.pl
The result of the query is:
Actor Movie
==================== ====================
Philip Seymour Hofman Capote
Philip Seymour Hofman Scent of a woman
Philip Seymour Hofman Stigmata
Kate Shindle Exorcist
Kate Shindle Hamsun
Very nice script, isn’t it?
I guess the DBI deserves further attention…
Let’s go on mastering our sqlite3 knowledge.
SQLite database is really just a file: a backup it’s as simple as copying one file.
The .dump command shows information about all the changes performed onto the database. Less pieces of information to the hidden file can be found in your home/user typing: $ ~/.sqlite_history.
$ sqlite3 test.db “.dump”
The result is:
PRAGMA foreign_keys=OFF;
BEGIN TRANSACTION;
CREATE TABLE n(id INTEGER PRIMARY KEY, f TEXT, l TEXT);
INSERT INTO “n” VALUES(1,’linus’,’torvalds’);
INSERT INTO “n” VALUES(2,’richard’,’stallman’);
COMMIT;
If you want to backup the database in a new file, you can specify a name (ex. “dbbackup”):
$ $ sqlite3 test.db ‘.dump’ > dbbackup
The contents of the backup can be modified.
For example you can filter and pipe it to another database. Below, table “n” is changed to “people” with the sed command, and it is piped into the “computer_pioneers” database.
$ sqlite3 test.db “.dump”|sed -e s/n/people/|sqlite3 computer_pioneers.db
The contect is the same:
$sqlite3 computer_pioneers.db “select * from people”;
Sqlite is useful to create a database (one file, .db extension) used to store configuration data, used Miicrosoft, Skype, Banshee… Smart Phone applications….
The file extension .db stands for a whole database: it’s made by the software C library called Sqlite…
This is a great opportunity to learn about SQLITE and the Perl scripting languages… great, don’t you think?
Let’s kill two birds with a stone!
Install Sqlite3 and follow me:
On UBUNTU, DEBIAN, etc:
$ sudo apt-get install sqlite3
On OPEN-SUSE:
$ sudo zypper install sqlite3
On REDHAT, CentOS, or FEDORA:
$ yum install SQLite3
BASH EXAMPLE
Let’s create an example: a database called “test.db” by the (unix) shell by the following command:
:~$ sqlite3 test.db “create table if not exists user(id INTEGER PRIMARY KEY, name TEXT, surname TEXT);”
Let’s fill it:
:~$ sqlite3 test.db “insert into user (name, surname) values (‘linus’,’torvalds’);”
:~$ sqlite3 test.db “insert into user(name,surname) values(‘richard’, ‘stallman’)”;
To check it out:
:~$sqlite3 test.db “select * from n”;
The result is:
1|linus|torvalds
2|richard|stallman
Alternatively you can create a database entering the sqlite3 enviroment
$ sqlite3 test.db
SQLite version 3.0.8
Enter “.help” for instructions
Enter SQL statements terminated with a “;”
sqlite>
In the sqlite3 enviroment you can use pure SQL statements to work with your database (in this case the test.db).
You can even change a few default settings to make the ouput of the commands look better. For example the column .mode and the .headers commands.They will last you exit the SQLite shell or change them to something else.
sqlite> .mode col
sqlite> .headers on
To see all the tables and views type:
sqlite> .tables
To see the databases that are currently open use the .databases command. It will show the main and temp databases and where they are on the system:
sqlite> .databases
To exit type .quit or .exit:
sqlite> .quit
Anyway it’s better to work in the shell prompt directly, that allows you to run bash scripts.
In this example the prompt is in your home/user directory. Check it out by the pwd command if you’re not sure…
PERL EXAMPLE
Make a file called test.pl :
$ touch test1.pl
Use an editor(ex. gedit under ubuntu and opensuse) or the cat test1.pl command to fill it with the following script:
#!/usr/bin/perl -w
use DBI;
use strict;
my $db = DBI->connect(“dbi:SQLite:test.db”, “”, “”) or die “couldn’t connect to db”.DBI->errstr;
$db->do(“CREATE TABLE IF NOT EXISTS user (id INTEGER PRIMARY KEY, name TEXT, surname TEXT)”);
$db->do(“INSERT INTO user\(name, surname) VALUES ( ‘linus’, ‘torvalds’)”);
$db->do(“INSERT INTO user\(name, surname) VALUES ( ‘richard’, ‘stallman’)”);
my $all = $db->selectall_arrayref(“SELECT * FROM USER”);
foreach my $row (@$all) {
my ($id, $name, $surname) = @$row;
print “$id|$name|$surname \n”;
}
$db->disconnect;
Alternatively you can make the file directly by the shell:
$ cat > test.pl
.. perl script content…
Type Ctlr+C to close the file and exit.
Now check the file content:
$> cat test.pl
Make the perl script executable:
$ sudo chmod +x test.pl
Then run the perl script simply:
$ ./test.pl
The result is:
1|linus|torvalds
2|richard|stallman
In the same folder where the script lies, you can find a file called “test.db”. That’s the Sqlite database. Just one file.
Yeah! So we’ve learned some Perl and SQLite, right?
Banshee is the standard media player software in Ubuntu 11.04 and OpenSuse 11.4.
It’s a cross-platform application, but it’s basically currently running on “unixoide” operative systems only.
It’s written in C# and and it’s build upon Mono and GTK+ (GIMP Toolkit) and the GStreamer frawework, that is used to create media handling components like audio and video playback, recording, streaming and editing.
With Banshee you can play music, videos and webradios, import and put media on your Android, Apple, or other player — or import from it. You can even purchase music from the integrated Amazon MP3 Store.
As I have a subscriptio to LinuxMagazin (german version), I’ve found a very interesting article about it. Even a mini-tutorial online: http://www.linux-magazin.de/plus/2011/06/Perl-Snapshot-Linux-Magazin-2011-06
So I’ve just discovered that in the hidden folder .config/banshee-1/ you can find the file called “banshee.db”.
The extension .db stands for a whole database: it’s made by the software C library called Sqlite…
Linux Day 2011 will be held on October the 23th.
As a member of the Cassino Linux User Group, I’m organizing the cultural event with the other guys of the group
Call for Papers Linux day 2011
Check it out!
Seamless Theme Keith, made by Altervista
Create a website and earn with Altervista - Disclaimer - Report Abuse - Privacy Policy - Customize advertising tracking