Useful Linux/Unix commands To run things with higher priority than default: nice -n -10 Original command... xargs: Unix and Gnu versions differ wildly in args, but basic behavior and return values are the same. Old bash shells' "which" does not return failure status for resources that aren't present, regardless of whether it displays an error message. MBR: 1st 512 bytes on a hard disk are 446 bytes of boot code 64 bytes of partition table 2 bytes boot code signature Can selectively either back or clear just the boot code by specifying 446 bytes instead of 512. netcat -l -p 9002 netcat localhost 9002 Excellent uses for netcat at http://www.foureleven.org/pub/nc/ What I use to detect listener with 1 second timeout: nc -4 -z -w 1 $HOST 22 # Returns failure if no connect. Original impl. GNU version has very different syntax (and perhaps behavior) Even on Linux now, should use "shutdown -r now" instead of "reboot" "shutdown -h now" instead of "halt" UNIX kernel logging facility sucks. The priority/level system is fine. There are a set number (about 15) "facilities", and this is the only way to categorize/route your messages. syslog-ng.conf implements a horrific work-around where they create filters as pseudo-facilities based on STRING MATCHES in record contents! Plain facilities would be better. To run something directly as another user, who has no shell, as root: ENVVAR=x su -s /bin/bash targetuser -c 'target command' Changing time zone: yast2 timezone or http://www.wikihow.com/Change-the-Timezone-in-Linux gnuplot. See "gnuplot.txt" file nmap -p 5900 192.168.102.64-127 -oG - Searches the specified address range for something listening on port 5900, displaying output in Greppable format. Supports YUL scripting language. nmapsi4 is a Qt interface for it. make -j2 makes builds run faster with dual processors. GNU diff. Directory comparisons: diff -rd dir1 dir2 YUM Basic Yum usage: http://yum.baseurl.org/wiki/YumCommands Get used to "-y" switch, because this thing assumes you are retarded. Config (incl. repos. definitions) at /etc/yum.conf Refresh db: yum checkupdate OR yum makecache yum -y update # For some reason does not clear "yum list updates" ??? Apparently does not clean up after itself by default (/var/cache/yum/...), so you must run: yum clean When run "yum shell", the modifying commands just get queued into a transaction list ("tx list", etc.), which only executes when you run "run". NO zfs AVAILABLE!!! Shit. grep Only for line-specific searches. Great switches: Regexp modes, mutually exclusive: -G (default), -E, -F, -P -C 5 #output context -F #for multiple, must use multi-line ' or " str. == fgrep Doesn't work on Solaris even with egrep. -x match whole line. -Fx together awesome. -E extended regexp. == egrep. Switch doesn't work on Solaris. N.b. there is no word boundary operator in extended pattern mode. -q # correct POSIX, but 7th edition UNIX grep fd up, so must >/dev/null # for full portability! -e 'exp ression' # Allows for pattern beginning with - -r # recursive -d skip # Ignores specified directory names (incompatible with -r) -m 1 # stop after a single match -c # Count of matching lines -h Skip filename prefix (nice when you don't need to know file and lines are long) -a Display matches which could contain binary characters (since input contains binary chars) (Otherwise matches will just output "Binary file (x) matches". Idiom to report on strings in file A that are not (precisely) in file B: while read W; do grep -qFx "$W" B.txt || echo $W; done < A.txt To check for union just change || to &&. Character escapes do not work portably, and few work even on Linux. \n doesn't make sense, \t doesn't work. \\ always works as expected even in -G mode. \s works only on Linux, even in -G mode. '\<', '\>' work with -G, -E modes on Linux; never on AIX, with -G mode on Sol. [[...]] pre-defined character classes aren't portable, even across Linux. Character escapes generally do not work (\t does not' top. MEMORIZE!!! invocation -b -n 1 | head -20 interactive R Reverses sort order [Following not working for me. To change order do: f, go to field, s, ENTER On\n Sort by % Mem Ox\n Sort by command name/line Ok\n Sort by % CPU (the default)] M sort by %mem P sort by %cpu k Kill (sends specified signal. You still have to key in pid.) 1 Shows all CPUs W Saves all default settings for you q Quit To clear your default settings: rm ~/.toprc To enlarge an existing non-LVM partition. Delete the partition then recreated it with an extended end point. resize2fs, even with partition mounted Use units of 'cyl'. Parted seems to -1 from specified end point. Great ls switches that are only available with newer gnu ls: -Q quote --time-style=long-iso Generally use "ls -A" instead of "ls -a". The . and .. reported by "ls -a" are friggin' useless. cron GOTCHA: % characters need to be escaped with \ OR First means everything following gets piped to stdin. Consequent get replaced by newlines. [there is no problem with @ characters] cron GOTCHA: Can't use $ references in cron assignment values. (Just do assignments like that in the job commands). A consequence of this is you cant append to PATH using cron var; nor can you use ~ or $HOME to build useful env variables. Workarounds are either specify hard-coded literal PATH globally, or give PATH=x:y prefixes to individual commands. See file tech/linux.txt for important things only tested on Linux. The assignment values are EXPORTED variables. NTP work-around: sntp -a 0.rhel.pool.ntp.org CUPS printing from Add printer with location http://print.admc.com:631/printers/queueName Choose driver Generic / MS Publisher Imagesetter Photo geotags. Use exiftool per http://www.tuxradar.com/content/geotagging-linux . Cell phones can add this info automatically. tightvnc vncviewer. For some reason, with latest version, at least connecting to Windows 8, cursor appears as a tiny dot instead of real cursor (seems to be using -nocursorshape switch by default now). To restore real cursor, use -x11cursor switch. around this, To avoid SSH login delays due to failing DNS looups: set "UseDNS no" in /etc/ssh/sshd_config and restart the SSHD process. "cygwin" and "xterm" TERM variable values generally work terribly. Change TERM value to "ansi" if those aren't working. "screen" is the host-side multi-window terminal-emulator program. (The windows within screen are called "windows"). It's gnu, with open source package available for Solaris. Besides multi-window, screen retains window sessions when connections dropped. Can only terminate screen by exiting all windows or with command Ctrl+a Ctrl+\. SCREEN INVOCATIONS FROM REGULAR SHELL: screen [-L] the command (-L is for Logging). Use this to create 1st virtual term. Log files like $PWD/screenlog.0 get APPENDED TO. The command must be separate tokens. I know of no way to support metacharacters/compound commands. screen -ls # -ls lists the screen sessions (not windows) screen -r [session] # -r Reattaches SCREEN INVOCATION FROM INSIDE A screen WINDOW: screen another command This replaces the current window with the new one (until you exit it) CRITICAL screen commands: CTRL+a + 0 to 9 Switch to specified window d Detach Ctrl+\ Exit ALL D D Disconnect = Detach + HUP to screen programt ? Ctrl+d Disconnect " prompt for window name/num To just list all windows, just ESC once list is displayed. M Monitor current window c New shell window. Use this to create all virtual terms after 1st. If run with -L, each window gets its own log file. To get a shell on another host, immediately "exec ssh..." from here. A Rename current window Special file permissions. 4th byte: 1 == temp dir final T permission 2 == group-set. (Normally want: 02?7?, since need group rwx to use) chown --reference=... sets file group in addition to user. sftp: "progress" is as close as you can get to ftp's "hash". I think this is on by default, but some clients (psftp) don't have it at all. Contrary to the man page, there is no "bar" or any sort. It just keeps updating real-time percentage, rate, size-transmitted, ETA. To quiet login banners, touch "~/.hushlogin". See linux file about slocate (version of locate most available on Solaris). See linux file about find. Solaris: The new "image" style packages (Solaris 11+) are managed with program "pkg". Run "pkg help". sudoers allowing/permitting of command params: If params given then they must be matched. Can use wildcards in the target file name and in any directory path segment. Can use wildcards in the params but I don't know how the match: Pattern "One *" would command "One two three" match that? If no param given then all params allowed. To require no command params supply param value of "". ??? works with no param setting? sudo ignores shell built-ins. For example, even though 'pushd' and 'test' are built-ins, you can sudo /path/to/pushd and /path/to/test, relying on $PATH for resolution, and the built-in will be skipped when searching. When exec'ing the command, sudo apparently does not use the regular shell resolution algorithm. sudo rules automatically work for target files that are hard-links to the specified file that have the same name as the specified file (which necessarily means that they reside in a different directory). automatically work for sym-links of the final files. Great sudo switches: -i: simulate Initial login -r/-t: set SELinux role or type -l: List my rules -n: non-interactive (if not available then -S option useful, for Stdin) -u: User other than root -V: release banner mailx takes recipients as either separate args or single comma-and-space-delimited list. Hostname conventions: Hostname should be unqualified/short, as should entry in /etc/hostname. Entry in /etc/hosts should be: FQHN SHORT_HN LOGNAME vs. USER. USER is marginally more effective-user a.o.t. who logged in as. But real difference is that LOGNAME is Sys-V-provided, USER is BSD_provided, and other variants provide either one or both. Reverse lines in a text file: tac xargs: Default: For programs that can process multiple command arguments and invokes the program as few times as necessary (possibly just once) for all of the provided input comman args to be processed, each invocation with possibly many command args. -n 1 switch: For programs that must take just 1 command. Command invoked for every input token. This is the general fix whenever you run a UNIX command that doesn't use wildcard expansion and get a shell error that the command line is too long. N.b. If problem is with a wildcard expansion then you need to rewrite using a program that outputs the node list to stdout or stderr instead of using wildcard expansion. Input tokens by default delimited with \s+ (so blank lines ignored), but can switch to anything with -0 or -d. Awesome -I switch: Needs further testing if the input list is not \n-delimited, but with -I instead of command args to the specified command, it INSERTS command args into the specified command, substituting them for your specified variable name. xargs -Ī INSERT_HERE cmd0 cmd1 INSERT_HERE cmd2 ed editor ed -vE [filename.txt] # switches -H extended Help; -v is H command You are іn an editing session with the file in your buffer. Use a subset of vim :ex mode commands. timing executions. To set env vars, give that AFTER the "time˝ built-in: time VAR=x executable... Open files: fuser, lsof