Tech Musings

Wednesday, December 14, 2005

Useful UNIX/LINUX commands

Here are some useful commands I use frequently in the terminal:

Examples of how to use UNIX / Linux find command to locate files and directories here. Note, the find command is much slower than locate because it searches the file system in real time.

sudo tar -cvzf mytar.tar.gz mytar sourcefilesordir create tar file (check permissions if it fails)
tar -xvfz mytar.tar.gz destination extracts gzipped (compressed) tar file
tar -xvf mytar.tar destination extracts tar file
tar -yxf mytar.tar.bz2 need bzip2 installed (/usr/ports/archivers/bzip2)
gzip fileordir compress a file with gzip
gunzip file.gz decompresses a file with gzip

uname -v to determine which version (or flavor?) of unix / linux you are running (i.e. how to tell which underlying kernal type is installed on your OS X or OS 10 Server machine). You can also gather this information on the readout from your phpinfo() page.

less /etc/filename (displays text file one page at a time; scroll forward with "f", backward with "b", "h" to list commands, and "q" to exit).

cat /etc/filename (displays entire file; also use to create a new file cat>newfilename; close file using ^D).

head -5 /etc/filename (displays the first five lines of a file).

tail -5 etc/filename (display last five lines; use the -f option to cause tail not to stop when end of file is reached).

^C stops a current job while ^Z suspends the current job.
jobs list background processes
kill stops a running process
ps lists running processes and their status.
top -u also lists running processes (I think).

grep home /etc/filename.txt (displays all lines containing home in the file filename.txt).
grep -r -i home /etc/postfix (displays all files containing the word home in the directory /etc/postfix and ignore case). By default, GREP's pattern searches are case sensitive!
grep hello *.txt -in | more (reads all files ending in .txt in the current working directory looking for the word hello. It then prints out the file name and line number where the word hello was found and pipes the output into "more" in case there is A LOT of it! Thanks to Jason Lambert for this helpful example!).

shutdown -r now or sudo /sbin/reboot to restart OS X Server.

chown -R user /Path/To/Directory [changes ownership]
chgrp -R groupname * [changes if all files in current directory]
chmod -R 755 (a+x) /Path/To/Directory [changes permissions]
ls -a [shows hidden files]
ls -l [shows permissions of files]
ssh -l admin 10.5.67.987 [login to a remote computer as user admin]
su user changes user
rm -r -f directoryname dump entire directory of files regardless of whether or not the files are write protected (i.e. folders full of stubborn OS 9 locked files you can't empty from your GUI trash can!)
pwd print working directory; helpful when discerning a directory's full server path for use in things like upload scripts and the like.

UPDATE 8/3/07


To chmod or chown all files in the current directory use * as the wild card. If you need to recurse through subdirectories use chmod -R.

sudo chmod 755 -R *
sudo chown -R trevor /Users/trevor/Music/iTunes\ Music

0 Comments:

Post a Comment

Links to this post:

Create a Link

<< Home