Archive for the ‘Linux’ Category
If you want to execute python scripts with Linux you need to add the shebang line: “#! /usr/bin/env python”
It must be added on top of the file.
The shebang will allow you to run the script as any other script. Among the many options to run it, assuming the script name is “script”, one is:
The file must be made executable:
> sudo chmod +x script.py
Assuming we want to print an homogenous array created with the numpy module, a script might include the module import too:
#! /usr/bin/env python import numpy as np array1 = np.array([1,2,3,4]) print(array1) print(type(array1))
It will print the following lines:
[1 2 3 4]
Running “apt-get update” ubuntu complains about missings ppa keys.
In my case I was trying to install Libre Office and the missing key was
I couldn´t find any key running:
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 83FBA1751378B444
The message that I gog in the console was:
gpg: requesting key 83FBA1751378B444 from hkp server keyserver.ubuntu.com
gpgkeys: key 83FBA1751378B444 not found on keyserver
gpg: no valid OpenPGP data found.
gpg: Total number processed: 0
The solution to me was running:
and the I could finally run “apt-get update”.
If you need to convert audio files in another format you can use the tool called “soundconverter”, that you can simply install:
~$ sudo apt-get install soundconverter
Then simply run a command like:
~$ soundconverter -b -m "audio/mpeg" -s ".mp3" /home/laura/cd-wav/*.wav
“-b” stands for batch type
“-m” to specify the mime format.
“-s” to specify the suffix
And move them into another folder eventually:
~$ mv /home/laura/cd-irene/*.mp3 /home/laura/cd-wav.
For more info check the official wiki pages:
Launching sudo apt-get update you might get the NO_PUBKEY issue. Something like:
W: GPG-Fehler: http://ppa.launchpad.net trusty Release: Die folgenden Signaturen konnten nicht überprüft werden, weil ihr öffentlicher Schlüssel nicht verfügbar ist: NO_PUBKEY EFD5FA852F20733F
Well it´s very simple. Just execute the following (specifying the missing public key):
[email protected]:~$ sudo apt-key adv --keyserver.ubuntu.com --recv-keys EFD5FA852F20733F
And then run sudo apt-get update again. The error will disappear.
Lately I’ve purchased a virtual private server hosting (VPS) to deploy my liferay portal. I’ve been assigned a different port number… and I needed to understand the steps to make a ssh connection.
After some hours surfing the web and making experiment, I could make it. So now I’m posting this litte tutorial, for those that want to work by the linux shell B)
Firt of all you need to generate a public and private keys with a cryptographic algorithm:
ssh-keygen -t dsa
I’ve chosen the DSA (digital signature algorithm), but you can choose RSA, etc.
After entering the ssh-keygen command on the shell, under the folder
~/.ssh/ you will find the following files: id_dsa, id_dsa.pub, authorized_keys and known_hosts files.
Make sure that you have all the permissions on the folder and that you’re the only one that can read and write the authorized_keys file:
sudo chmod 600 ~/.ssh/authorized_keys
The system will add your host to the lists of the “known hosts”, when you try to login to the remote server for the first time.
Once your keys have been generated, you need to copy the public key in the “authorized_keys” file:
cp ~/.ssh/id_dsa.pub ~/.ssh/authorized_keys
Then you need to send your public key to the server. Let’s assume that our ssh port number is 12345:
scp -P 12345 ~/.ssh/id_dsa.pub [email protected]:~/.ssh/authorized_keys
The shell will ask you a password:
[email protected]'s password: user's passowrd
Now that you’ve sent your public key to the server you can connect:
ssh -p 12345 [email protected]
After this command you’ll be asked your passphrase password (that you set when you generate the public key),
so you can be authenticated with your private key.
That’s it! 😎
To practise for the LPIC 101 I’ve decided to make a new ext4 file system on a pen drive.
Login as root.
To list all partition on all devices use the following command:
$ fdisk -l
Then format the usb device with the ext4 filesystem.
$ mkfs.ext4 -L usb_laura /dev/sdb1
The Master Boot Record (MBR) is a space of 512 bytes that holds the partition table as well as the stage 1 of the boot loader.
Making a backup of the MBR might be useful in case of damage, as the operative system wouldn’t boot.
Therefore, you can make a copy in your home directory typing:
sudo dd if=/dev/sda of=~/mbr.txt count=1 bs=512
If you type:
sudo cat /dev/sda
you can see that /dev/sda is a binary file. However you can see that the backup is a file called “mbr.txt“.
If you need to restore the MBR you can use the following command:
sudo dd if=~/mbr.txt of=/dev/sda count=1 bs=512
Make a directory called “helloM” in your home dir and edit the following .C file, called “hello.c”:
/*hello.c – The simplest kernel module.*/
#include <linux/module.h> /* Needed by all modules */
#include <linux/kernel.h> /* Needed for KERN_ALERT */
printk("<1>Hello world 1.\n");
// A non 0 return means init_module failed; module can't be loaded.
printk(KERN_ALERT "Goodbye world 1.\n");
To compile this kernel module you need to edit the following “Makefile” (called “Makefile” !):
# We were called by kbuild
obj-m += hello.o
else # We were called from command line
KDIR := /lib/modules/$(shell uname -r)/build
#KDIR := /home/cynove/src/kernel/linux-source-2.6.31
PWD := $(shell pwd)
@echo ' Building target module 2.6 kernel.'
@echo ' PLEASE IGNORE THE "Overriding SUBDIRS" WARNING'+
$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
endif # End kbuild check
######################### Version independent targets ##########################
rm -f -r *.o *.ko .*cmd .tmp* core *.i
Then, within our working folder, type
make, which will process the
Makefile and create a module file,
To install the module,type:
sudo insmod hello.ko
To verify the module has output to the log file in Ubuntu 11.10 type:
You should read the message of the init_module() method, that is “Hello world 1.”
To remove the module, type:
sudo rmmod hello.ko
In the tail of the kern.log you should find “Goodbye world 1.”.
Funny! By these first steps you can make interesting kernel modules!
filesystem: the files and directories (or folders), the method used to store data on the hard drive (such as the ext3 filesystem.
– Windows keeps all the important system files in a single directory C:\
– Linux follows the lead of its UNIX
– Windows and Linux setups are both logical
✓ Linux uses a forward slash (/) between directories, not the backslash (\) that Windows uses. So, the file yum.conf in the directory etc is
✓ Files and directories can have names up to 256 characters long, and these names can contain underscores (_), dashes (-), and dots (.) any-
where within. So my.big.file or my.big_file or my-big-file are all valid filenames.
✓ Upper- and lowercase matter. They have to match exactly. The files yum.conf and Yum.conf are not the same as far as Linux is concerned.
Linux is case-sensitive — it pays attention to the case of each character. Windows, on the other hand, is case-insensitive.
✓ The same filesystem can span multiple partitions, hard drives, and media (such as CD-ROM drives). You just keep going down through
subdirectories, not having to care whether something is on disk A, B, or whatever.
Everything in the Linux filesystem is relative to the root directory — not to be confused with the system Administrator, who is the root user. The root directory is referred to as /, and it is the filesystem’s home base — a doorway into all your files. As such, it contains a relatively predictable set of subdirectories. Each distribution varies slightly in terms of what it puts in the root directory. More or less you can find the following directories.
/bin : Essential commands that everyone needs to use at any time.*
/boot : The information that boots the machine, including your kernel.*
/dev : The device drivers for all the hardware that your system needs to interface with.*
/etc : The configuration files for your system.*
/home : The home directories for each of your users.
/lib : The libraries, or the code that many programs (and the kernel) use.*
/media : A spot where you add temporary media, such as floppy disks and CD-ROMs; not all distributions have this directory.
/mnt : A spot where you add extra filesystem components such as networked drives and items you aren’t permanently adding to your filesystem but that aren’t as temporary as CD-ROMs and floppies.
/opt : The location that some people decide to use (and some programs want to use) for installing new software packages, such as word
processors and office suites.
/proc : Current settings for your kernel (operating system).*
/root : The superuser’s (root user’s) home directory.
/sbin : The commands the system Administrator needs access to.*
/srv : Data for your system’s services (the programs that run in thebackground).*
/sys : Kernel information about your hardware.*
/tmp : The place where everyone and everything stores temporary files.
/usr : A complex hierarchy of additional programs and files.
/var : The data that changes frequently, such as log files and your mail.