osX: Unix commands to get by
Search for a possible commandwhatis /usr/bin/* | grep "search string"
man -k "search string" | grep (1 to return the same results a bit faster
Remove directory recursively
rm -rf directory
Find file
find / -name mydoc.txt -print
find / -name *fungi* -print (regex)
Bulk convert (files to 666, directories to 777)
find . -type f | xargs chmod 666
find . -type d | xargs chmod 777
Find & kill processes
ps -auxww|grep syslogd
the process ID should be the number in the second column.
'kill -HUP xxx" where xxx is the process ID of syslogd.
Move a directory including resource fork
ditto -v -rsrcFork /Users /Volumes/Users
Change the tcp/ip send & receive buffers
sysctl -w net.inet.tcp.sendspace=65536
sysctl -w net.inet.tcp.recvspace=65536
sysctl -w net.inet.tcp.delayed_ack=0
sysctl -w net.inet.udp.recvspace=73728
Tar
1. tar cvzf archive.gz (fileordirectory)
2. tar cvfX - ib | gzip -9 > cgi.tar.gz
selective backup
(write exclude file)
find [directory] ! -type d -print | egrep '/,|%$|mas/|stats/' > excludefile
tar cvzfX [directory].tar.gz excludefile www
unTar
tar -xf archive.tar
tar -zxvf article.tar.gz (uncompress)
crontab
crontab (filename) to use
crontab -l to list current jobs
crontab -r to remove
crontab -e to edit
Emac
* Ctrl-A - go to start of line
* Ctrl-E - go to end of line
* Ctrl-D - delete char
* Ctrl-K - delete rest of line
* Esc-D - delete word
* Ctrl-Y - paste deleted word
* Ctrl-P - previous line/command
* Ctrl-N - next line/command (although who can beat the arrow keys, right?)
* Ctrl-U - wipe out everything
'more' command
spacebar = page down
b = page up
q = quit
? = help, which will show all the commands
Make invisible
sudo SetFile -a V /Volumes/"Audio CD"/
prebind
Update prebind (rebuild library ref)
update_prebinding -root /
Line convert
define an alias = alias mac2unix 'tr "r" "n"'
mac2unix < macintoshfile.txt > unixfile.txt
Apache server toggle
apachectl restart or
apachectl graceful
mysql server
safe_mysqld
apachectl graceful
perl modules
perl -V will show you the versions and the path
perdoc perlmodlib will show you what is installed (by defaults)
perldoc perllocal will show you other modules
perldoc Crypt::CBC or Crypt::Blowfish will show you info on specifc module
Check to make sure the perl modules are actually present:
perl -e 'use CGI qw(:standard); ' > /dev/null 2>1 || echo need CGI
perl -e 'use Mail::POP3Client; ' > /dev/null 2>1 || echo need Mail::POP3Client
perl -e 'use Socket; ' > /dev/null 2>1 || echo need Socket
perl -e 'use MIME::Base64; ' > /dev/null 2>1 || echo need MIME::Base64
perl -e 'use Net::SMTP; ' > /dev/null 2>1 || echo need Net::SMTP
perl -e 'use Crypt::Blowfish; ' > /dev/null 2>1 || echo need Crypt::Blowfish
perl -e 'use Crypt::CBC; ' > /dev/null 2>1 || echo need Crypt::CBC
How to install a module into your local directory and use it in your perl script:
----
add to alias.mine
I'm not sure if this is useful for some, but I use this shell script I wrote for creating and adding aliases to my .cshrc file all the time. I must have 2 or 3 dozen aliases in .cshrc file. Here's the shell script:
#!/bin/sh
echo -n "Enter the CMD you want to make an alias for: " ; read CMD ;
echo -n "Enter the alias without quotes: " ; read ALIAS ;
echo "alias" $CMD "'"$ALIAS"'" >> /Users/$USER/.cshrc
echo " "
tail -1 /Users/$USER/.cshrc
echo " "
echo "You need to relogin now!"
su -l $USER
Save this somewhere in your path, make it excecutable (chmod 755 script_name) and then type 'rehash' to activate it. Now simply type the name of the script when you wish to create a new alias.
web search shortcut script
http://www.macosxhints.com/article.php?story=2002072923444892
For other awkward or unprintable characters, it's often easier to identify the file using the filename completion features built into the shell.?If your file is called myfile^?, say, and it's the only one beginning with myfile, then
removing files with conflicting names:
For the specific case of a leading hyphen, as has been said elsewhere, most Unix commands have a neat way around it: if you give -- as a parameter, then all following parameters are taken as filenames and not as parameters.?So
rm -- -myfile
does the trick very easily, as does
rm ./-myfile
rm myfile*
could hardly be easier.?If the file is harder to separate out, you can use characters after the *, or instead use one or more of the ? wildcard which matches a single character.?You can ensure you're only deleting the right file by trying
ls (whatever)
before doing the
rm (whatever)
Installer follows symbolic links
This may or may not work!
sudo defaults write com.apple.installer FollowLinks -boolean true
Taken from this macosxhints article
Comments?
Leave a comment regarding “osX: Unix commands to get by”
Recent articles in osXosX: ASR - Apple Software RestoreosX: Bootable OSX cd osX: File locations osX: Hdiutil osX: OS 9 partition on new 2003 hardware |
simplicity at its most complex