Linux Debian/Ubuntu Commands
Last Updated April 2009
My Mini Manual
|– FILES/SEARCH/SYSTEM  –|
Unique names, remove duplicate names:
# cat words.txt | sort | uniq > dictionary.txt
remove any words not X size, or from X to Y:
# cat dictionary.txt | pw-inspector -m 6 -c 2 -n > passlist.txt
LIST ALL OPEN FILES:
# lsof
Only of specific process(for only top 5 use -d0-5):
# lsof -a -p 890 <-d0-5>
FINIDNG WHERE IS THE CMD:
# type ls
Find where is the executable
# which mysqldump
FINDING A FILE:
# find / -name flie.txt
# slocate file
# locate file
# whereis (search mans/bins)
FINDING AN INSTALLED LIBRARY/PACKET:
# apt-cache search gd | grep php
# dpkg -l | grep radius
# ldconfig -p |grep ‘libgd.so’
# ldconfig  -v  | grep db
# aptitude search snmp | grep perl
FIND A STRING INSIDE FILES
# grep -R “s1-ws-2960G” /home/comm/nagios/conf/* | less
# find / -name | xargs grep <stringtosearch>
FIND A STRING AND REPLACE
$ grep -rl OLDSTRING . | xargs perl -pi~ -e ’s/OLDSTRING/NEWSTRING/’
and if you want to do it sorted, files (this will even do unique results too!):
$ grep -rl OLDSTRING . | sort -u | xargs perl -pi~ -e ’s/OLDSTRING/NEWSTRING/’
and for you old school sed peeps (sed args aren’t as obscure):
$ grep -rl OLDSTRING . | xargs sed -i -e ’s/OLDSTRING/NEWSTRING/’
FIND KERNEL DRIVER MODULE CONFIG:
# grep -R “bttv” /etc/* | less<
The strings Commands
SEARCH INSIDE BINARY FILES FOR TEXT STRING:
# strings $(which sshd)| grep libwrap
# strings /usr/bin/users
MORE INFO ON A FILE:
# ls -l file
# stat file
# file -b file (reports Txt Type)
CHECKING HD SIZE:
# df -k
# du -kx / | sort -nr | less
DIRECTORY SIZES:
#du –summarize –human-readable
SIZE OF NEW FILES:
#du -ah | sort -rn | head
FIND BIG FILES EXCLUDING ANYTHING IN A BIN DIR:
# find / -type f -ls | sort -k 7 -r -n | grep -v ‘/bin’ | head
# find / -type f -ls | sort -k 25 -r -n | head
EXCLUDE EXECUTABLES:
# find / -type f -not -perm -g=x,-o=x -ls | sort -k 7 -r -n | head
CHECK LARGEST EXECUTABLE FILE:
# find / -type f -perm -g=x,-o=x -ls | sort -k 7 -r -n | head
|— NETWORK –|
NETWORK ACTIVITY, ports Listening and Established connections:
# lsof | egrep “ESTABLISHED|LISTEN” | more
Change ip address:
# vim /etc/network/interfaces
SET STATIC IP
auto eth3
iface eth3 inet static
address 10.1.0.87
netmask 255.255.0.0
network 10.1.0.0
broadcast 10.1.255.255
gateway 10.1.0.1
OR, but not persistant
# ifconfig -a
# netstat -rn
Setup Static IP/MASK/Gateway:
# ifconfig eth0 <IP> mask <mask>
ifconfig eth1 10.10.10.186 mask 255.255.255.0
Route Net:
# route add -net 161.116.1.0 netmask 255.255.255.0 eth0
Set Gateway:
# route add default gw 192.168.3.1
Set DNS:
# vim  /etc/resolv.conf
Or just vim /etc/network/interfaces
Restart the Network:
# /etc/init.d/networking restart
NETWORK CONFIG GUI BASED
netconf , linuxconf, netconfig
Connexions TCP/IP
# netstat -an
# lsof -i
SET INTERFACE TO USE A DHCP
# vim /etc/network/interfaces
# auto eth0
# iface eth0 inet dhcp
WIRELESS INTERFACES
# iface wlan0 inet dhcp
# wireless_mode managed
# wireless_rate 54M auto
# wireless_channel 6
# wireless_essid XXXXX
# wireless_key XXXXXXXXXX
MOUNT WINDOWS SHARE
edit /etc/hosts with IP host
# mkdir /mnt/music
# vim /etc/fstab    //host/share  /mnt/music  smbfs exec,credentials=/etc/cifspw 0 0
# vim /etc/cifspw > username=Jason /n password=ImNotGonnaTellYouThat
# chmod 600 /etc/cifspw
# mount -a
If smbfs dont work try cifs
Or
# mount -t smbfs -o username=$NTUSER,password=$NTPASSWD $NTSHARE $MNT
# mount -t smbfs -o username=backadmin1,password=backadin1 10.10.1.1bck_linux_oasis mntbackup_linux
Get MAC address:
Get the MAC address in script form:
# ifconfig wlan2 | grep HWaddr | awk ‘{print $5}’ | sed -e ‘s/-/:/g’  >>/tmp/mac
Best way:
# cat /sys/class/net/<iface>/device/net/<iface>map /address
NETBIOS INFORMATION, same as Windowze “nbtstat -an”:
# nmblookup -A <IP>
CHANGE HOSTNAME
# vim /etc/hostname
# etc/init.d/hostname.sh start
or
#hostname myname.local
or
#sysctl kernel.hostname=<NEWNAME>
|– HARD DISK –|
PARTITION DISK
Use GUI:
# gparted
List partition and Disks
# fdisk -l
Partition
# cfdisk /dev/hdc
FORMAT
# mkfs.ext3 /dev/hdc1
MOUNT
mkdir /new-disk
mount -t ext2 /dev/sdb1 /cache
OGs de SO: Estat HW i SW
dmesg
more /var/adm/messages
more /var/log/syslog
Estat processos
#ps -edaf
#sudo lsof -p pid
Backup, Compress entire folder:
#tar cvf FILE.tar /home/PATH/confs/*.*
Estat de càrrega sistema
#top
#vmstat
UPDATING DEBIAN/UBUNTU:
# apt-get update
# apt-get dist-upgrade
# apt-get autoclean
|– SQUID PROXY –|
nice way to monitor real time
#tail -f /var/log/squid/access.log | awk ‘{print$3 ” ” $8 ” ” $4 ” ” $6 ” ” $8 ” ” $9 ” ” $7}’
Where number showed on awk option are number of log information per line splited by space.

