Useful debian commands

Here some of the most useful debian commands are listed:

List all open ports and applications that hold them.
lsof -i
useful is also:
netstat -tunap

Search the package database for the package xyz.
apt-cache search xyz

Get package information for the package xyz.
apt-cache show xyz

Install the package xyz
apg-get install xyz

Look for a file pcre.h in all packages using the regular expression
apt-file search -x "/pcre.h$"

Set the access rights of all files in the current directory and all files in subdirs to 644 (check unix access rights for help on this topic).
find . -type f -print0 | xargs -0 chmod 644

Set access rights for all directories in current dir and for all subdirs to 755.
find . -type d -print0 | xargs -0 chmod 755

Find help on the command chmod:
man chmod

Check all .sfv files found in a directory (and its subdirs):
find . -type f -name *.sfv -execdir cfv -f {} \;

cfv must be installed!
apt-get install cfv

Extract all files/folders in archive.tar to the current directory and create directory structure.
tar xvf archive.tar.gz

Add all files/folders to archive from the specified directory
tar -pczf archive.tar.gz folder/

Check the space available on the hard drives.
df -h

Show the size of a directory.
du ./folder/ --max-depth=0 -h

Find all files in a directory containing a specific string.
find /Search/Path -type f | xargs strings -f | fgrep -i SearchString

Pass a command as parameter to a program:
./program `command`
For example pass file content to a program as first parameter:
./program `< file.txt`

Installs a init.d script using the given comments in the file into the bootup sequence
insserv -d scriptname

Removes a init.d script from bootup sequence
insserv -r scriptname

After configuring a package and running make, instead of make install you can
execute the checkinstall command. It will build a package and install it on the system.
This package can then be removed easily with dpkg.

Login as www-data user:
You have to provide a shell, since by default none is set for
this user...
So use: su -s /bin/bash www-data

If running apt-get update returns an error because of changed sources.list (new version f.e.),
just update the debian keyring like that:
apt-get install debian-keyring debian-archive-keyring

The next execution of update should work without any problems.