fgrep -r "something" . (or *)
tail -f (or a number) somefile
cat file1 >> file2
tar zcfv filename.tar.gz somedir
tar zxfv filename.tar.gz
telnet hostname portnumber
a2ps -o ‘outfile.pdf’ ‘infile’
mysqladmin -u root password ‘root password for mysql’
//or after mysql -u root
mysql>SET PASSWORD FOR root@localhost=PASSWORD(‘rootpassword’);
sed:
this command is great. I been using it to make my almost 300 web files be recognized as utf-8 in 1 second so that no bizzard charater showing on the webpage if you don’t change the charcter encoding:
for i in *; do sed "s/<head>/<head><meta http-equiv="Content-type" content="text\/html; charset=utf-8">/' $i > tmp; mv tmp $i; done;
If we want to replace all the “old” with “new” for a file “test”. We can do this by doing the following:
sed -e 's/old/new/g' test > test2 mv –f test2 test
This one deletes empty lines or lines that only contain spaces:
sed -e '/^ *$/d' sedtest1.txt
This one replace foo with foo_bar in multiple file:
sed -i 's/foo/foo_bar/g' *.module
This one is pretty dangerous:
#!/bin/bash
sed -f sedscript filename.txt > tempfile
mv tempfile filename.txt
with sedscript file as follows:
s/Apples/Oranges/g
better replace the shell script like this:
#!/usr/bin/shmkdir ${SAVED:=saved} || exit 1for files in `find . -type f` do sed -f sedfile $file >qqfile [ -s qqfile ] || continue # sed error, NO output cp $file $SAVED/`echo $file|sed 's/\//---/g'` cp qqfile $file done
awk or gawk examples from http://www.ss64.com/bash/gawk.html:
This program prints the length of the longest input line:
awk '{ if (length($0) > max) max = length($0) } END { print max }' data
This program prints every line that has at least one field. This is an easy way to delete blank lines from a file (or rather, to
create a new file similar to the old file but from which the blank lines have been deleted)
awk 'NF > 0' data
This program prints seven random numbers from zero to 100, inclusive.
awk 'BEGIN { for (i = 1; i <= 7; i++) print int(101 * rand()) }'
This program prints the total number of bytes used by FILES.
ls -lg FILES | awk '{ x += $5 } ; END { print "total bytes: " x }'
This program prints a sorted list of the login names of all users.
awk -F: '{ print $1 }' /etc/passwd | sort
This program counts lines in a file.
awk 'END { print NR }' data
This program prints the even numbered lines in the data file. If you were to use the expression `NR % 2 == 1′ instead, it would print the odd numbered lines.
awk 'NR % 2 == 0' data