|– EMAIL SYSTEMS –|
MAILSERVER (EXIM4):
Config files are at
/etc/exim4/
Reconfigure:
#dpkg-reconfigure exim4-config
Restart Exim4 mailserver:
#invoke-rc.d exim4 restart
After editing the config file, run:
#exim -bV
Tip: I also link sendmail to exim via:
#ln -s /usr/sbin/exim /usr/sbin/sendmail
Now, check a local address:
#exim -bt local_user@your.domain
Next check a remote address:
#exim -bt fferreira@their.domain
Test sending an email:
# echo “TEST EMAIL” | Mail -s “TestSub” fferreira@osiatis.es
OR with Exim4 (fix the quotes!):
#exim -v fferreira@osiatis.es
Remove FRONZEN emails.
# exiqgrep -zi | xargs exim -Mrm
Spool should be here:
/var/spool/exim4/
Logs Should be here
more /var/log/exim4/mainlog
SENDMAIL
#apt-get install sendmail
#sendmailconfig (just say “Y” to all the questions)
ref. http://networking.ringofsaturn.com/Unix/sendmail.php
test email
# echo “TEST EMAIL” | sendmail -s “TestSub” fferreira@osiatis.es
OR with Exim4 (fix the quotes!):
# echo “TEST EMAIL” | Mail -s “TestSub” fferreira@osiatis.es
Or in Exim
#exim4 -bt email@test.com
Get info about mail:
# sendmail -d0.1 -bt < /dev/null
# sendmail -bv <user@domain>
Stop Sendmail:
# /etc/init.d/sendmail stop
Start Sendmail:
# /usr/lib/sendmail -bd -q1h.
|–  HARDWARE CMDS –|

List all hardware:
#lshw
List all network related
# lshw -C network
List all USB connected hardware:
# lsusb
List all PCI connected hardware:
# lspci
Screen Resolution setup:
#sudo dpkg-reconfigure -phigh xserver-xorg
START STOP A SERVICE:
# /etc/init.d/<service> start
GET INFO ON RUNNING PROCESS:
# ps ax | grep <process>

KEYS:

