| A | B | C | D | E | F | G | H | I | J | K | L | N | M | O | P | Q | R | S | T | U | V | W | X | Y | Z |
My very own UNIX cheatsheet - see last update info at end of file. This page is encoded in ISO-8859-1.
Apache folder browsing -- set column widths in httpd.conf:
IndexOptions DescriptionWidth=* NameWidth=*
Apache codes:
Successful Client Requests 200 OK 201 Created 202 Accepted 203 Non-Authorative Information 204 No Content 205 Reset Content 206 Partial Content Client Request Redirected 300 Multiple Choices 301 Moved Permanently 302 Moved Temporarily 303 See Other 304 Not Modified 305 Use Proxy Client Request Errors 400 Bad Request 401 Authorization Required 402 Payment Required (not used yet) 403 Forbidden 404 Not Found 405 Method Not Allowed 406 Not Acceptable (encoding) 407 Proxy Authentication Required 408 Request Timed Out 409 Conflicting Request 410 Gone 411 Content Length Required 412 Precondition Failed 413 Request Entity Too Long 414 Request URI Too Long 415 Unsupported Media Type Server Errors 500 Internal Server Error 501 Not Implemented 502 Bad Gateway 503 Service Unavailable 504 Gateway Timeout 505 HTTP Version Not Supported
ASCII and other control characters and sets - various notes.
Decimal values of upper case ASCII characters 6....7....7....8....8....9....9.... 5 0 5 0 5 0 5 ABCDEFGHIJKLMNOPQRSTUVWXYZ Decimal values of lower case ASCII characters 9...10...10...11...11...12...12.... 5 0 5 0 5 0 5 abcdefghijklmnopqrstuvwxyz
Some ASCII Control characters:
^@ Ctrl+@ null character NUL \0 0x00 octal 00 decimal 0
Ctrl+I horizontal tab HT \t 0x09 octal 11 decimal 9
^J Ctrl+J line feed LF \n 0x0A octal 12 decimal 10
^K Ctrl+K
^L Ctrl+L form feed FF \f 0x0C octal 14 decimal 12
^M Ctrl+M carriage return CR \r 0x0D octal 15 decimal 13
See Wikipedia entry here for really nice tables.
See also http://skyprod.net/pub/HintsAndTips/ASCIIendline/
http://www.asciitable.com/
http://en.wikipedia.org/wiki/C0_and_C1_control_codes
http://learnlinux.tsf.org.za/courses/build/shell-scripting/ch03s02.html#fullstop
http://www.unix.com/unix-dummies-questions-answers/41277-how-convert-m-appearing-end-line-unix-newline.html
See also vi and vim below.
Escape and reset at the end of line to destroy settings: this can be done by using \033[0m at the end of the line.
Specify $EINS\033[x;y where x is text attributes, y is text foreground .. and THEN
Specify $EINS\033[x;y;z where x is text attributes, y is text foreground, z is background.
Non-printing escape sequences have to be enclos`d in \[\033[ and \]. For colour escape sequences, they should also be followed by a lowercase m. See http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/x329.html as of 2010-05-20.
# # Text attributes # 0 All attributes off # 1 Bold on # 4 Underscore (on monochrome display adapter only) # 5 Blink on # 7 Reverse video on # 8 Concealed on # #Foreground colors # 30 Black # 31 Red # 32 Green # 33 Yellow # 34 Blue # 35 Magenta # 36 Cyan # 37 White # #Background colors # 40 Black # 41 Red # 42 Green # 43 Yellow # 44 Blue # 45 Magenta # 46 Cyan # 47 Whit
Some examples as you might use them in a BASH script:
echo -en "$EINS\033[1;031\033[1;031;47m 24 bold red on white OK\033[0m\n";
echo -en "$EINS\033[1;030\033[1;030;46m 25 bold black on l blue OK\033[0m\n";
echo -en "$EINS\033[44;1;31m 26 - light red fg blue back test #1 OK \033[0m\n";
echo -en "$EINS\033[44m\033[1;31m 26 - light red fg blue back #2 OK \033[0m\n";
echo -en "$EINS\033[0m\033[0;00m 26 - should be normal OK \033[0m\n";
Awk is most oftem used to split a delimited stream into tokens:
echo `date` | sed 's/\// /g' | awk '{print " " $1 " " $2 " " $3 " " $4 " " $5 " " $6}'
Thu 22 Dec 2011 18:40:10 CST
Awk uses a blank as the default delimiter:
while read line
do
echo $line | awk '{print $0}' # prints the whole string
echo $line | awk '{print $1}' # prints the 1st part of the string delimited using a blank.
done
ps;kill `ps | grep xterm | grep system.log | grep -v grep | awk '{print $1}'`
There are lots of ways to do this but here's one simple example that is not very hard to read:
# Using sed and awk to split the actual $HOME string directly into string variables part1 and part2 ..
# splits the tokens of the folder name assuming it's a UNIX-styler home folder name formatted like /token1/token2
part1=`echo $HOME | sed 's/\// /g' | awk '{print $1}'`
echo $part1
part2=`echo $HOME | sed 's/\// /g' | awk '{print $2}'`
echo $part2
BASH is a big subject but here are things I have found very useful and want to have a quick reference to.
if [ -s "/tmp/$NOW.html" ]
then open -a Firefox.app "/tmp/$NOW.html"
else echo "No results"
fi
# Split the tokens of the $HOME folder name - assuming it's a UNIX-style name formatted like /token1/token2
SRCDpart1=`echo $HOME | sed 's/\// /g' | awk '{print $1}'`
echo $SRCDpart1
SRCDpart2=`echo $HOME | sed 's/\// /g' | awk '{print $2}'`
echo $SRCDpart2
# Set up a list of sub-folder names (single level)
FOLDERS="Documents Downloads Library Sites Xcode"
# Process the list
for folderName in $FOLDERS
do
NOW="$(date +%Y-%m-%d.%H%M)"
echo " starting $foldername at $NOW"
tar -cvzf $TGTD/$HOST.$SRCDpart1.$SRCDpart2.$folderName.$NOW.tgz $SRCD/$folderName
echo " using command tar -cvzf $TGTD/$HOST.$SRCDpart1.$SRCDpart2.$folderName.$NOW.tgz $SRCD/$folderName"
echo " starting $foldername at $NOW"
NOW2="$(date +%Y-%m-%d.%H%M%S)"
echo " ended $foldername at $NOW2"
done
There are always three default files open, stdin (the keyboard), stdout (the screen), and stderr (error messages output to the screen). These, and any other open files, can be redirected. Redirection simply means capturing output from a file, command, program, script, or even code block within a script and sending it as input to another file, command, program, or script.
Each open file gets assigned a file descriptor. The file descriptors for stdin, stdout, and stderr are 0, 1, and 2, respectively. For opening additional files, there remain descriptors 3 to 9. It is sometimes useful to assign one of these additional file descriptors to stdin, stdout, or stderr as a temporary duplicate link. This simplifies restoration to normal after complex redirection and reshuffling.
Examples:
# Single-line redirection commands (affect only the line they are on):
# --------------------------------------------------------------------
1>filename
# Redirect stdout to file "filename."
1>>filename
# Redirect and append stdout to file "filename."
2>filename
# Redirect stderr to file "filename."
2>>filename
# Redirect and append stderr to file "filename."
&>filename
# Redirect both stdout and stderr to file "filename."
# This operator is now functional, as of Bash 4, final release.
See http://tldp.org/LDP/abs/html/io-redirection.html
#!/bin/bash ls data.*.txt | cut -c 1-28 > "/tmp/datalist.txt" # open file "/tmp/datalist.txt" for reading exec 6<"/tmp/datalist.txt" # read until end of file while read -u 6 dta do echo "$dta"; dta2=$dta; # echo "$dta2" done # close file exec 6<&- echo "Last file listed was: $dta2" exit
case "$HTTPcode" in
"304" )
echo -en "$EINS\033[43m$line\033[0m\n"
;;
"400" )
echo -en "$EINS\033[41m$line\033[0m\n"
;;
"404" )
echo -en "$EINS\033[45m$line\033[0m\n"
;;
* )
echo -en "$EINS\033[32m$line\033[0m\n"
;;
esac
NOW="$(date +%Y-%m-%d.%H%M)";echo "$NOW" will output: 2010-10-18.1738
HTTPcode=`cat readlog.work.file.txt`
echo "HTTPcode is $HTTPcode"
Awk uses a blank as the default delimiter:
while read line
do
echo $line | awk '{print $0}' # prints the whole string
echo $line | awk '{print $1}' # prints the 1st part of the string delimited using a blank.
done
There are lots of ways to do this but here's one simple example that is not very hard to read:
# Using sed and awk to split the actual $HOME string directly into string variables part1 and part2 ..
# splits the tokens of the folder name assuming it's a UNIX-styler home folder name formatted like /token1/token2
part1=`echo $HOME | sed 's/\// /g' | awk '{print $1}'`
echo $part1
part2=`echo $HOME | sed 's/\// /g' | awk '{print $2}'`
echo $part2
bc is a command line calculator. For example:
echo "1+3;./2" | bc
will return ..
4 2
See http://hints.macworld.com/article.php?story=2001020700163714 for a good discussion.
In OSX, /etc/crontab says: ------------------------- # The periodic and atrun jobs have moved to launchd jobs # See /System/Library/LaunchDaemons # # minute hour mday month wday who command 1) Use cp -pr /etc/crontab ~/.crontab to copy this 2) Use crontab .crontab to add this to cron's list 3) Now use crontab -e to edit and then check the crontab # Format used in /etc/crontab: # # minute hour mday month wday who command # # Format to be used in ~/.crontab: # # minute hour mday month wday command # # NOTE: Use TAB to separate entries! # # Here are mcook's crontab entries: # 0 * * * * cd ~/Sites/bm;chmod +r *;logger mcook ~Sites/bin chmod +r 15 * * * * cd ~/Sites/bm;chmod +r *;logger mcook ~Sites/bin chmod +r 30 * * * * cd ~/Sites/bm;chmod +r *;logger mcook ~Sites/bin chmod +r 45 * * * * cd ~/Sites/bm;chmod +r *;logger mcook ~Sites/bin chmod +r 4) Use crontab -l to list your cron tables. Here are some more examples of entries in root's format: # minute hour mday month wday who command 23 17 * * * /etc/webmin/cron/tempdelete.pl #Delete Webmin temporary files 7 12 * * * /etc/webmin/cron/tempdelete.pl #Delete Webmin temporary files
In Linux: -------- sudo crontab -l 25 23 * * * /etc/webmin/cron/tempdelete.pl #Delete Webmin temporary files 0,15,30,45 * * * * chmod -R +r /var/log/* && logger -i -s -p local3.info system.info -t root_cron_set_var_log_star_chmod_R_plus_r -- root_cron_set_var_log_star_chmod_R_plus_r
Embed an external stylesheet like this:
<head> <link rel=stylesheet href="http://skyprod.net/css/css2.css" type="text/css"> </head>
date returns e.g. Mon Dec 26 03:26:44 CST 2011 on OSX 10.4.11 (PPC).
date returns e.g. Mon 26 Dec 2011 03:29:15 CST on OSX 10.7.2 (x64).
Use man strftime to review how the output of the date command can be formatted.
NOW="$(date +%Y-%m-%d.%H%M)" gets the current date and time in YYYY-MM-DD.HHMM format useful for timestamping files in Bash.
RFC-822 date format (RSS "pubDate") is Mon, 26 Dec 2011 03:29:15 CST.
date "+%a, %b %d %Y %H:%M:%S %Z" will return Mon, Dec 26 2011 03:51:39 CST on PPC and x64.
date "+%s" returns the number of seconds since the Epoch as expressed by gettimeofday, for example 1324895338 was Mon 26 Dec 2011 04:28:58 CST. The time is expressed in seconds and microseconds since midnight (0 hour), January 1, 1970 UTC. Use date -r 1324895338 to reverse this to Mon 26 Dec 2011 04:28:58 CST.
See also T
df -- display (list) space per volume
diff f1 f2
date;diff -qr '/Library/Apache2/htdocs/skyprod.net' \ '/Volumes/FILE SYSTEM/var/www/Documents2/skyprod.net' | \ grep -v -e 'DS_Store' -e 'Thumbs' | sort > \ diffs.MONAwwwskyprod.net.BERTHAwwwskyprod.net.2008-01-09g.txt;date
df -k -F cifs -- display (list) active cifs shares, gives output like this:
mcook@bertha:/mnt/mona/mcook/Documents$ df -k -F cifs Filesystem 1K-blocks Used Available Use% Mounted on //mona/mcook 156155904 104329216 51826688 67% /mnt/mona/mcook
df -k -F smbfs -- display (list) active smbfs shares
du -- displays (lists) the size in blocks of all files in all sub-folders
du -s -- just works in this folder
du -sh -- human output (e.g. 4.5G, 250M)
du -csh -- total, summary only, human output (e.g. 4.5G, 250M)
Use the eject command to open your CD-ROM drive
See emacs.3.html as of 2011-12-31.
Find all files in the current folder whose names include the string "emacs" (with folder recursion):
find . -type f | grep emacs
Find all files in the current folder that contain the string "emacs" (with folder recursion):
find . -type f | xargs grep -l emacs | less
Find all file names in the current folder that contain the string "cout" (with folder recursion):
find . -print | grep -e cout | less
Find all lines within files in the current folder that contain the string "cout" (with folder recursion):
find . -print | xargs grep -e cout | less
Sometimes xargs will object to special characters (like quotes and blanks) in file names and you will get a message such as "xargs: unterminated quote". If so you can use the following:
To find all file names in the current folder that contain the string "Diary" (with folder recursion):
find . -type f -print0 | xargs -0 grep -l 'Diary'
To find all lines within files in the current folder that contain the string "Diary" (with folder recursion):
find . -type f -print0 | xargs -0 grep -e 'Diary'
Find using globbed name:
find ~/Journalism -name '*.txt'
Find using globbed regex for pathname (any depth):
find ~/Programming -path '*/src/*.c'
This will show only lines containing the expression defined by -e:
cat skyprod.net.access_log.0-text.txt | grep -e 's0106001346a25c35.wp.shawcable.net' | less
This will show only lines that do not contain the expression:
cat skyprod.net.access_log.0-text.txt | grep -v -e 's0106001346a25c35.wp.shawcable.net' | less
See also the section on the diff command above.
Use grep together with wc to count instances of a word in a file:
# Now count instances of "RSSpermalink"
count=`grep -o RSSpermalink production-feed2.xml.tmp | wc -w`
Ctrl-X, d ... go to directory
Home Esc < ... go to first line of panel
End Esc > ... go to last line of panel
Esc+s+d ... sort this panel by last modified date
Esc+s+n ... sort this panel by name
^S, ^Xs
Incremental search forward a file name in the current panel
(isearch-forward). Pressing ^S or ^Xs again will
force gitfm to go to the next entry that matches the current
isearched string. When the end of the panel is reached, the isearch is
restarted from its beginning.
^R, ^Xr
Incremental search backward a file name in the current panel
(isearch-backwardÃÂâ). Pressing ^R or ^Xr again will
force gitfm to go to the next entry that matches the current
isearched string. When the beginning of the panel is reached, the
isearch is restarted from its end.
^X 0
Enlarges the other panel to use the entire screen. It also changes the
minor mode to Enable all. The current panel will become
invisible (enlarge-other-panel).
^X 1
Enlarges the current panel to use the entire screen. It also changes
the minor mode to Enable all. The other panel will become
invisible (enlarge-panel).
^X 2
Switches back to the two panel mode (two-panel-mode).
Use hexdump -C <filename> to show both Hex ASCII contents of the file.
& -- starts the named program in the background
Ctrl+Z -- halts the program (e.g. vim if you're stuck in visual mode and don't know how to get out of it).
jobs -- lists jobs in the background (usually "Stopped")
jobs -l -- lists the process numbers so you can use kill.
fg -- brings the job marked with + back to the foreground
fg %3 -- brings job number 3 back.
bg %2 -- resumes job 2 if stopped, but leaves it in the background
stop %2 -- stops that job.
To check Linux version:
mcook@bertha:~$ cat /etc/issue Ubuntu 8.04.2 \n \l mcook@bertha:~$ cat /etc/lsb-release DISTRIB_ID=Ubuntu DISTRIB_RELEASE=8.04 DISTRIB_CODENAME=hardy DISTRIB_DESCRIPTION="Ubuntu 8.04.2" mcook@bertha:~$ uname -a Linux bertha 2.6.24-24-generic #1 SMP Wed Apr 15 15:54:25 UTC 2009 i686 GNU/Linux
See examples in the section above on cron
Used to specify character set in HTML "head" and/or XML, e.g.:
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="generator" content="HTML Tidy for Linux (vers 6 November 2007), see www.w3.org" />
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
..etc. ..
Other common character sets ..
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
You can use this as an alternative to GNU Interactive Tools (gitfm a.k.a gnuit).
Some commands are similar, others are different:
Similar to gnuit: ---------------- Esc+p recalls the last command on the mc commands line. Different to gnuit or not available: ----------------------------------- Copy directory name of the opposite panel to the command line.
To make an ISO image file fropm a CD or DVD:
dd if=/dev/dvd of=dvd.iso # for dvd dd if=/dev/cdrom of=cd.iso # for cdrom dd if=/dev/scd0 of=cd.iso # if cdrom is scsi
To make an ISO image from files on your hard drive, create a directory which holds the files you want, then:
mkisofs -o /tmp/cd.iso /tmp/directory/
mount /dev/sdb1 /mnt/sdb1
mount -t smbfs -o username=uuuuuuu,password=ppppppppp //Workgroup/Host/Share-D /Volumes/Host-Share-D
sudo mount -t cifs //mona/mcook /mnt/mona/mcook -o / username=user,password=password,uid=1000,gid=1000,file_mode=0640,dir_mode=0750,iocharset=utf8 -- mounts the share for the same username and password on both systems but overrrides user number and group number from the current system for use when the target system uses different user number and group number.
mount -o loop -t iso9660 file.iso /mnt/test
You can check NTP status using these commands:
sudo ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
*time.apple.com 17.254.0.49 2 u 22h 36h 177 92.508 16.888 28.547
sudo ntpdc
ntpdc> sysstats time since restart: 283107 time since reset: 283107 packets received: 20 packets processed: 17 current version: 17 previous version: 0 bad version: 0 access denied: 0 bad length or format: 0 bad authentication: 0 rate exceeded: 0 ntpdc>
Command+S - usually "save"
Command+Tab -- show active applications in a tabbable list
Command+W -- close the active window (e.g. in Textedit or Finder).
open -a iCal.app -- to open iCal from the command line (e.g.).
open-x11 xterm -- to open an X11 application (e.g.). Starts X11 first. Does not pass any parameters.
Option+Command+Escape -- brings up Force Quit dialog.
OSX includes no rename command (unlike Linux).
This command will rename *.JPG files to *.jpg:
for i in *.JPG; do mv "$i" "${i/.JPG}".jpg; done
This command will remove "73" from the list of files 73mcookt22.*:
for i in 73mcookt22.*; do mv "$i" "${i/73}"; done
This command will remove .Z from a list of files *.Z:
for i in *.Z; do mv "$i" "${i/.Z}"; done
Work in progress on this section.
After two attempts at re-installing via tftp/nfs "net install", and still getting IO errors on the HD, also having broken the DVD-ROM connector on the motherboard riser, I took the Mac Mini in to Mac Helper. Fri 08 Jan 2010 04:50:47 PM CST Still working towards netinstall of OSX on Mac mini with broken hard DVD drive. See http://www.linuxquestions.org/questions/linux-networking-3/netinstall-341580/ ... simplest menu so far. Installed tftpd .... Selecting previously deselected package tftpd. (Reading database ... 271257 files and directories currently installed.) Unpacking tftpd (from .../tftpd_0.17-15ubuntu1_i386.deb) ... Setting up tftpd (0.17-15ubuntu1) ... --------- IMPORTANT INFORMATION FOR XINETD USERS ---------- The following line will be added to your /etc/inetd.conf file: tftp dgram udp wait nobody /usr/sbin/tcpd /usr/sbin/in.tftpd /srv/tftp If you are indeed using xinetd, you will have to convert the above into /etc/xinetd.conf format, and add it manually. See /usr/share/doc/xinetd/README.Debian for more information. ----------------------------------------------------------- Removed tftp as above. Install tftp-ha instead ... Preconfiguring packages ... (Reading database ... 271264 files and directories currently installed.) Removing tftpd ... Purging configuration files for tftpd ... Selecting previously deselected package tftpd-hpa. (Reading database ... 271257 files and directories currently installed.) Unpacking tftpd-hpa (from .../tftpd-hpa_0.48-1ubuntu1_i386.deb) ... Setting up tftpd-hpa (0.48-1ubuntu1) ... --------- IMPORTANT INFORMATION FOR XINETD USERS ---------- The following line will be added to your /etc/inetd.conf file: tftp dgram udp wait root /usr/sbin/in.tftpd /usr/sbin/in.tftpd -s /var/lib/tftpboot If you are indeed using xinetd, you will have to convert the above into /etc/xinetd.conf format, and add it manually. See /usr/share/doc/xinetd/README.Debian for more information. ----------------------------------------------------------- All following steps as root ... Updated /etc/inetd.conf ... ## netbios-ssn stream tcp nowait root /usr/sbin/tcpd /usr/sbin/smbd ####tftp dgram udp wait nobody /usr/sbin/tcpd /usr/sbin/in.tftpd /srv/tftp tftp dgram udp wait root /usr/sbin/in.tftpd /usr/sbin/in.tftpd -s /var/lib/tftpboot Edited /etc/default/tftpd-ha ... RUN_DAEMON="yes" Mounted Tiger install disk and as root: cp /cdrom/System/Library/CoreServices/BootX /var/lib/tftpboot/BootX (not actually renamed) cp /cdrom/mach_kernel /var/lib/tftpboot/mach.macosx cp /cdrom/System/Library/Extensions.mkext /var/lib/tftpboot/mach.macosx.mkext Unmounted cd and make a simple image of the Mac Install CD in the TFTP server root. dd if=/dev/scd0 of=/var/lib/tftpboot/tiger.img Then etc/init.d/tftpd-hpa start and sudo /etc/init.d/nfs-kernel-server restart. Updated NFS exports ... for 192.168.2.100 ... /var/lib/tftpboot/ mac-ip-address(ro) Restart the TFTP server and NFS server. On the Mac ... boot into open firmware (by holding command+option+O+F) and issue the following commands: setenv boot-device enet:ip-address-of-linux-server,BootX setenv boot-args rp=nfs:ip-address-of-linux-server:/var/lib/tftpboot/:tiger.img boot Had to change username for tftpd from nobody (nogroup) to root as above. Now I get the network boot screen, then a big black square after ... Jan 10 06:00:41 bertha mountd[6028]: refused mount request from 192.168.2.100 for /var/lib/tftproot/ (/): not exported
From MONA, to get remote X session on BERTHA:
1) Start X on MONA
2) In xterm: ssh -X mook@bertha (or can go ... ssh -2 -Y mcook@bertha .. not tried today)
3) Note that echo $DISPLAY should return: localhost:10.0
4) Run (e.g.): xterm &, or mahjongg & (or can go ... gnome-panel, or: startkde ... not tried today).
NOTES:
a) Did not first check Xforwarding is enabled in /etc/ssh_config and sshd_config
b) gnome-session has a bug.
c) After mahjongg & exits from xterm on BERTHA I get 1 error like below.
d) gnome-session does not start
Have username and password identical on both source and target systems.
To copy all *.txt files to named folder (without replacement or folder recursion):
rsync -t *.txt 192.168.2.107:/home/mcook/bin/test-rsync
To synchronize files/directories between the local and remote system.
rsync -avz $SOURCE_FILESPEC $RHOST:$REMOTE_FILESPEC
Again, have username and password identical on both source and target systems.
rsync --password=<filename> will not work if rsync uses ssh. In this case, to avoid having to enter ssh password manually:
Source system Target system
+-----------------+ +-----------------+
| | | |
| | | |
| OSX | | Ubuntu |
| 192.168.2.106 | | 192.168.2.107 |
| mona.local | | bertha.local |
| | | |
| | | |
+-----------------+ +-----------------+
First, you have to generate an ssh public key on the source system like this:
ssh-keygen -t rsa
-- type enter (default) after each question even for password, press enter
-- it will generate 2 files : the private key and the public key (id_rsa.pub is your public key)
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/mcook/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/mcook/.ssh/id_rsa.
Your public key has been saved in /Users/mcook/.ssh/id_rsa.pub.
The key fingerprint is:
a0:16:24:a7:28:63:ef:ae:58:49:c0:cd:9f:fa:33:02 mcook@mona.local
The key's randomart image is:
+--[ RSA 2048]----+
| . o |
|..o= |
|=o.o. . |
|oo. .o.. |
| ..oo S |
| E.o. |
| +o |
|.....o |
|......o |
+-----------------+
You then have to copy your public key to the target system:
scp ~/.ssh/id_rsa.pub 192.168.2.107:.ssh/authorized_keys
Now try ssh 192.168.2.107 echo ... it should no longer ask for a password!
-- you might need to restart sshd on either system
-- check your security log on the target system if you are still having a problem
-- from the public key generated on MONA (source system) ~/.ssh/id_rsa.pub ..
-- You must create the file (e.g. /home/mcook/.ssh/authorized_keys) on the target system if it does not already exis.
(this must NOT be a directory).
-- Use cat or an editor to add extra public keys to an existing authorized_keys file (per user).
ssh, rsh, and rsync should no longer require a password going to target host bertha.local from source host mona.local.
To set this up in reverse:
1) on bertha.local ssh-keygen -t rsa
2) Concatenate the public key with~/.ssh/authorized_keys on the OSX system.
Sed is a non-interactive editor. Instead of altering a file by moving the cursor on the screen, you use a script of editing instructions to sed, plus the name of the file to edit. You can also describe sed as a filter. Let's have a look at some examples:
$sed 's/to_be_replaced/replaced/g' /tmp/dummy
Sed replaces the string 'to_be_replaced' with the string 'replaced' and reads from the /tmp/dummy file. The result will be sent to stdout (normally the console) but you can also add '> capture' to the end of the line above so that sed sends the output to the file 'capture'.
$sed 12, 18d /tmp/dummy
Sed shows all lines except lines 12 to 18. The original file is not altered by this command.
See also: http://www.grymoire.com/Unix/Sed.html
More examples:-
Replace all occurrences of a string:-
# REPLACE ALL ====RSSpubdate==== with newRSSdate
sed "s/====RSSpubdate====/${newRSSdate}/g" dateforRSS.production-feed2.template.xml > production-feed2.xml.tmp
Replace only the first occurrence:
# THIS REPLACES THE FIRST OCCURRENCE THEN STOPS
# Replace only the FIRST occurrence
# of "RSSpermalink" in each new generation of the work file
# AND THEN STOPS
sed "1,/====RSSpermalink====/s/====RSSpermalink====/${nowms}/" \
production-feed2.xml.tmp2 > production-feed2.xml.tmp.$counter
ss is a useful and flexible alternative to using netstat.
In the simplest form ss is equivalent to netstat with some small deviations. ss -t -a dumps all TCP sockets ss -u -a dumps all UDP sockets ss -w -a dumps all RAW sockets ss -x -a dumps all UNIX sockets Option -o shows TCP timer state. Option -e shows some extended information. Without option -a sockets in states TIME-WAIT and SYN-RECV are skipped. The format of UNIX sockets coincides with tcp/udp. The default is to dump only TCP sockets. By default ss does not resolve numeric host addresses. This is enabled using option -r. Service names, usually stored in local files, are resolved by default.
For example, try: ss -o state established '( dport = :http or sport = :http )'
Gives output like:
mcook@bertha:/usr/share/tomcat5.5/bin$ ss -o state established '( dport = :http or sport = :http )' Recv-Q Send-Q Local Address:Port Peer Address:Port 0 0 192.168.2.107:47746 66.249.81.100:www
The stat command lists inode information for the named file. This includes all three time stamps.
stat filename on Linux will print output like this:
stat .gdbinit File: `.gdbinit' Size: 55 Blocks: 1 IO Block: 4096 regular file Device: 803h/2051d Inode: 16267 Links: 1 Access: (0777/-rwxrwxrwx) Uid: ( 0/ root) Gid: ( 0/ root) Access: 2010-06-09 19:19:34.000000000 -0500 Modify: 2009-02-17 20:31:26.000000000 -0600 Change: 2010-06-09 18:57:46.000000000 -0500
On OSX you will get:
stat xtab 234881026 44591 -rw-r--r-- 1 root wheel 0 0 "May 27 12:05:27 2005" "May 27 12:05:27 2005" "Feb 19 10:42:00 2010" 4096 0 0 xtab
Or to see times in seconds from 00:00 on 1 Jan 1970:
stat -r xtab 234881026 44591 0100644 1 0 0 0 0 1117213527 1117213527 1266597720 4096 0 0 xtab
gnome-terminal and xfce4-terminal are common Linux "wrappers" for xterm.
The default size of the gnome terminal window in Fedora Core 3 can be modified by editing /usr/share/applications/gnome-terminal.desktop. Modify the Exec= entry to read:
Exec=gnome-terminal --geometry=120x30
Otherwise, to override size, start like this:
gnome-terminal --geometry=120x32
See the information on the stat command above.
The output from date varies depending on the version. For example, in OSX 10.4.11 the BSD version of date only gives time in seconds.
If using GNU date (on Linux), this script ..
#!/bin/bash # Returns date in nanoseconds (GNU date version 6) - does not work when using BSD date in OSX 10.4.11 PPC or OSX 10.7.2 x64. echo $0 uname -a date date "+%s" date --version|head -n1 NS=`date +%s%N` echo $NS
Will return output like this ..
./get-tod-in-nanosec.sh Linux cara 2.6.32-33-generic #72-Ubuntu SMP Fri Jul 29 21:08:37 UTC 2011 i686 GNU/Linux Mon Dec 26 05:21:17 CST 2011 1324898477 date (GNU coreutils) 7.4 1324898477646624489
You can use a Perl script from Bash like this:
#! /bin/bash i=0 while [ $i -le 60 ] do ms=$( perl -MTime::HiRes -e 'print int(1000 * Time::HiRes::gettimeofday),"\n"' ) sec=$( date '+%S' ) printf '%2d %d\n' "$sec" "$ms" sleep 1 i=$(( $i + 1 )) done
See also D
time Program_name Parameters will run the named program passing the parameters and then report like this:
real 0m0.364s user 0m0.001s sys 0m0.008s
More explanation:
The time [command] executes and times [the named program, passing paramters to it if specified.
After the program finishes, time writes the total time elapsed, the time consumed by system overhead,
and the time used to execute [the program] to the standard error stream. Times are reported in seconds.
Available options:
-l The contents of the rusage structure are printed.
-p The output is formatted as specified by IEEE Std 1003.2-1992 (``POSIX.2'').
An example:
mona:/usr/bin mcook$ time -p date Wed Jun 16 16:52:08 CDT 2010 real 0.05 user 0.00 sys 0.00
Bash has a builtin C function called times. You find this on Linux and OSX and it can be run both from the command line or within a script provided you are using BASH.
The times() function returns the value of time in CLK_TCK's of a second
since 0 hours, 0 minutes, 0 seconds, January 1, 1970, Coordinated Univer-
sal Time.
It also fills in the structure pointed to by tp with time-accounting
information.
The tms structure is defined as follows:
struct tms {
clock_t tms_utime;
clock_t tms_stime;
clock_t tms_cutime;
clock_t tms_cstime;
};
The elements of this structure are defined as follows:
tms_utime The CPU time charged for the execution of user instructions.
tms_stime The CPU time charged for execution by the system on behalf of
the process.
tms_cutime The sum of the tms_utimes and tms_cutimes of the child pro-
cesses.
tms_cstime The sum of the tms_stimes and tms_cstimes of the child pro-
cesses.
All times are in CLK_TCK's of a second.
Here is an example, with results to 1/1000 of a second:
mona:~/bin mcook$ times 0m0.024s 0m0.036s 0m6.323s 0m1.973s mona:~/bin mcook$
The first column is user time, the second is system time. The first row is times for the shell and the second row is all reaped children.
NOTE: because times uses accounting information, the results [seem to?] accumulate for successive executions of times within the current shell instance only. This means it [might not be?] suitable for iteritave use within a script when trying to time command execution.
The top command in Linux provides several useful hot keys:
Hot Key Usage t Displays summary information off and on. m Displays memory information off and on. A Sorts the display by top consumers of various system resources. Useful for quick identification of performance-hungry tasks on a system. f Enters an interactive configuration screen for top. Helpful for setting up top for a specific task. o Enables you to interactively select the ordering within top. r Issues renice command. k Issues kill command. z Turn on or off color/mono 1 Toggles multiple CPU information ? Prints help information.
The top command in OSX is a BSD variant: command line options and interactive keys differ.
Use top -X for compatibility mode.
State Command Description
? Display this help screen, regardless of context.
^L Redraw the screen.
n c Set event counting mode to {a|d|e|n}.
on f Toggle shared library reporting.
2147483647 n Only display processes.
-pid O Set secondary sort key to (see o).
-pid o Set primary sort key to : [+-]{command|cpu|pid
|prt|reg|rprvt|rshrd|rsize|th|time|uid|username|vprvt
|vsize}.
q Quit.
on r Toggle process memory object map reporting.
S\n Send signal to pid .
1 s Set the delay between updates to seconds.
off t Toggle uid to username translation.
U Only display processes owned by , or all.
narrow w Toggle wide/narrow delta mode.
touch -a -m -t 200905252300 mcookt22.mac.2009-05-25.txt; ls -lisa mcookt22.mac.2009-05-25.txt
h/j/k/l -- move left/down/up/right
0 (zero) -- move the cursor to the start of the current line
$ -- move the cursor to the end of the current line
1G -- move to the top of the file
nnnG -- move the cursor to line nnn
999G -- move to the end of the file (or not)
b -- move the cursor to the beginning of the previous word (use w to move forward)
D -- deletes the content of the current line
dd -- deletes the current line
G -- moves to the end of the file
g -- does the same
w -- moves the cursor to the beginning of the next word
Ctrl+F and Ctrl+B -- page up and down
Esc -- get into (or leave) command mode when you can enter commands prefixed with a colon, including:
:a -- append to the end of the current line
:e filename -- edits the new file
:file -- displays the current file name.
:history -- displays vi's command history.
:i -- insert at the current cursor position
:j -- join this line and the next
. -- when used after text insertion, duplicates the inserted text
:n -- moves to the next file (this does not loop back to file 1 of n, use :rew for that)
: -- then use arrow keys to scroll through vi command line history.
:r filename -- reads and appends filename
:rew -- moves back
:redo -- redoes last undo
:%s/old/new/g -- search and replace: on all lines %, or specify from/to line numbers as from_line_number, to line_number, e.g. 1,10)
:%s/old/new/gc -- search and replace with confirmation (line specified as above)
:%s/^M/^M /g followed by :%s/^M//g to replace ^M characters in file (use Ctrl+V then Ctrl+M to get the ^M).
:se nocp OR :set nocompatible
Creating ~/.vimrc can help - read :help compatible
:set nu -- show line numbers
:set nonu -- remove line numbers
:u -- undo
To edit text in hex use :%!xxd use %!xxd -r to return to regular ASCII mode.
:%!colrm 1 4 -- delete columns 1 to 4 throughout the data (shift left 4 columns).
Try :\tp if you are stuck in insert mode after using visual and/or some other rare key combination.
If you are using vi on a UNIX-like system, the [CTRL][V] tells the computer NOT to execute the next command [CTRL][M] -- which is a new line or carriage return 0x0D -- but to write it instead.
If you are using vim in Windows, you have to use [CTRL][Q] instead of [CTRL][V] since on Windows [CTRL][V] is mapped to "Paste". The [CTRL] character will always appear as '^' in the file.
Windows programs end each line with two characters: <new-line><carriage-return> \n\r or 0x0A0x0D, whereas UNIX ends a line with only one character <new-line> \n or 0x0A.
I believe a new-line character is [CTRL][L] and the carriage return is [CTRL[M].
Use this to replace Ctrl+M (CR, 0x0D, octal 015, \r) with a newline character (LF, 0x0A, octal 012, \n):
tr '\015' '\n' < input_file > output_file
The C programming language provides the escape sequences '\n' (newline) and '\r' (carriage return). However, contrary to popular belief, these are in fact not required to be equivalent to the ASCII LF and CR control characters.
On Unix platforms, where C originated, the native newline sequence is ASCII LF (0x0A), so '\n' was simply defined to be that value.
Writing '\n' to a text mode stream works correctly on Windows systems, but produces only LF on Unix, and smthing completely different on more exotic systems. Using "\r\n" in binary mode is slightly better, as it works on many ASCII-compatible systems, but still fails in the general case. One approach is to use binary mode and specify the numeric values of the control sequence directly, "\x0D\x0A". Java also provides '\n' and '\r' escape sequences. In contrast to C, these are guaranteed to represent the values U+000A and U+000D, respectively.
See also http://en.wikipedia.org/wiki/Newline
See also http://en.wikipedia.org/wiki/C0_and_C1_control_codes
See also http://www.asciitable.com/
With some Debian Linux distributions, the keys for using vi/vim may be different. For example, if you press 'i', then the 'del' key, it should delete blank lines, but it won't. Also, if you try to use the arrow keys to move up and down to different lines vi/vim instead starts typing random letters and making them capital and lower case. To resolve this, first, try to run:
:se nocp OR :set nocompatible
There are lots of quick references for vi, including:
This list is work in progress.
Some good tutorials for vi:
This list is work in progress.
Windows -- see http://notthere.dyndns.org/pub/HintsAndTips/Windows/
xterm -e 'command_name parameter parameter' & # Run xterm to execute the command
xterm -font -*-helvetica-*-*-*-*-20-*-*-*-*-*-*-* & # Use xfontsel to list and select font spec to the clipboard)
xterm -ls & # Run xterm as login shell to execute ~/.profile
xterm -t & # Run Tek terminal (the default is usually VT100)
xterm -sb -rightbar -fg green -bg black -geometry '128x64' -ls
xterm -sb -rightbar -fg white -bg black -geometry '+60+645' -T "$HOST skyprod.net.error.log" /
-e 'tail -f /var/log/httpd/skyprod.net.error_log' &
Use Shift+Ctrl+C to copy from xterm and middle mouse button to paste.
Use Ctrl+mouse buttons left to right to show Main Options menu, VT Options menu, VT Fonts menu.
clear clear the terminal window.
editres is the X Resource Editor.
infocmp displays xterm info.
reset resets the terminal.
resize prints the size of the xterm (COLUMNS and ROWS environment variables, when using Bash).
showrgb to show colors db.
tput cup X Y moves the cursor to the (X,Y) coordinates in the current terminal.
tput longname lists xterm version info.
xflock4 lock the screen (at window manager level).
xfontsel list and select X11 fonts.
xlsfonts lists installed X11 fonts.
xrdb -query -all lists Xserver resources (see also the system Xresources file in /etc/X11, and/or ~/.Xresources).
This page is encoded in ISO-8859-1.
Last edited:
echo.local 2012-01-09 for ASCII table href change #P
echo.local 2011-12-31 added vi referencs #P
echo.local 2011-12-26 added another awk example #P
echo.local 2011-12-26 added more info about date command and date and time formats #P
echo.local 2011-12-21 added META character set examples; re-validated #P
mona.local 2011-08-01 added more find examples
mona.local 2011-06-26 added info about shifting columns left in vi
mona.local 2011-05-30 added info about xterm commands
mona.local 2010-10-18 added info about hexdump command #J.
cara.local 2010-09-17 Validated XHTML 1.0, #I (validated).
mona.local 2010-09-07 added info about NTP commands and vi. #H.
mona.local 2010-08-29 added info about undo.redo in vi. Updated #G.
mona.local 2010-06-17 added info about various time functions. #G
mona.local 2010-06-14 added info about Bash I/O redirection. #F
bertha.local 2010-06-06 Validated XHTML 1.0, #E.
mona.local 2010-05-20+ added some Bash stuff, top, etc. #D
mona.local 2010-05-09 #C
bertha 2010-04-09 #B
mona 2008-05-11 #6