chownSOFTWARE: unix linux bashchown joe myfile.txt change ownership of files and directories. MORE INFO:untar and tar filesSOFTWARE: unix linux bashtar -zxvf myfile.tar.gz To Untar (decompress)Use to uncompress a tar file on the command line. Should also work for tar files ending in slightly different suffixes: .tgz, .tar.gz etc.
To Untar files with .bz2 suffixModify the flags to be like:
Note the difference between the two commands above is that the first uses the -z flag for gzip, whereas the second uses the -j flag for bzip2. Get more detail about the available flags to use with the tar command with:
To Tar (compress)There are a number of options. Here's an example to tar up two files in your current directory into an archive called "myarchive.tar"
You can also use the "z" flag to use zip/gzip, and the "v" flag to get verbose output. To zip a directory, you just target the directory like you would for a file and it'll go recursive by default:
MORE INFO:
scpSOFTWARE: unix linux bashscp -r servername:/remotedir /localdir/localsubdir Copy directory across boxes using scp. You can use . to signify "here" (this directory) when designating where to copy files to in the second argument if you're already in the location you want to copy your files to.
The example above assumes your copying from a remote machine to your local machine. If you want to do it the other way around, just flip the first and second arguments like:
Also, to add the remote user that you want to connect as on the remote server, use username@servername:/path/filename:
MORE INFO:
ssh agentSOFTWARE: unix linux bashssh-agent bash (hit enter) ssh-add (hit enter) use to add auth to your shell so you can automatically access a number of boxes. It's two part, so run "ssh-agent bash" first, then "ssh-add". MORE INFO:chmodSOFTWARE: unix linux bashchmod 755 myfile.txt To change permissions in Unix, use "chmod". Number MethodIt's tricky to remember which numbers to use, so find out quickly with the online calculator. Then, the format to use is:
Example:
Or for a directory, use recursive flag (-R) to catch all contents:
Regular MethodFor "who" will get the permissions you've got (u)ser, (g)roup, and (o)thers. And the available permissions are: (r)ead, (w)rite, and e(x)ecute. The format is
Example to add write permission for user:
Or to set all users to no permissions:
Which could also be set with:
Comma separate different user operator permission sets:
MORE INFO: http://en.wikipedia.org/wiki/Chmod
tailSOFTWARE: unix linux bashtail -f production.log View just the end of a file. Useful for watching the results of actions scroll by in logs. Get n number of last lines (ie 40):
MORE INFO: http://en.wikipedia.org/wiki/Tail_(Unix)
reverse search command in shellSOFTWARE: unix linux bashctrl_key + r + [start typing command to recall ...] Use this command sequence to search through recently used commands in the shell. Faster than using the up and down arrows to scroll through recent commands if you know what your command you want to recall started with. -source: A. Limi. MORE INFO:logsSOFTWARE: unix linux bashWhereAccess logs by checking out the /var/log directory on many nix systems. Scanning
Type this (replace with whatever your log is called) in the shell and leave shell open while you hit pages to see what's goin' on:
MORE INFO:
rsync at site5 hostingSOFTWARE: unix linux bashrsync -avz -e ssh username@www.yourdomain.com:/home/username/remotedir /path/to/localdir An example of using rsync (through ssh tunnel) to download an archive (-avz settings) of remote_dir which lives in your /home/username directory at site5:
Could be good in conjunction with this cool backup shell script: Reference URL for this cheat is a good tutorial for using rsync. Here's an entire workflow for gettting live stuff not only backed up, but also mirrored onto your dev box automatically. Kind of a reverse staging->production thing ... MORE INFO: http://everythinglinux.org/rsync/handy vi commandsSOFTWARE: unix linux bash:$ end of file, :0 top of file A few handy things in the vi text editor:
search directory with grepSOFTWARE: unix linux bashgrep -r -i termtofind pathtodirectory When grepping through an entire directory, use the -r (recursive) flag to search the whole thing.
As always, the . for "here" can be nice, as in:
MORE INFO:
clear terminal screenSOFTWARE: unix linux bashclear Just type clear and hit return to clear the terminal window. Quick way to get a nice clean window in which to work if it gets cluttered. MORE INFO:SSH RSA KeysSOFTWARE: unix linux bashgenerate keypair > trxfr public key (idrsa.pub) to remote "authorizedkeys" file This is a note on the "big picture" with keys. IE visualizing what's actually going on. Details on the actual commands to use are available at: The Big PictureThere are three main files that live under .ssh/ They are:
So the basic steps are:
Code
Other NotesYou can also authenticate via bash once with "ssh-agent bash", "ssh-add". This will load your auth into cache so you can ssh around without having to re-enter the passphrase each time. I believe the "known_hosts" file under your local .ssh directory forms a sort of secure handshake between the two keys so that once you've been prompted to accept the connection once, it will not have to prompt you again to accept. If you removed an entry from this file for a given connection, it would give you the original prompt again asking if you want to trust. If you already have a keypair on your local machine, you can simply add the id_rsa.pub file up to the remote .ssh/authorized_keys file. This way you'll be prompted for the same passphrase you normally use. Non-password or non-default key pathIf you want to have no passphrase required, you can create a new keypair. Give it a unique name when creating so you don't overwrite your main keys. Simply hit Enter when prompted for the passphrase for the keys when you make them. Less secure obviously. So use with caution only when you need to (IE with a Cron script that requires it.) In a case like this where you have multiple keys, you need to manually designate which key to use when connecting to a server via ssh, so do something like:
MORE INFO: http://troy.jdmz.net/rsync/index.html
Mail CommandsSOFTWARE: unix linux bashtype "mail" to access email in terminal A quick cheatsheet of commands for unix mail:
Mac OS X Tiger CronSOFTWARE: unix linux bashsudo vi /etc/crontab crontab -e to generate crontab for specific user wasn't getting kicked off by the daemon, so I just used the main crontab in /etc/crontab instead.
Note that the format for cron jobs in the main crontab includes WHO as well like so:
So be sure to designate which user you want to run the command as well. IE to have a user kirk run the command 'doublekick.sh' at 9am:
MORE INFO:
disk space reportSOFTWARE: unix linux bashdf -h OR du -sh /path/to/dir (for just a directory) The whole boxCheck disk space on linux box.
the h flag prints the space in Megs and Gigs instead of K. A specific directoryUse du to check a specific directory. The -s flag makes it a summary for the whole directory, and the -h flag makes it Megs and Gigs instead of K.
Get help and additional flag options with the usual:
MORE INFO:
shutdown or restart linuxSOFTWARE: unix linux bashshutdown -r now To restart (-r flag) right away (now), the basic command is:
Or, you can pass another time instead of now. For example, restart in two minutes:
And, you can add a comment to flash to users:
Actual shutdown instead of restart is the -h flag (halt)
MORE INFO:
Encrypt dmg (Mac OSX)SOFTWARE: unix linux bashhdiutil create -encryption -stdinpass -srcfolder private encrypted.dmg Lifehacker has a link to how to create an encrypted dmg. Also includes info on how to set up with disk utility. At command lineTo create an encrypted disk image with the name "encrypted.dmg" with contents from the source folder "private" in your current location:
Enter password at prompt. Decrypt:
http://lifehacker.com/software/mac-tip/create-an-encrypted-disk-image-at-the-command-line-279005.php With disk utility app
Once it's made, you can double click to open it, add files, modify etc. Just eject it to unmount. Subsequent times you click it to open, you'll be prompted for password. MORE INFO: http://lifehacker.com/software/mac-tip/create-an-encrypted-disk-image-at-the-command-line-279005.phptelnet to test address and portSOFTWARE: unix linux bashtelnet ip_address port The ping command is cool for testing a connection to an ip address. If you need to test a specific port, tho, you can open a shell and type:
IE
If you get a connection, it works. Escape with:
Quit with "quit" Works in nix and PC shells. MORE INFO:install from sourceSOFTWARE: unix linux bashuntar > cd to dir > ./configure > make > make install Install from sourceOn mac os x, make sure you have developer tools installed. Using MacPorts or Fink is a lot easier since then you're downloading a package and patches and things you might need for mac os x are already taken care of. But when you need to go straight to source, here's the deal. Locate the file on the net via a google search or whatever. Download the file with your browser. Or, if you want to be fancy pants and download via the shell, you can use software like curl to get it:
"myfile.txt" is what the download will be called on your machine. You can just enter the actual name of the file you're grabbing to keep it simple. Extract the file. On mac, you can just double click many compressed files to open. Or you can do it by hand depending on the compression type. For tar files use:
Now, change directory into the location of the extracted software:
If you look in the directory with ls, you should see a file called "configure". So run:
Or, some builds will want you to supply arguments such as:
So add those if you need them. I'm a bit vague on this, but it would appear that if you want your software installed in /usr/local/bin most of the time, you should include the --prefix argument as above when you run ./configure. Get help about configure with:
If you're lucky you can find some documentation for the software you're installing. Anyway, once the build is configured we can move on to generating the make with "make"
And now we need to actually install with :
PrecompiledSome software downloads are available as "precompiled" for a given os. Installation methods may vary. You might be able to simply drop into the appropriate folder on your system and be done, or the software may have had "configure" run on it, but still need to have "sudo make install" run to actually install. MORE INFO:findSOFTWARE: unix linux bashfind location -name "file_name" To search in the terminal for files and things: use the find command and designate where you want to look, followed by -name and the filename in quotes. To search for a file called .bash_profile in your home directory (~):
Or, if you want to find a name that contains certain characters, but you're not sure exactly what it's called, use the * operator:
You can use this same idea to find a filetype based on its extension. For example to find all pdf files:
A bunch of other cool tricks with find are in the tutorial listed as the reference URL for this cheat. Find xml files containing mystring:
MORE INFO: http://dmiessler.com/study/find/
suse yast rpm cheatnotesSOFTWARE: unix linux bashtype "yast" in shell to access setup A few notes on sysadmin of suse 10.x. Yast provides a bunch of admin options for your suse box. Alternatively, you can manage packages manually via the rpm command in the shell. Below are a few notes on both. YASTType "yast" in the terminal to open up the "yet another setup tool" in suse linux. Good stuff because it provides a bunch of options via an ncurses interface and can be easier to use than direct rpm commands etc.
When accessing via a mac and ssh, some of the commands for navigating the ncurses interface weren't working right (IE alt + H doesn't take.) So I just started using TAB which zips you around thru all available options on the screen.
Http Server info is in Network Services > HTTP Server. Lots of fun stuff in there. That's where you install apache2 mods. Tab over to "Server Modules" to configure them. If you don't see one listed that you want to enable for apache2, back out to the root of yast interface and use Software Management to add the required mod package first. To install, uninstall, upgrade software packages, go to Software Management in yast. RPM Commandsrpm commmands are a bit cryptic. Here are a few: Help:
Manual:
List all installed packages (query all):
Only list installed packages with "mod_" in the name:
To get info about a package:
To get package file list:
Package Docs/usr/share/doc/packages MORE INFO:suse yast zope configSOFTWARE: unix linux bashyast > System > /etc/sysconfig Editor For zope on SUSE Linux: Normally, you edit your conf for zope in:
But yast can manage your configuration settings for zope. This option is toggled on/off in yast under:
Tab thru the options here to toggle config options on/off. If the option to manage has been toggled on in yast, then changes you make directly to zope.conf on the filesystem can cause mismatch errors. You can also modify the config settings directly on the command line via:
Note that if you toggle debug mode to on, and your server fails to start, it's because any errors cause startup to fail, rather than simply logging them. You can inspect the event log (/var/opt/zope/default/log/event.log) to find out what might be killing your server. I had a bad product sitting in Products that I didn't notice in production mode since it just failed to show up, but didn't hurt anthing ... until I switched the zope server to debug. MORE INFO:symlink (symbolic link)SOFTWARE: unix linux bashln -s target link_name To create a symbolic link from link_name that points to the actual stuff at target:
In other words it's like:
Here's an example that makes a link called "DIYPloneStyle" in the Products directory and points to the actual stuff in the Plone-3rd-Party directory:
MORE INFO: http://en.wikipedia.org/wiki/Symbolic_link
quick colorize terminal when ssh to another boxSOFTWARE: unix linux bashalias ls='ls --color' Mac OS X TerminalA quick and dirty way to get mac terminal to colorize files when you're ssh'd to another (remote linux) box. ssh to the remote server, then do:
this will set the --color flag for the ls command to always (default), which makes the results of listing a directory colorized by file type. On your own local machine, you can modify your .bash_profile to include something like this:
A bit cryptic to figure out the colors to designate, but nice because it always works on your local machine's shell. More info about how this stuff works on the linux side via:
To colorize your terminal in mac: just alias ls -G to ls.
MORE INFO:
copy common files (ie plone upgrade)SOFTWARE: unix linux bashcp -R mydir /path/to/PARENTdir Copy only same contentsYou can use this trick when upgrading plone for example. You get your new distro from plone.org and you want to cp the Products and lib folders over your old install. But, you've added some stuff (additional products etc) and you want to keep those during the upgrade. If you copy (cp -R) a directory and give it a target of the parent of a subdirectory with the same name, you'll only overwrite the files that are common to both. So an example is that I have a "Products" directory with some new versions of stuff, and I want to copy it over my old Products directory which lives in a directory called "default". I do:
This way, I get to keep my old stuff that I may have added to the old Products directory and not worry about clobbering all that stuff. MORE INFO:regexp match NOT stringSOFTWARE: unix linux bash^(?:(?!mystring).)*$ To match anything but the string "mystring":
MORE INFO: http://wiki.tcl.tk/986
Add a UserAdd a user called "webadmin" to a linux server. This adds them to the "www" group. Gives them the bash shell. Lets them sftp in and work on stuff.
useradd -c "add a comment here" -m -g www -s /bin/bash webadminHelp is available for "useradd":
useradd --helpSet the password for the new "webadmin" user with:
passwd webadminBecause they're part of the www group, change user/group on the directories and files if you need to so apache owns them:
chown -R wwwrun:www [directory name]Now give the "www" group permissions to the stuff the user will work on:
chmod g+x [directory]chmod g+w [files] |