Linux / Ubuntu Bash Commands
Copying a directory: cp -R source target
Removing a directory: rm -rf dir
—–
Mounting directory:
sudo mkdir /media/www
sudo mount //server/www /media/www
In /etc/fstab:
//server/www /media/www smb defaults 0 0
In /etc/hosts: 192.168.0.1 server
Using cifs with username and password in .smbcredentials:
//server/www /media/www cifs credentials=/root/.smbcredentials,iocharset=utf8 0 0
Ntfs-3g example usage:
/dev/sda2 /media/disk ntfs-3g defaults,nls=utf8,umask=007,gid=46 0 1
Reloading fstab: mount -a
—–
Compress/Decompress:
tar -cjf backup.tar.bz2 directory
tar -xjf backup.tar.bz2
tar -cvf tarname directory/
gzip tarname.tar
tar -xzvf tarname.tar.gz
Uncompress gz: tar -zxvf file.tar.gz
Uncompress zip: unzip file.zip
—–
Restart System / Apache / PostgreSQL / MySQL
shutdown -r now
sudo /etc/init.d/apache2 restart
sudo /etc/init.d/postgresql-8.2 restart
sudo /etc/init.d/mysql restart
—–
IP:
ifconfig / iwconfig
ip addr show
ip route
—–
Restart X-Server: Ctrl-Alt-BackSpace
—–
Linking:
ln -s target/path name
—–
All services: ps aux
Filtered services: ps aux | grep servicename
Search the whole file system: find / -name filename
Copy dir: cp -r dir/* dest/dir
Example /etc/network/interfaces:
auto lo
iface lo inet loopback
iface eth0 inet dhcp
address 192.168.1.22
netmask 255.255.255.0
gateway 192.168.1.254
auto eth0
Network info: sudo ifconfig
VI: ESC to get into command mode. In command mode use i to insert text, ESC to get back to command mode. Get out and save by typing :wq.
——
General hardware info: lspci
——
My current /etc/hosts file:
127.0.0.1 localhost
127.0.1.1 henrik-desktop
192.168.0.1 server
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
——
Location of Grub menu file: /boot/grub/menu.lst
——
find /home -name ‘*.avi’
chmod 777 folder
——
Shutting down / restarting:
sudo shutdown -P now
sudo reboot
——
Email:
Clearing all mails in queue: postsuper -d ALL
——
Checking folder info: du -hs dir
Checking Ubuntu version: lsb_release -a
Checking Kernel version: uname -r
Vacuuming Firefox database:
3.0.*
for f in ~/.mozilla/firefox/*/*.sqlite; do sqlite3 $f 'VACUUM;'; done
3.5.*
for f in ~/.mozilla/firefox-3.5/*/*.sqlite; do sqlite3 $f 'VACUUM;'; done
——
Pushing keys to remote server to be able to ssh without entering password all the time:
ssh-keygen -t dsa (accept all the defaults)
cat ~/.ssh/id_dsa.pub | ssh root@domain.com 'mkdir .ssh; cd .ssh; cat >> authorized_keys; chmod 600 authorized_keys'
Note: root@domain.com, it needs to be replaced with the server info in question and step 1 is only needed once. If you do it again and use default values you will overwrite your existing keys, not good.
Killing a process by name, 4 different methods from how to geek, I added the last one which will kill the process no matter what:
kill $(pgrep irssi)
killall -v irssi
pkill irssi
kill `ps -ef | grep irssi | grep -v grep | awk ‘{print $2}’`
killall -9 -v irssi
Listing all big files / folders:
find . -type f -size +10000k -exec ls -lh {} \; | awk '{ print $8 ": " $5 }'
Getting my twitter timeline with CURL and saving it to twitter.xml with a 60 second timeout.
curl -u hsarvell:password -m 60 -o twitter.xml http://twitter.com/statuses/friends_timeline.xml
Dumping MySQL database:
mysqldump --databases dbname > /some/folder/dbname.sql
or verbose:
mysqldump databasename tablename --user userid --password > /some/folder/dbname.sql
bzip2 dbname.sql
Importing a dumped MySQL database with the file being encoded in utf8:
mysql -u username -p --default_character_set utf8 dbase < file.sql
Deleting the whole Postfix queue: postsuper -d ALL
Printing computer specs (as root): lshw -html > specs.html
Turning off touchpad: synclient TouchpadOff=1
Compiling 32bit binaries on a 64bit system:
1.) sudo apt-get install gcc-multilib libc6-i386
2.) Use the -m32 flag.
Checking which ports are busy and what’s running behind them:
sudo apt-get install nmap
nmap -p 1-65535 -sV 127.0.0.1
Checking if any process is using port 80: netstat -anl | grep :80
Short note on how to setup new mail / change password on existing mail with Postfix and Courier:
cd /etc/postfix
nano access
nano virtual
cd virtual_domains
nano domain.com
cd /etc/courier/userdb
nano domain.com (add a hash for a password you already know)
cd /usr/lib/courier
perl makeuserdb
/etc/init.d/postfix restart




