Tag Info

Hot answers tagged

80

I have a little script that extracts archives, I found it somewhere on the net: extract () { if [ -f $1 ] ; then case $1 in *.tar.bz2) tar xvjf $1 ;; *.tar.gz) tar xvzf $1 ;; *.bz2) bunzip2 $1 ;; *.rar) unrar x $1 ;; *.gz) gunzip $1 ;; ...


38

Since I use so many different machines, my .bashrc always sets the command prompt to include, among other things, the name of the server I am currently logged into. This way, when I am three levels deep in telnet/ssh, I don't type the wrong thing in the wrong window. It really sucks to rm -rf . in the wrong window! (Note: At home, telnet is disabled on ...


26

Color for manpages in less makes manpages a little easier to read: export LESS_TERMCAP_mb=$'\E[01;31m' export LESS_TERMCAP_md=$'\E[01;31m' export LESS_TERMCAP_me=$'\E[0m' export LESS_TERMCAP_se=$'\E[0m' export LESS_TERMCAP_so=$'\E[01;44;33m' export LESS_TERMCAP_ue=$'\E[0m' export LESS_TERMCAP_us=$'\E[01;32m' Colored manpages can also be obtained by ...


23

No more cd ../../../.. but up 4 Goes up many dirs as the number passed as argument, if none goes up by 1 by default (found in a link in a comment in stackoverflow.com and modified a bit) up(){ local d="" limit=$1 for ((i=1 ; i <= limit ; i++)) do d=$d/.. done d=$(echo $d | sed 's/^\///') if [ -z "$d" ]; then d=.. fi cd $d ...


22

For those wanting a less cryptic way of getting a nice screen set up, I can heartily recommend byobu (formerly called screen profiles). It gives you a nice default set of stuff at the bottom of the screen - the bottom line contains various handy status information, and the second from bottom line contains a list of your screen windows. All this can be ...


17

I deal with a lot of different machines so one of my favorites is aliases for each machine that I need to frequently SSH to: alias claudius="ssh dinomite@claudius" It is also useful to setup a good .ssh/config and ssh keys to make hopping amongst machines even easier. Another one of my favorite aliases is for moving up directories: alias ..="cd .." ...


17

First, if you have more than a couple machines you work with, consider putting your ~/.vim/, ~/.vimrc and other useful config files (screen, your shell, etc.) in a revision control system. I prefer using darcs - it's cheap on Debian systems (no need to install Haskell compiler, just install the package directly), distributed, and has great interactive modes. ...


15

GPG encrypted bashrc I'm sure we all have things we'd like to put in our bashrc that we don't want easily readable by sudoers. My solution to this is: if [ -f ~/.bash_private.gpg ]; then eval "$(gpg --decrypt ~/.bash_private.gpg 2>/dev/null)" fi I have a GPG agent that makes it so I only have to enter my private key's password once every few hours. ...


12

this is an awesome resource for this: show us your .bashrc


12

I also use a fairly involved caption/hardstatus line combination, to simulate the effect of dropdown tabs (the caption line is solid grey and the current tab in the hardstatus is the same color). I also have my shell tell screen what the current process name is and what directory I'm in, so my tab names stay up to date with what I'm doing in each tab. This ...


12

I used to set these up all over the place but then realized that it was better to just remember how to do them 'manually' because it meant I would 1) fully understand what was going on and 2) have access to these capabilities even if my custom .bashrc wasn't installed. The only thing I use aliases for these days are to cut down on repetitive typing of ...


12

Yes, this is an OSX thing and is related to the AppleDouble File Format. When OSX writes to a non-native file system (so not HFS), that does not support resource forks, it writes extended info such as finder information in a "._" hidden file.


10

The most useful screen customization, IMHO, is to change the modifier key to something other than C-a. That is just too important of a key to have eaten (go to the beginning of the line at all readline prompts, and in emacs). I use C-z, since I need to suspend applications a lot less often than I need to edit something at the beginning of the line. The ...


9

I often have more than 10 windows running and wanted a way to select them. I found out how to configure C-a Shift+0 through 9 to select windows 10 through 19. bind ! select 11 bind @ select 12 bind \# select 13 bind $ select 14 bind % select 15 bind \^ select 16 bind & select 17 bind * select 18 bind ( select 19 bind ) select 10 Note the ...


9