CRTL-ALT-BACKSPACE will restart X11
CRTL-ALT-F1 will go to CMD line
FINDING INFO ABOUT A CMD:
# apropos mail
# man -k <cmd>
EDITORS
# nano
# vim
# vi
Make sure MySQL module for php5 is installed:
# dpkg –list | grep php5-mysql
# ldconfig  -v
STARTUP IN TEXT/GUI MODE:
Remove GUI from boot up ( better memory):
#update-rc.d -f gdm remove
To start GUI:
#startx
To have it GUI startup again:
# /usr/sbin/update-rc.d gdm defaults
*Autostart Daemon Ubuntu/Debian
# /usr/sbin/update-rc.d mysql defaults
/usr/sbin/update-rc.d nagios defaults
SCHEDULLE A TASK
Edit the crontab schedulle
# crontab -e
The syntax is:
* * * * * Command to be executed
– – – – –
| | | | |
| | | | +—– Day of week (0-6)
| | | +——- Month (1 – 12)
| | +——— Day of month (1 – 31)
| +———– Hour (0 – 23)
+————- Min (0 – 59)
ex.
0 23 * * *  bash /etc/scripts/backupmysql.sh
0 10 * * *  perl /scripts/ftpsync.pl -q
0 18 * * *  perl /home/felix/Documents/SCRIPTS/ftpsync.pl
Every 2 minutes
# */2 * * * * * bash /etc/scripts/backupmysql.sh
AT Schedulle Tasks, it will prompt for the cmd, + CRTL+D (to save)
# at 22:30
# /etc/scripts/backupmysql.sh
# CRTL D
List tasks
# atr
Deletes tasks. Type:
#atrm job .
-Change default language:
dpkg-reconfigure -plow locales
-Change keyboad layout:
dpkg-reconfigure console-data
-Reconfigure postfix for your convenience:
dpkg-reconfigure postfix
|– MySQL –|
Run the Backup Script then
# mysql -u root -p
mysql> flush logs;
will create a brand new mysql-bin.0000xy
mysql> purge binary logs to ‘mysql-bin.0000xy’;
will purge all your logs files before the last.
Commads on User information::
#usermod
#id logname whoami groups users who
#adduser, addgroup, deluser and delgroup
Setting the Time and Hardware time
#date -s “Thu Oct  2 9:30:47 CEST 2008”
If you set your clock to UTC rather than local time, issue the command:
#hwclock –systohc –utc
When you power down or reboot your system, the system date and time will revert to the values held in non-volatile (CMOS) memory. To store the Linux date and time in CMOS, issue the following command:
#hwclock –systohc
Set the TimeZone:
#tzconfig
TImeZones file:
vim /etc/default/rcS
RECONFIGURE A PACKAGE
# dpkg-reconfigure tzdata
Strange Time problems? Solution Install chrony (uses NTP protocol):
#apt-get install chrony
Restart chrony:
#invoke-rc.d chrony restart
ref. http://www.debian.org/doc/manuals/system-administrator/ch-sysadmin-time.html
ref. /usr/share/doc/util-linux/README.Debian.hwclock
VI EDITOR
La tecla “x” borra el carácter seleccionado con el cursor.
La tecla “d”, puslada dos veces consecutivas, borra una línea.
Una vez finalizada la edición, escribimos “:wq”
http://faqs.pcbsd.es/index.php?action=artikel&cat=11&id=204&artlang=es
IPTABLES
Show all current Nmap rules
# iptables -L
To use a nice graphic interface download firestarter
Allows state INVALID (otherwise nmap wont work and you
will get errors type: “Operation not permitted”)
iptables echo 1 > /proc/sys/net/ipv4/ip_forward
echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts
echo 0 > /proc/sys/net/ipv4/conf/all/accept_source_route
echo 1 > /proc/sys/net/ipv4/tcp_syncookies
echo 0 > /proc/sys/net/ipv4/conf/all/accept_redirects
echo 0 > /proc/sys/net/ipv4/conf/all/send_redirects
echo 1 > /proc/sys/net/ipv4/conf/all/rp_filter
echo 1 > /proc/sys/net/ipv4/conf/all/log_martians
iptables –flush
iptables -F INPUT
iptables -P INPUT DROP
iptables -F OUTPUT
iptables -P OUTPUT DROP
iptables -F FORWARD
iptables -P FORWARD DROP
iptables -t nat -F
iptables -A INPUT -m state –state ESTABLISHED,RELATED -j ACCEPT
iptables -A OUTPUT -m state –state NEW,ESTABLISHED,RELATED,INVALID -j ACCEPT
NAUTILUS
Gnome Nice Scripts for its “Explorer” Nautilus.
Just copy the files to
# ~/.gnome2/nautilus-scripts
and
# chmod +x -R ~/.gnome2/nautilus-scripts
Here are the scripts:
http://g-scripts.sourceforge.net/index.php
route add default gw 192.168.99.254

Tags: , , , , , , , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *