Wednesday, October 17, 2007

Favorite Unix Commands

I am by no means a unix expert and don't use it often enough to have these commands at my fingertips, so I collecting them in one place:

Restart Server:
shutdown -r now

What's running:
ps aux

What using up disk space
du -k | sort -rn | head -20

Check for latest package:
rpm -qa | grep "mysql"

To replace all instances of oranges with bananas in the file mytext.txt

sed -e 's/oranges/bananas/g' mytext.txt

This will display the file with changes. I havn't found a way of making the changes in situ, but to write the output to a new file:

sed -e 's/oranges/bananas/g' mytext.txt > newfile.txt

20 most recently updated files:
find . -type f -printf '%TY-%Tm-%Td %TT %p\n' | sort -r | head -20

What's using memory
top

Value of environment variables set
export


List of all files recursively, containing text
grep -lir "no todo" *

4 comments:

Unknown said...

try
sed 's /word/new-word/' my text

the -e option informs sed that more than one set of editing instructions is to follow:
sed -e 's/Veg/VEG/' -e 's/Meat/MEAT/' mytext

I don't think the mytext > mytextcopy is necessary, but you might try a further mytext < mytextcopy to see what happens.

Unknown said...

no gaps between

sed 's/word/new-word/' mytext

Phoebe Bright said...

thanks

Phoebe Bright said...

Delete all .svn directories recursively:

rm -rf `find . -name .svn`