Linux

lsof - examples

lsof /bin/bash lists all processes that use the bash shell lsof -p PID lists all open files of the process with the given PID lsof +D /tmp lists all open files in "/tmp" and its subdirectories without paying attention to symbolic links lsof -u user lists all files that are opened by the given user lsof -u ^user lists all opened files that are not opened by the given user lsof -d txt process list a la ps aux lsof +L1 lists all deleted files, that are still opened and use up disk space (files with less than one link) lsof -i network-relevant files lsof -i -P -n all network-relevant files without spelling out the port numbers as services and without resolving the hostname lsof -i6 ipv6-related files lsof -i|grep '\->' lists all active connections lsof -a -i -u www-data lists all network files opened by the user www-data (boolean and with -a)    

Limit ssh brute force attacks

This will limit incoming connections to port 22 to no more than 4 attemps in ten minutes. Any more will be dropped. You can adjust the numbers yourself to limit connections further.
iptables -I INPUT -p tcp --dport 22 -i eth0 -m state --state NEW -m recent   --set
iptables -I INPUT -p tcp --dport 22 -i eth0 -m state --state NEW -m recent   --update --seconds 600 --hitcount 4 -j DROP

(Found here http://blog.blackdown.de/2005/02/18/mitigating-ssh-brute-force-attacks-with-ipt_recent/

Copying a directory hierarchy

cd /tmp
tar cvf - blarg | (cd /var; tar xf -)
or to copy from a local machine to a remote machine
tar Pcfz - /usr/local/src/aolserver | ssh rumborak.foobar.de tar Pvxfz -
or to copy from a remote machine to a local machine
ssh rumborak.foobar.de tar Pcfz - /usr/local/src/aolserver | tar Pvxfz -

RPM

Find out the version number of an installed package
rpm -q Blahblah

Get a list of all installed packages
rpm -qa

Find out to which package a file belongs
rpm -qf /home/dirk/bla.ttx

Display information about the specified package:
rpm -qi rpm

Show the files that will be installed for the specified package file:
rpm -qp1 bla.rpm

Listing the files in a package file
rpm2cpio logrotate-1.0-1.i386.rpm | cpio -t

sed

sed '23!d' filename Output line 23 of filename
sed '23,42!d' filename Output lines 23 to 42 of filename
sed -n '/foo/,/bar/p' filename Output all lines between the first line that matches foo and the last line that matches bar.
sed -n '/foo/,/bar/p' filename Output all lines that are not in between the lines which contain "foo" and "bar"

grep

grep '^..$' filename Match all lines with exactly two characters
grep '^.\{12\}$' filename Match all lines with exactly 12 characters
grep '^.\{12,\}$' filename Match all lines with at least 12 characters
grep '^.\{7,12\}$' filename Match all lines with at least 7 and less than or equal to 12 characters
grep -v foobar filename Match all lines in filename that do not match foobar

find

find . -name Root -exec perl -pi -e 's/\/usr\/local\/cvsroot/\/cvsweb/' {} \;  
find .

Debian Package System Notes

apt
apt-cache add
apt-cache gencaches
apt-cache showpkg
apt-cache stats
apt-cache unmet
apt-cache search
apt-cache depends
apt-cache policy
apt-cache pkgnames
apt-cache dotty
dpgk
dpkg -lList packages matching given pattern. If no package-name-pattern is given, list all packages in /var/lib/dpkg/available.
dpkg -LList files installed to your system from package.
dpkg -SSearch for a filename from installed packages
dselect
+Install or upgrade
-Remove
_Remove and purge config
=Hold in present state
:Unhold: upgrade or leave uninstalled
oChange order of the list
v,VToggle verbose display
i,IToggle/cycle info displays
Uset all to sUggested state
Dset all to Directly requested state
/search (Return to cancel)
\repeat last search
Syndicate content