Updated on | #bash, #git, #aptitude | 0 User comments

Ubuntu and Debian commands - GIT, Filesystem and User

This is my Ubuntu and Debian command line reference to make the system more smoothly.

Filesystem

  1. ln -s [[to]] [[from]]

For example: ln -s /home/test /etc/test

Parse a PHP variable in Bash

You have a php-file (e.g. test.php) where a variable like "$test" is used:

  1. <?php
  2. $test = "jup";
  3. ?>

You can parse this variable in a shell script with:

  1. #!/bin/bash
  2. TEST=`cat test.php | grep 'test' | cut -d \' -f 2`
  3. echo $TEST
jup

No space left on device

I'm using a small boot partition to optimize the boot process, that increases computer's or NAS performance. In other words, I don't like to have x old kernel packages on my hard disk. On the other side, from time to time I get error message while the update process as it shown below. Here you can find a small guide how you can clean your boot partition:

  1. sudo apt-get update
  2. sudo apt-get upgrade
Fehler traten auf beim Bearbeiten von:
 linux-image-extra-3.13.0-45-generic
 linux-image-generic
E: Sub-process /usr/bin/dpkg returned an error code (1)
Ein Paket konnte nicht installiert werden. Versuch, dies zu lösen:
linux-image-extra-3.13.0-45-generic (3.13.0-45.74) wird eingerichtet ...
run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 3.13.0-45-generic /boot/vmlinuz-3.13.0-45-generic
run-parts: executing /etc/kernel/postinst.d/dkms 3.13.0-45-generic /boot/vmlinuz-3.13.0-45-generic
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 3.13.0-45-generic /boot/vmlinuz-3.13.0-45-generic
update-initramfs: Generating /boot/initrd.img-3.13.0-45-generic

gzip: stdout: No space left on device
cpio: Fehler beim Schreiben: Datenübergabe unterbrochen (broken pipe)
E: mkinitramfs failure cpio 1 gzip 1
update-initramfs: failed for /boot/initrd.img-3.13.0-45-generic with 1.
run-parts: /etc/kernel/postinst.d/initramfs-tools exited with return code 1
dpkg: Fehler beim Bearbeiten des Paketes linux-image-extra-3.13.0-45-generic (--configure):
 Unterprozess installiertes post-installation-Skript gab den Fehlerwert 1 zurück
dpkg: Abhängigkeitsprobleme verhindern Konfiguration von linux-image-generic:
 linux-image-generic hängt ab von linux-image-extra-3.13.0-45-generic; aber:
  Paket linux-image-extra-3.13.0-45-generic ist noch nicht konfiguriert.

dpkg: Fehler beim Bearbeiten des Paketes linux-image-generic (--configure):
 Abhängigkeitsprobleme - verbleibt unkonfiguriert
Fehler traten auf beim Bearbeiten von:
 linux-image-extra-3.13.0-45-generic
 linux-image-generic

The most important messages are gzip: stdout: No space left on device and update-initramfs: failed for /boot/initrd.img-3.13.0-45-generic with 1. in this error output. This means, that I don't have enough space on the boot partition.

How much space left?

Now is the question, how much space left on the boot partition? In order to analyze this, you can use the command df. This small tool reports the amount of available disk space being used by file systems.

  1. df -l
Dateisystem                       1K-blocks   Benutzt Verfügbar Verw% Eingehängt auf
/dev/mapper/mediaserver--vg-root  303413624  84467448 203510608   30% /
none                                      4         0         4    0% /sys/fs/cgroup
udev                                7987796         4   7987792    1% /dev
tmpfs                               1599808      1268   1598540    1% /run
none                                  51200         0     51200    0% /run/lock
tmpfs                               7999032         4   7999028    1% /run/shm
none                                 102400         0    102400    0% /run/user
/mnt/mediahd/home                1441049464 650651156 717174184   48% /home
/dev/sdf1                            233191    214417      6333   98% /boot

As you can see above, only 2% space is free in /boot. Therefore, you have to delete old kernel packages.

Remove old kernel packages

At first have a look to your kernel that you are using with:

  1. uname -mrns
Linux mediaserver 3.13.0-39-generic x86_64

Based on this output, we know that kernel 3.13.0-39 is in use and that we can remove all other kernels by using:

  1. sudo apt-get remove --purge $(dpkg -l 'linux-image-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d')
