chris clarke
software development that works…or something
GNUs Not U
January 24, 2007 on 7:56 pm | In Unix |Highlight some expression using colour:
grep --color expression file
Go to a dir, execute a command and return to the current directory:
(cd dir && command)
A stopwatch:
time cat ^D
Download a url at 1 AM:
echo 'wget url' | at 01:00
Do some sums:
echo "monkeys=24; monkeys * 6 / 4" | bc
Convert a string to lowercase:
echo 'TeSt' | tr '[:upper:]' '[:lower:]'
List files that a process has open:
lsof -p 483
List processes that have the specified path open:
lsof ~
Display a webpage (MAC/BSD):
wget -qO - http://www.cheese.com > tmp.html && textutil -stdout -convert txt tmp.html
Look for a word case insensitively:
cat Names | grep -i demarco
Search and replace:
cat index.html | sed 's/Google/MSN/g'
Print lines 10 to 20:
cat index.html | sed -n '10,20p;20q'
Time how long it takes to calculate PI to 5000 decimal places:
time echo "scale=5000; 4*a(1)" | bc -l
Convert binary to decimal:
echo "obase=10; ibase=2; 01111111" | bc
Perform a calculation on some output:
ls -al *.html | awk '{sum+=$5} END{print sum}'
Fix typos in files but backup the original files:
perl -p -i.old -e 's/oldstring/newstring/g' *.txt
Execute a command on several computers:
perl -e 'for("B","C","D"){`scp command.pl $_:`; `ssh $_ command.pl`; }'
Look for a regular expression:
cat index.html | perl -ne 'print if /font-size:\s*\d+px/'
Print selected lines of a file:
cat buildOutput.txt | perl -ne 'print if 1..2'
Can you think of another way to print selected lines?
Comma-delimit:
ls -l | perl -wne 'BEGIN{$" = ","} @fields = split/\s+/; print "@fields\n";'
Find a file without the “permission denied” messages:
find . -name 'monkeys.txt' 2> /dev/null
No Comments yet »
RSS feed for comments on this post. TrackBack URI
Leave a comment
GNUs Not U
January 24, 2007 on 7:56 pm | In Unix |Highlight some expression using colour:
grep --color expression file
Go to a dir, execute a command and return to the current directory:
(cd dir && command)
A stopwatch:
time cat ^D
Download a url at 1 AM:
echo 'wget url' | at 01:00
Do some sums:
echo "monkeys=24; monkeys * 6 / 4" | bc
Convert a string to lowercase:
echo 'TeSt' | tr '[:upper:]' '[:lower:]'
List files that a process has open:
lsof -p 483
List processes that have the specified path open:
lsof ~
Display a webpage (MAC/BSD):
wget -qO - http://www.cheese.com > tmp.html && textutil -stdout -convert txt tmp.html
Look for a word case insensitively:
cat Names | grep -i demarco
Search and replace:
cat index.html | sed 's/Google/MSN/g'
Print lines 10 to 20:
cat index.html | sed -n '10,20p;20q'
Time how long it takes to calculate PI to 5000 decimal places:
time echo "scale=5000; 4*a(1)" | bc -l
Convert binary to decimal:
echo "obase=10; ibase=2; 01111111" | bc
Perform a calculation on some output:
ls -al *.html | awk '{sum+=$5} END{print sum}'
Fix typos in files but backup the original files:
perl -p -i.old -e 's/oldstring/newstring/g' *.txt
Execute a command on several computers:
perl -e 'for("B","C","D"){`scp command.pl $_:`; `ssh $_ command.pl`; }'
Look for a regular expression:
cat index.html | perl -ne 'print if /font-size:\s*\d+px/'
Print selected lines of a file:
cat buildOutput.txt | perl -ne 'print if 1..2'
Can you think of another way to print selected lines?
Comma-delimit:
ls -l | perl -wne 'BEGIN{$" = ","} @fields = split/\s+/; print "@fields\n";'
Find a file without the “permission denied” messages:
find . -name 'monkeys.txt' 2> /dev/null
No Comments yet »
RSS feed for comments on this post. TrackBack URI
Leave a comment
Powered by Cheese.
RSS Entries Feed.
RSS Comments Feed
^Top^