My useful linux commands notes

show open files and programs holding it 
#lsof +L1

Repeatedly run a command and see output 

watch -n 1 date +%r


Create a password that works for Debian and Ubuntu  (can be used in Puppet manifests ) 


 mkpasswd -m sha-512


Create database (MySql) 

CREATE DATABASE databasename;

Create user for a database 

mysql> grant all privileges on databasename.* to 'user'@'host' \
identified by 'password';

if you want to access this database with that user over the network (tcp connection) replace the 'host' with the one you need or change to '%' to allow access from any host (a security threat) .

Delete database 

DROP DATABASE databasename;


Convert flac to mp3 - right in the flac files folder

(install flac and lame)
apt-get install flac lame

for f in *.flac; do flac -cd "$f" | lame -b 320 - "${f%.*}".mp3; done


Mount Windows shares 



mount -t cifs //FILE-SERVER-IP-ADDRESS/public /local/mountpoint -o user=nobody

Compress and Decompress Folder ( for backup or whatever ) - use p to preserve permissions


COMPRESS 
tar -zcvf outputfile.tar.gz /home/jerry/prog

DECOMPRESS 
tar -zxvf outputfile.tar.gz

Copy files over ssh using *.pem file authentication 

scp -i  mykey.pem somefile.txt root@ec2-123-123-123-123.compute-1.amazonaws.com:/tmp

Copy files to S3 bucket 

apt-get install s3cmd
( configure s3cmd to authenticate with your credentials, make sure you have the required permission for the bucket) 

s3cmd put file.tar.gz s3://bucketname/


VI(M) tips


make a .vimrc file in the user directory and in /etc/skel , type syntax on in it in order to always have syntax highlighting enabled.

:%s/foo/bar/g
Find each occurrence of 'foo' (in all lines), and replace it with 'bar'.
:s/foo/bar/g
Find each occurrence of 'foo' (in the current line only), and replace it with 'bar'.
:%s/foo/bar/gc
Change each 'foo' to 'bar', but ask for confirmation first.
:%s/\/bar/gc
Change only whole words exactly matching 'foo' to 'bar'; ask for confirmation.
:%s/foo/bar/gci
Change each 'foo' (case insensitive) to 'bar'; ask for confirmation.
This may be wanted after using :set noignorecase to make searches case sensitive (the default).







Comments