Paketlisten werden gelesen... Fertig
Abhängigkeitsbaum wird aufgebaut.       
Statusinformationen werden eingelesen.... Fertig
Die folgenden Pakete wurden automatisch installiert und werden nicht mehr benötigt:
  linux-headers-3.13.0-35 linux-headers-3.13.0-35-generic
  linux-headers-3.13.0-40 linux-headers-3.13.0-40-generic
  linux-headers-3.13.0-41 linux-headers-3.13.0-41-generic
  linux-headers-3.13.0-43 linux-headers-3.13.0-43-generic
  linux-headers-3.13.0-44 linux-headers-3.13.0-44-generic
Verwenden Sie »apt-get autoremove«, um sie zu entfernen.
Die folgenden Pakete werden ENTFERNT:
  linux-image-3.13.0-35-generic* linux-image-3.13.0-40-generic*
  linux-image-3.13.0-41-generic* linux-image-3.13.0-43-generic*
  linux-image-3.13.0-44-generic* linux-image-3.13.0-45-generic*
  linux-image-extra-3.13.0-35-generic* linux-image-extra-3.13.0-40-generic*
  linux-image-extra-3.13.0-41-generic* linux-image-extra-3.13.0-43-generic*
  linux-image-extra-3.13.0-44-generic* linux-image-extra-3.13.0-45-generic*
  linux-image-generic*
0 aktualisiert, 0 neu installiert, 13 zu entfernen und 0 nicht aktualisiert.
2 nicht vollständig installiert oder entfernt.
Nach dieser Operation werden 1.165 MB Plattenplatz freigegeben.

After this, you can check again the free space on /boot with:

  1. df -l
Dateisystem                       1K-blocks   Benutzt Verfügbar Verw% Eingehängt auf
/dev/mapper/mediaserver--vg-root  303413624  82553624 205424432   29% /
none                                      4         0         4    0% /sys/fs/cgroup
udev                                7987796         4   7987792    1% /dev
tmpfs                               1599808      1268   1598540    1% /run
none                                  51200         0     51200    0% /run/lock
tmpfs                               7999032         4   7999028    1% /run/shm
none                                 102400         0    102400    0% /run/user
/mnt/mediahd/home                1441049464 650640572 717184768   48% /home
/dev/sdf1                            233191     33978    186772   16% /boot

As you can see, 84% space left on this partition. Furthermore, look at the boot partition in order to see all kernel versions:

  1. ls -l /boot
insgesamt 30059
-rw-r--r-- 1 root root  1164547 Okt 28 15:25 abi-3.13.0-39-generic
-rw-r--r-- 1 root root   165712 Okt 28 15:25 config-3.13.0-39-generic
drwxr-xr-x 3 root root     5120 Feb 14 12:33 grub
-rw-r--r-- 1 root root 20108779 Nov 14 04:03 initrd.img-3.13.0-39-generic
drwxr-xr-x 2 root root    12288 Sep 24  2013 lost+found
-rw------- 1 root root  3386936 Okt 28 15:25 System.map-3.13.0-39-generic
-rw------- 1 root root  5808544 Okt 28 15:25 vmlinuz-3.13.0-39-generic

Yep, that is what we want: The actual kernel exists and all other kernels are removed.

Install latest generic kernel

The last step is to reinstall the meta package linux-generic, in order to get the latest kernel version from the package management system.

  1. sudo aptitude install linux-generic

Package system

Delete unused debian packages with deborphan

  • aptitude update
  • aptitude autoclean
  • aptitude clean
  • aptitude purge deborphan --guess-all

You can use the following script:

  1. #!/bin/sh
  2. aptitude update
  3. aptitude autoclean
  4. aptitude clean
  5. while [ -n "`deborphan --guess-all`" ]; do
  6.     aptitude purge `deborphan --guess-all`
  7. done

Users

Create a user without a home folder

  1. adduser --system --group {{USERNAME}} --no-create-home

GIT

Add files and push them

  1. git add --all :/
  2. git status
  3. git commit -m 'Change Message'
  4. git push

Add special folders

There are special folders, which will not be uploaded automatically to GITHub. You can use the following command for e.g. _build folder:

  1. git add _build -f

Add SubModule

If you want to use another repo as a submodule than you have to go to the right subfolder

  1. cd /tmp/myrepo/classes/

and add it with:

  1. git submodule add https://github.com/michelf/php-markdown

Clone only a Subdirectory

You want only to clone a subdirectory from a git repository without all other files/directories? Here you can find the solution:

  1. git clone https://github.com/MoonMaker/modx.git
  2. cd modx
  3. git filter-branch --prune-empty --subdirectory-filter Disqus HEAD

In the modx repository is a subdirectory called "Disqus". After filtering the branch, the repository will contain the git history which touches Disqus.

Clone repository

  1. cd /tmp
  2. git clone --recursive https://github.com/MoonMaker/modx.git

Well, what do you think?

Comments powered by LudwigDisqus for ModX