Tag Info

Hot answers tagged


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 ;; ...


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 ...


ssh -t username@hostname /bin/sh works for me.


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 ...


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 ...


you can try to abort (ctrl+C) before the exit part of your .bashrc is executed. I tried by adding the following at the top of a testuser's bashrc, it works, it's just a matter of timing. Very easy in my case: sleep 3 echo "Too late... bye" exit 0


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 .." ...


It's copied from /etc/skel/.bashrc for new users


I haven't used cygwin in some time, but I'm guessing that it wants ~/.bash_profile. Simple fix to test. ln -s ~/.bashrc ~/.bash_profile Or if ~/.bash_profile exists, source .bashrc. if [ -f ~/.bashrc ] then . ~/.bashrc fi


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. ...


Try doing this instead if [ "$SSH_TTY" ] then source .bashc_real fi


mv ~/.bashrc ~/.bashrc.messed cp /etc/skel/.bashrc ~/.bashrc


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


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 ...


In your login shell's profile files you can set up some things that you will use during your session, and which are needed to be done only once. Some ideas: create a temporary file containing the ip you connected, later on you can include it in some scripts setting firewall rules. run ssh-agent, ask for your ssh keys, and store the ssh agent environment ...


I usually address this with a short cron wrapper script: #!/bin/bash [ -r $HOME/.bashrc ] && . $HOME/.bashrc [ -r $HOME/.profile ] && . $HOME/.profile exec "$@" Then just prefix the command in crontab with your wrapper: * * * * 1-5 ~/scripts/cron-wrapper ~/scripts/myscript.sh * * * * 1-5 ~/scripts/cron-wrapper ~/scripts/myotherscript.sh ...


I think your only options are: ssh in as another user and su to your account; use something like ftp or smbclient, if the relevant services are enabled on the host; find an open vulnerability in an open network service and exploit it :). get an admin to fix the problem.


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 ...


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.


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]\\$ ...


Use the pathmunge() function available in most distro's /etc/profile: pathmunge () { if ! echo $PATH | /bin/egrep -q "(^|:)$1($|:)" ; then if [ "$2" = "after" ] ; then PATH=$PATH:$1 else PATH=$1:$PATH fi fi } edit: For zsh users, typeset -U <variable_name> will deduplicate path entries.


Usually you can tell bash to ignore these rc files with: ssh -t your-host bash --noprofile --norc After login, you can view and update the problematic rc files.


Move the damaged file out of the way, then reinstall the package that provides the damaged file. mv /etc/bashrc /etc/bashrc.damaged yum reinstall $(rpm -qf /etc/bashrc)


Add your modified PS1 setting to /etc/profile.d/custom_ps1.sh. Files under /etc/profile.d are automatically sourced from /etc/profile: if [ -d /etc/profile.d ]; then for i in /etc/profile.d/*.sh; do if [ -r $i ]; then . $i fi done unset i fi Which is called whenever a login shell is spawned. From the bash manpage: When bash is ...


Mike's answer will probably work. But it's worth pointing out that you can accomplish this carefully selecting which startup files to put the verbose stuff in. From the bash man page: When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file ...


Could you describe how do you test these 2 files? Did you try login or non-login shell? Here is the difference: When you login your system and see the command line prompt, it’s a login shell, and it executes these files in order: /etc/profile ~/.bash_profile ~/.bashrc /etc/bashrc A non-login shell will only execute the two files in order: /etc/bashrc ...


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 ...


I've had the same problem, and somehow was able to solve it. I used ssh to access the system, and pressed and held Ctrl+c as soon as I logged into the system. Then, ~/.bashrc was not read, and I was able to modify it.


It depends somewhat on how you personally use shells. An interactive shell is anything that has a terminal connected to its input and output. Login shells are spawned by /bin/login. Login shells source your .bash_profile. Most terminal emulators such as xterm start an interactive shell that is not a login shell. Interactive, non-login shells source your ...


I wouldn't change the default /etc/bashrc. Instead, I would create a new file in /etc/profile.d/ This way you have something that will survive upgrades. At least in Fedora and earlier RedHat, the /etc/bashrc contains the following bit of script: for i in /etc/profile.d/*.sh; do if [ -r "$i" ]; then . $i fi The last time I wanted to add ...

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