Various tidbits - notes from korn bourne and friends. |
| Saturday, 26 March 2005 10:45 |
How do I redirect stderr to stdout...or maybe redirect stderr to a file??For some reason, remembering how to properly redirect stderr is beyond me. I always forget that 2>&1. Redirecting standard error (stderr) and stdout to file...$ command &> command.log OR $ command > command.log 2>&1 OR $ command 2>&1 | tee command.log zshZshrobbyrussell's oh-my-zsh at master - GitHub Korn ShellKSH script BASICS For filename completion, use ESC \ and ESC = To enter your history, hit the ESC key, press k to move through prior commands. To edit use h and l to move the cursor left and right, x to delete characters, i to insert characters (use ESC to finish the insertion). Just like vim style commands. Screen is your friend!Lately I have been really loving the program called screen. It allows you to run multiple programs on a terminal and switch between them. The power of screen comes in when you've got a bunch of tasks that you need to do on a single computer. So for example, if I want to run a vim session on a configuration script, as well as run the server, and sit in the server debug console... you run a separate screen for each of these tasks. Then, instead of exiting vim, running the script, and then running the command to get into the debug console... you simply hit CTRL-ALT-" to select which thing you want to do. Saves a BUNCH of time!To create a screen type: screen -t screenname "cmd" To reconnect to the detached terminal, use (-x)...hey works multiple. screen -x ctrl +a S horizontal split region ctrl +a Screen FAQ A nice article on screen @ the LinuxJournal The power of 'screen' revisited Screen: The terminal baby-sitter in the sysadmin's toolbox scie.nti.st » GNU screen with vertical split support Screen VT100/ANSI Terminal Emulator Cheat Sheet - good coders code, great reuse Vertical Split for GNU Screen Find & Replace String In A Non-Ascii File with Perl and Python Fun with findThis finds all root owned suid files.find . -user root -a -perm -4000 -printThis replaces 'search' with 'replace' in all files. find . -type f -exec sed -i ’s/search/replace/’ {} \;Delete empty directories find -depth -type d -empty -exec rmdir {} \; Grep with path and line numbersI'm always forgetting this one, so maybe I'll remember if I document it. To get line numbers and filenames when using grep... Add the options -H (for filenames) and -n (for line numbers). So for example lets say you want to search for all files in the current directory including subdirectories... you would use:find . -name "*" -exec grep -H -n "Edit" {} \;Mime-Construct is awesome:Looking for a good command-line util for sending email? One that might support multi-part attachments? Well mime-construct might be exactly what you are looking for! Get it from the PERL cpan archives [here].mime-construct --to " This e-mail address is being protected from spambots. You need JavaScript enabled to view it " --subject "Subject line" --attachment "attachmentname.ext" --file "path/to/file" Security:Here is a pam module that will execute a script when people login.pam_preprofile.tgz SNMP:MibDepotLinux Kernel DevelopmentI've decided on doing some linux development. More to come.Doc on Linux Internals Kernel Newbies 32-bit UID BSD Accounting patch Linux Input Replay Linux Related Mailinglists I always for forget the escape key to get into command mode when connected to a remote host. When you get inside telnet press "^]" (CTRL-Right_Bracket is a common telnet escape, that will allow you to get to the telnet> prompt and then you can type quit to kill that telnet session to a remote host). Flushing DNSTo flush DNS in Microsoft Windows run: ipconfig /flushdnsYou can also use the command ipconfig /displaydns to view the DNS resolver cache. How to Flush DNS in Mac OSX run: lookupd -flushcache How to Flush DNS in Linux: In Linux, the nscd daemon manages the DNS cache. To flush the DNS cache, restart the nscd daemon. To change your dynamic linking information, edit /etc/ld.so.conf, then run /sbin/ldconfig. Many times you have to add "/usr/local/lib" Undo the extraction of a tar gone wrong!This oneliner deletes the list of files from a tar from the disk.tar tfz filename.tar.gz | xargs rm -fR Find programs with open portsHaving a firewall is good, but I also like to have a close look at the processes with open ports. The following will display port and process information:netstat -apn|less
watch 'netstat -apn'
How to make backup copies with GNU tartar --create --gzip --preserve-permissions --same-owner --file=backup-`date +"%b_%d_%Y"`.tar.gz filestobackup/ scripts - perlhobby - One-sentence summary of this page. - Project Hosting on Google Code - bunch of random commands. Using sed to comment and uncomment all lines in a scriptLets comment the already uncommented lines with #@ so that we can uncomment our programatic comments later.sed -i 's/^\([^#]\)/#@\1/g' yourfile Now, lets remove those comments. sed -i 's/^#@//g' yourfile awk$ awk -F":" '{ print "username: " $1 "\t\tuid:" $3" }' /etc/passwdThe GNU Awk User's Guide Awk by example, Part 1 -- Hartigan/Computer/AWK [one-liner]: Special Variables in Bash « Lâmôlabs [one-liner]: Bash’s wait Command « Lâmôlabs [one-liner]: Removing a File’s Extension with Cut « Lâmôlabs Pushing & Pulling Files Around Using tar, ssh, scp, & rsync « Lâmôlabs Jonathan Ellis's Programming Blog - Spyced: Linux performance basics - vmstat,iostat,top |
| Last Updated on Wednesday, 27 October 2010 11:17 |

