Tips and Tricks: Difference between revisions

From Q
Jump to navigation Jump to search
Tgurr (talk | contribs)
No edit summary
Tgurr (talk | contribs)
No edit summary
 
(44 intermediate revisions by the same user not shown)
Line 1: Line 1:
== Packagemenagement ==
== Useful commands ==
=== Recursively set directory permissions to 755 ===


=== To which package belongs file X ===
{{Root|<nowiki>find /var/www/path -type d -print0 | xargs -0 chmod -c 755</nowiki>}}
{{Codeline|# equery belongs -f <dateiname>}}
 
=== Recursively rename directory and files from ISO-8859-15 to UTF-8 ===
 
{{Command|<nowiki>convmv -f iso-8859-15 -t utf8 -r /var/www/path --preserve-mtimes --notest</nowiki>}}


=== Which packages has USE-Flag X ===
=== Recursively search for files of a specitic type, e.g. documents and list them ===
{{Codeline|# equery hasuse <useflag>}}


=== Backup an installed package ===
{{Command|<nowiki>find . -regex '.*\(pdf\|doc\)'</nowiki>}}
{{Codeline|# quickpkg net-www/apache}}


After this you can install the package on another machine or do a fast downgrade if something went bad after an update. You can find the file under {{Filename|/usr/portage/packages/All}} and in this example a symlink to the apache file in {{Filename|/usr/portage/packages/net-www}}. To install the now precompiled binary use:
=== User: Change a users home directory ===


{{Codeline|# emerge --usepkgonly "<net-www/apache-2.2.4"}}
{{Root|usermod -d /home/newhome user}}


=== Detect and get rid of leftover packages ===
=== Strip comments from config file ===
{{Codeline|# emerge depclean --pretend}}


=== Change your current profile ===
{{Command|<nowiki>grep -v "#" file.conf</nowiki>}}
{{Codeline|# emerge eselect}}


{{Codeline|# eselect profile list}}
=== rsync file transfer ===
Synchronise a directory or whole partition:
{{Root|<nowiki>rsync -av --delete-before /run/media/user/4TB-WD/ /run/media/user/4TB-WD-BCK/ --exclude="/lost+found/" --dry-run</nowiki>}}


{{Codeline|# eselect profile set <nummer>}}
Upload a file to a remote server via rsync over ssh:
{{Root|rsync --partial --progress movie.mkv root@example.com:/var/www/subdomain.example.com/htdocs/movies/movie.mkv}}


== SCP file transfer ==
=== SCP file transfer ===
File transfer via commandline.
File transfer via commandline.


Upload file:<br />
Upload file:
{{Codeline|# scp /root/htdocsbackup.tar.bz2 root@remote-host.de:/root/}}<br />
 
Download file:<br />
{{Root|scp /root/htdocsbackup.tar.bz2 root@remote-host.de:/root/}}
{{Codeline|# scp root@remote-host.de:/root/htdocsbackup.tar.bz2 /root/htdocsbackup.tar.bz2}}
Download file:
 
{{Root|scp root@remote-host.de:/root/htdocsbackup.tar.bz2 /root/htdocsbackup.tar.bz2}}
 
Upload directory:
 
{{Root|scp -p -r /root/directory root@remote-host.de:/root}}
Download directory:
 
{{Root|scp -p -r root@remote-host.de:/root/directory /root}}
 
=== SSH tunnel ===
Very useful if the server you want to connect to has only the SSH port open and/or a firewall infront and you want to access for example a tomcat server running on port 8080.
 
{{Root|ssh -N -i /home/<user>/.ssh/id_dsa -L 7777:remote-host.de:8080 root@remote-host.de}}
 
After establishing the tunnel you can access the tomcat server of the remote machine port 8080 at your localhost port 7777.
 
=== Generate SSH Host Keys ===


Upload directory:<br />
{{Root|ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key -N ''}}
{{Codeline|# scp -r /root/directory root@remote-host.de:/root}}<br />
{{Root|ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N ''}}
Download directory:<br />
{{Root|ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key -N ''}}
{{Codeline|# scp -r root@remote-host.de:/root/directory /root}}


== SSH tunnel ==
=== SSL: Remove passphrase from a SSL key ===
Ist auf dem Server nur der SSH Port offen aber man möchte sich z.B. auf den auf Port 8080 laufenden Tomcat Webserver verbinden so kann man das über einen SSH Tunnel machen.


{{Codeline|# ssh -N -i /home/benutzer/.ssh/id_dsa -L 7777:webserver:8080 root@webserver}}
{{Command|openssl rsa -in ssl_with_passphrase.key -out ssl_without_passphrase.key}}


Anschließend kann man den Tomcat unter localhost:7777 erreichen.
=== SSL: Add/change passphrase to/from a SSL key ===


== Yakuake DCOP-Skripte ==
{{Command|openssl rsa -in ssl_without_passphrase.key -out ssl_with_passphrase.key -des3}}
=== MultiSSH ===
Per SSH auf mehrere Hosts verbinden, dafür jeweils ein neues Yakuake Tab anlegen und entsprechend benennen.
multissh.sh
<source lang="bash">
#!/bin/bash


[[ -n "$1" && -n "$2" ]] || {
=== Perl: List included perl core modules with their versions ===
    echo "Usage: ./multissh.sh \"user\" \"server1 server2\""
    echo " z.B.: ./multissh.sh \"root\" \"server1 server2\""; exit 0 ; }


lastid=`dcop yakuake DCOPInterface sessionIdList | awk -F, '{print $NF}'`
{{Command|corelist -v 5.22.1}}


for i in $2 ; do
=== Postfix: Show mailqueue ===
        dcop yakuake DCOPInterface slotAddSession
        let "lastid += 1"
        dcop yakuake DCOPInterface slotRenameSession $lastid $i
        dcop yakuake DCOPInterface slotRunCommandInSession $lastid "ssh $1@$i"
done


exit 0
{{Root|mailq}}
</source>


=== MultiCommand ===
=== Postfix: Attempt to deliver all queued mail ===
Ein Kommando in mehreren Yakuake Tabs ausführen.
multicommand.sh
<source lang="bash">
#!/bin/bash


[[ -n "$1" && -n "$2" ]] || {
{{Root|postqueue -f}}
    echo "Usage: ./multicommand.sh \"tabname1 tabname2\" \"kommando\""
    echo " z.B.: ./multicommand.sh \"server1 server2\" \"emerge --sync\""; exit 0 ; }


ids=`dcop yakuake DCOPInterface sessionIdList | sed 's/,/ /g'`
=== Postfix: Delete a single mail from queue ===


for i in $ids ; do
{{Root|postsuper -d id_of_mail}}
        sessionname=`dcop yakuake DCOPInterface slotSessionName $i`


        for x in $* ; do
=== Postfix: Delete all mails with a specific sender from queue ===
                if [ "$sessionname" = "$x" ] ; then
                        dcop yakuake DCOPInterface slotRunCommandInSession $i "$2"
                fi
        done
done


exit 0
{{Root|<nowiki>mailq | tail -n +2 | awk 'BEGIN { RS = "" } / apache@example\.com$/ { print $1 } ' | tr -d '*!' | postsuper -d -</nowiki>}}
</source>


== KDE4 Fixes ==
=== ImageMagick: Combine images side by side ===
=== .gtkrc isn't honoured by GTK Applications anymore ===
KDE overrides the GTK colours with global ones, if you want that. If not (since it also overrides the GTK theme with the ugly default one) you can disable that behaviour under System Settings -> Appearance -> Colors at the bottom. This does not always work, so copy over your .gtkrc-2.0 from your homedir or one of the themes that come with the theme pack.


{{Codeline|# cp ~/.gtkrc-2.0 ~/.kde/share/config/gtkrc-2.0}}
{{Command|convert image{1,2,3}.png +append output.png}}


{{Codeline|# cp /usr/share/themes/Clearlooks/gtk-2.0/gtkrc ~/.gtkrc-2.0}}
=== Safely spin down external USB drive AFTER unmounting using sg3_utils ===


For more information have a look at [[GTK_Anwendungen_unter_KDE|GTK Applications under KDE]].
{{Root|sg_start --readonly --stop /dev/sdX}}


=== Reset to the default Plasma layout ===
=== Delete content in the underlying directory of a mounted filesystem without having to unmount first ===
Log out and deleting from tty:
Bind mount root to a temporary mount point, e.g. /mnt/temp. Useful to fix. e.g. following systemd informational notice:


{{Codeline|# rm ~/.kde/share/config/plasma*}}
tmp.mount: Directory /tmp to mount over is not empty, mounting anyway.


=== Change the Dolphin standard view to detailed view for ALL folders ===
{{Root|mount --bind / /mnt/temp}}
 
Browse to /mnt/temp/yourmountpoint and be able to delete the files, afterwards unmount /mnt/temp again.
 
=== eyeD3: Remove a specific ID3 tag frame ===
 
{{Command|<nowiki>eyeD3 file.mp3 --remove-frame=TPE2</nowiki>}}
 
=== Ghostscript: Split a PDF file in single files per page using a python script ===
<pre>
#!/usr/bin/python3
 
import os
 
number_of_pages = 10
input_pdf = "file.pdf"
 
for i in range(1, number_of_pages +1):
    os.system("gs -q -dBATCH -dNOPAUSE -sOutputFile=page{page:04d}.pdf -dFirstPage={page} -dLastPage={page} -sDEVICE=pdfwrite {input_pdf}".format(page=i, input_pdf=input_pdf) )
</pre>
 
=== Ghostscript: Merge multiple PDF files ===
 
{{Command|<nowiki>gs -dBATCH -dNOPAUSE -dQUIET -sDEVICE=pdfwrite -sOutputFile=merged.pdf file1.pdf file2.pdf file3.pdf</nowiki>}}
 
Alternativly use poppler (which removes metadata)
 
{{Command|pdfunite file1.pdf file2.pdf file3.pdf merged.pdf}}
 
=== Change the Dolphin standard view to detailed view for ALL folders ====
Open Dolphin -> Settings > Configure Dolphin -> Views -> Common Tab -> and mark -> Use the same view for all folders
Open Dolphin -> Settings > Configure Dolphin -> Views -> Common Tab -> and mark -> Use the same view for all folders


=== Disable IPv6 until the next reboot ===
{{Root|echo 1 > /proc/sys/net/ipv6/conf/<iface>/disable_ipv6}}
=== Stream a video via VLC to Chromecast ===
{{Command|<nowiki>vlc --sout="#chromecast{ip=xxx.xxx.xxx.xxx}" ~/video.mkv</nowiki>}}
=== Summary of the top 15 directories occupying the most hard disc space ===
{{Command|<nowiki>du -cksh * | sort -hr | head -n 15</nowiki>}}
== Package management (Portage) ==
=== To which package belongs file X ===
{{Root|equery belongs -f <dateiname>}}
=== Which installed packages have USE-Flag X ===
{{Root|equery hasuse <useflag>}}
=== Backup an installed package ===
{{Root|quickpkg net-www/apache}}
After this you can install the package on another machine or do a fast downgrade if something went bad after an update. You can find the file under {{Path|/usr/portage/packages/All}} and in this example a symlink to the apache file in {{Path|/usr/portage/packages/net-www}}. To install the now precompiled binary use:
{{Root|emerge --usepkgonly "<net-www/apache-2.2.4"}}
=== Detect and get rid of leftover packages ===
{{Root|emerge depclean --pretend}}
=== Change your current profile ===
{{Root|emerge eselect}}
{{Root|eselect profile list}}
{{Root|eselect profile set <nummer>}}


[[Kategorie:Software]]
[[Category:Software]]

Latest revision as of 16:53, 22 February 2017

Useful commands

Recursively set directory permissions to 755

# find /var/www/path -type d -print0 | xargs -0 chmod -c 755

Recursively rename directory and files from ISO-8859-15 to UTF-8

$ convmv -f iso-8859-15 -t utf8 -r /var/www/path --preserve-mtimes --notest

Recursively search for files of a specitic type, e.g. documents and list them

$ find . -regex '.*\(pdf\|doc\)'

User: Change a users home directory

# usermod -d /home/newhome user

Strip comments from config file

$ grep -v "#" file.conf

rsync file transfer

Synchronise a directory or whole partition:

# rsync -av --delete-before /run/media/user/4TB-WD/ /run/media/user/4TB-WD-BCK/ --exclude="/lost+found/" --dry-run

Upload a file to a remote server via rsync over ssh:

# rsync --partial --progress movie.mkv root@example.com:/var/www/subdomain.example.com/htdocs/movies/movie.mkv

SCP file transfer

File transfer via commandline.

Upload file:

# scp /root/htdocsbackup.tar.bz2 root@remote-host.de:/root/

Download file:

# scp root@remote-host.de:/root/htdocsbackup.tar.bz2 /root/htdocsbackup.tar.bz2

Upload directory:

# scp -p -r /root/directory root@remote-host.de:/root

Download directory:

# scp -p -r root@remote-host.de:/root/directory /root

SSH tunnel

Very useful if the server you want to connect to has only the SSH port open and/or a firewall infront and you want to access for example a tomcat server running on port 8080.

# ssh -N -i /home/<user>/.ssh/id_dsa -L 7777:remote-host.de:8080 root@remote-host.de

After establishing the tunnel you can access the tomcat server of the remote machine port 8080 at your localhost port 7777.

Generate SSH Host Keys

# ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key -N
# ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N
# ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key -N

SSL: Remove passphrase from a SSL key

$ openssl rsa -in ssl_with_passphrase.key -out ssl_without_passphrase.key

SSL: Add/change passphrase to/from a SSL key

$ openssl rsa -in ssl_without_passphrase.key -out ssl_with_passphrase.key -des3

Perl: List included perl core modules with their versions

$ corelist -v 5.22.1

Postfix: Show mailqueue

# mailq

Postfix: Attempt to deliver all queued mail

# postqueue -f

Postfix: Delete a single mail from queue

# postsuper -d id_of_mail

Postfix: Delete all mails with a specific sender from queue

# mailq | tail -n +2 | awk 'BEGIN { RS = "" } / apache@example\.com$/ { print $1 } ' | tr -d '*!' | postsuper -d -

ImageMagick: Combine images side by side

$ convert image{1,2,3}.png +append output.png

Safely spin down external USB drive AFTER unmounting using sg3_utils

# sg_start --readonly --stop /dev/sdX

Delete content in the underlying directory of a mounted filesystem without having to unmount first

Bind mount root to a temporary mount point, e.g. /mnt/temp. Useful to fix. e.g. following systemd informational notice:

tmp.mount: Directory /tmp to mount over is not empty, mounting anyway.

# mount --bind / /mnt/temp

Browse to /mnt/temp/yourmountpoint and be able to delete the files, afterwards unmount /mnt/temp again.

eyeD3: Remove a specific ID3 tag frame

$ eyeD3 file.mp3 --remove-frame=TPE2

Ghostscript: Split a PDF file in single files per page using a python script

#!/usr/bin/python3

import os

number_of_pages = 10
input_pdf = "file.pdf"

for i in range(1, number_of_pages +1):
    os.system("gs -q -dBATCH -dNOPAUSE -sOutputFile=page{page:04d}.pdf -dFirstPage={page} -dLastPage={page} -sDEVICE=pdfwrite {input_pdf}".format(page=i, input_pdf=input_pdf) )

Ghostscript: Merge multiple PDF files

$ gs -dBATCH -dNOPAUSE -dQUIET -sDEVICE=pdfwrite -sOutputFile=merged.pdf file1.pdf file2.pdf file3.pdf

Alternativly use poppler (which removes metadata)

$ pdfunite file1.pdf file2.pdf file3.pdf merged.pdf

Change the Dolphin standard view to detailed view for ALL folders =

Open Dolphin -> Settings > Configure Dolphin -> Views -> Common Tab -> and mark -> Use the same view for all folders

Disable IPv6 until the next reboot

# echo 1 > /proc/sys/net/ipv6/conf/<iface>/disable_ipv6

Stream a video via VLC to Chromecast

$ vlc --sout="#chromecast{ip=xxx.xxx.xxx.xxx}" ~/video.mkv

Summary of the top 15 directories occupying the most hard disc space

$ du -cksh * | sort -hr | head -n 15

Package management (Portage)

To which package belongs file X

# equery belongs -f <dateiname>

Which installed packages have USE-Flag X

# equery hasuse <useflag>

Backup an installed package

# quickpkg net-www/apache

After this you can install the package on another machine or do a fast downgrade if something went bad after an update. You can find the file under /usr/portage/packages/All and in this example a symlink to the apache file in /usr/portage/packages/net-www. To install the now precompiled binary use:

# emerge --usepkgonly "<net-www/apache-2.2.4"

Detect and get rid of leftover packages

# emerge depclean --pretend

Change your current profile

# emerge eselect
# eselect profile list
# eselect profile set <nummer>