The one liners and tiny scripts out there could go on forever. I recommend man bash and writing things yourself. Some good short bash stuff at http://www.commandlinefu.com. Heres a few things. #use extra globing features. See man bash, search extglob. shopt -s extglob #include .files when globbing. shopt -s dotglob #When a glob expands to nothing, make it ...


9

A little tip for Bash if you are a sysadmin and work with root privileges a lot: shopt -o noclobber This will prevent you from accidentally destroying the content of an already existing file if you redirect output (>filename). You can always force overwriting with >|filename.


8

I have the following in my bashrc function __setprompt { local BLUE="\[\033[0;34m\]" local NO_COLOUR="\[\033[0m\]" local SSH_IP=`echo $SSH_CLIENT | awk '{ print $1 }'` local SSH2_IP=`echo $SSH2_CLIENT | awk '{ print $1 }'` if [ $SSH2_IP ] || [ $SSH_IP ] ; then local SSH_FLAG="@\h" fi PS1="$BLUE[\$(date +%H:%M)][\u$SSH_FLAG:\w]\\$ ...


7

Apple has a page about this : http://support.apple.com/kb/TA20578


6

Not really sure what part of this is specifically sysadmin related, but my essentials are: syntax on set background=dark set shiftwidth=2 set tabstop=2 if has("autocmd") filetype plugin indent on endif set showcmd " Show (partial) command in status line. set showmatch " Show matching brackets. set ignorecase " Do case ...


6

I've had this in my .bashrc for a while and I've found it helpful. If you are sshing in to the box, is starts screen automatically when you login, that way when your network connection gets interrupted or whatever, you don't lose whatever you were doing. It should be placed at the end. if [ "$PS1" != "" -a "${STARTED_SCREEN:-x}" = x -a "${SSH_TTY:-x}" != x ...


6

Sick of full-screen programs like vim remaining in the scrollback buffer after you've closed them? Wouldn't it be great if they'd go away completely just like they do when you're not running screen? Try putting this in your ~/.screenrc file... altscreen on


5

How many aliases to fortune do you need, anyway? I like to make a cdd alias that takes me to wherever I'm presently most likely to be working on that server. PATH redefinition really belongs in .bash_profile, not .bashrc. On a server where I routinely use a large set of screens, my .bashrc will have: alias s1="screen -dr chaos1" alias s2="screen -dr ...


5

Among other things, I set some defaults for less, prevent accidentally closing my terminal and enable forward navigation through history: # ignore case, long prompt, exit if it fits on one screen, allow colors for ls and grep colors export LESS="-iMFXR" # must press ctrl-D 2+1 times to exit shell export IGNOREEOF="2" # allow ctrl-S for history navigation ...


5

I have a few bits: # stop the pc speaker ever annoying me :) setterm -bfreq 0 # don't put duplicate lines in the history. See bash(1) for more options HISTCONTROL=ignoredups # ... and ignore same sucessive entries. HISTCONTROL=ignoreboth # Expand the history size HISTFILESIZE=10000 HISTSIZE=100 # commands with leading space do not get added to history ...


4

Tail all logs in /var/log alias logs="find /var/log -type f -exec file {} \; | grep 'text' | cut -d' ' -f1 | sed -e's/:$//g' | grep -v '[0-9]$' | xargs tail -f"


4

The 'folders' alias is great! I modified it slightly so that directories with spaces don't cause errors. alias folders='find . -maxdepth 1 -type d -print0 | xargs -0 du -sk | sort -rn'


4

To have colors for All grep commands such as grep, egrep and zgrep, I have the following in my .bashrc export GREP_OPTIONS='--color=auto'


4

If you are usually working at a user, than this make it possible to "pipe" a file to sudo so it can be saved. cmap w!! %!sudo tee > /dev/null % use the command: :w!! to envoke sudo and save the file.


4

Our CTO has a pretty feature-filled Vim configuration on GitHub. Highlights: Syntax highlighting, 2 space tabstop, expanded tabs. NERDtree, a file-tree view similar to TextMate's project drawer. FuzzyFileFinder, plugin to do TextMate's cmd-T functionality. Lots of color themes with a nice one (twilight) default. I find it great for Ruby coding, as our ...


3

You can also look at this SO question: What's in your vimrc?



Only top voted, non community-wiki answers of a minimum length are eligible