Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Console / shell tips & tricks
View unanswered posts
View posts from last 24 hours

Goto page Previous  1, 2, 3 ... 7, 8, 9 ... 14, 15, 16  Next  
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
KiTaSuMbA
Guru
Guru


Joined: 28 Jun 2002
Posts: 430
Location: Naples Italy

PostPosted: Thu May 27, 2004 2:21 am    Post subject: Reply with quote

Ok, this is not "strictly" a bash trick but here is my bash prompt:
Code:

export PS1=' \[\033[01;36m\]\A$(uptime | cut -d "p" -f 2 | cut -d "," -f1)up \[\033[01;32m\]$(free | tail -n 2 | head -n 1 | cut -d " " -f 12-)Kb $((($(ls -l /proc/ | grep -v "total" | grep -v "^l" | grep -c "[1234567890]$")-2)))prc$(uptime | cut -d ":" -f 5|cut -d"," -f1)$(uptime | cut -d ":" -f 5|cut -d"," -f2)$(uptime | cut -d ":" -f 5|cut -d "," -f3) \[\033[01;36m\]\w\n \[\033[01;32m\]\u@\h \[\033[01;34m\]\W \$ \[\033[00m\]'

Kiss that gkrellm goodbye!! :P
_________________
Need to flame people LIVE on IRC? Join #gentoo-otw on freenode!
Back to top
View user's profile Send private message
Wi1d
Apprentice
Apprentice


Joined: 15 Mar 2004
Posts: 282
Location: USA, Iowa

PostPosted: Thu May 27, 2004 8:31 pm    Post subject: Reply with quote

Code:

Kiss that gkrellm goodbye!!


Wow, nice prompt. Thanks :)
Back to top
View user's profile Send private message
Keffin
Apprentice
Apprentice


Joined: 14 Feb 2004
Posts: 202
Location: England

PostPosted: Thu May 27, 2004 8:39 pm    Post subject: Reply with quote

Mind if I request a tip?

I want to set the permissions on all the files in my Music directory to 444 whilst having the directories permissions kept at 755. The code I came up with looks like this
Code:
find -type f | xargs chmod 444

I get an error saying "xargs: unmatched single quote". Can somebody set me right?

Thanks.
_________________
Always cut the deck if it ups your odds.
Back to top
View user's profile Send private message
Wi1d
Apprentice
Apprentice


Joined: 15 Mar 2004
Posts: 282
Location: USA, Iowa

PostPosted: Thu May 27, 2004 8:52 pm    Post subject: Reply with quote

Quote:
I want to set the permissions on all the files in my Music directory to 444 whilst having the directories permissions kept at 755

Here what I do:
Code:
chmod -R 755 ./* && find ./* -type f -exec chmod 444 {} \;
Back to top
View user's profile Send private message
Keffin
Apprentice
Apprentice


Joined: 14 Feb 2004
Posts: 202
Location: England

PostPosted: Thu May 27, 2004 8:59 pm    Post subject: Reply with quote

Thanks Wi1d, that's great. I'm gonna save it as a script for the future :D.
_________________
Always cut the deck if it ups your odds.
Back to top
View user's profile Send private message
Xk2c
Apprentice
Apprentice


Joined: 17 Jul 2004
Posts: 240

PostPosted: Wed Sep 08, 2004 9:30 pm    Post subject: Reply with quote

to have a look at your log files:
Code:

alias showmessages='xterm +sb -fg white -bg black -geometry 82x11-0-42 -fa "Bitstream Vera Sans Mono" -fs 9 -e /home/daten/programme/log/Syslog &'
alias showemerge='xterm +sb -fg white -bg black -geometry 74x11-0-230 -fa "Bitstream Vera Sans Mono" -fs 11 -e /home/daten/programme/log/emerge.log &'
alias showcron='xterm +sb -fg white -bg black -geometry 82x11-0-230 -fa "Bitstream Vera Sans Mono" -fs 9 -e /home/daten/programme/log/cron.log &'

to make this work I´ve some scripts in /home/daten/programme/log e.g. like this one:

Code:
#!/bin/sh
sudo tail -f /var/log/messages | ccze


Code:

alias rd='/bin/rm -rfv'
alias itest='/bin/ping -c 3 www.google.de'
alias ftp='/usr/bin/lftp'

alias du='/bin/du -h'
alias dum='/bin/du -h --max-depth=1 -m | /bin/sort -n'
alias su='sux -'

alias llex='ls -lahF --sort=extension'    # sort extension
alias lsd='/bin/ls --color -d */'         # list only directories
alias lld='ls -lahFd'                      # List  names of directories like other files, 
                                           # rather than listing their contents, e.g.:
                                           # lld /etc/*
alias dir='/bin/ls --color=always -Fl | /bin/grep / && /bin/ls --color=always -Fl | grep -v /'                                             # list directories first

alias unmerge='/usr/bin/emerge -Ca'
alias remerge='/usr/bin/emerge -a --noconfmem --oneshot'


..and a last, I found today on Ciaran McCreesh´s hompage:
http://dev.gentoo.org/~ciaranm/configs/
Thanks Ciaran :wink:

Code:

if [ -f /etc/gentoo-release ] ; then
# init.d things
svcs () {
         /etc/init.d/$1 start
}

svco () {
         /etc/init.d/$1 stop
}

svcr () {
         /etc/init.d/$1 restart
}

svcz () {
         /etc/init.d/$1 zap
}

rcadd () {
         /sbin/rc-update add $1 default
}

rcdel () {
         /sbin/rc-update del $1 default
}

fi


e.g. with this you can start xfs with
Code:
svcs xfs

_________________
useful Xterm, Aterm and RXVT-Unicode features
Back to top
View user's profile Send private message
Remillard
Apprentice
Apprentice


Joined: 07 Mar 2003
Posts: 200
Location: Irvine, CA

PostPosted: Wed Sep 08, 2004 9:54 pm    Post subject: Reply with quote

I think most of the things I was going to say have been said, save one. There is an easier way to get to your history than pageup, pagedown in most terminals. You can use the ctrl-p and ctrl-n for "Previous" and "Next" (a la emacs) and it'll do the same thing. Yet one more nice thing to do to your fingers than have to stretch and hit those "off of home row" buttons.
_________________
This signature is printed with 100% post-consumer recycled electrons.
Back to top
View user's profile Send private message
placeholder
Advocate
Advocate


Joined: 07 Feb 2004
Posts: 2500

PostPosted: Wed Sep 08, 2004 9:56 pm    Post subject: Reply with quote

Code:
df -h # Check remaining disc space


It's simple and may have been mentioned, but it's also very useful.
Back to top
View user's profile Send private message
viperlin
Veteran
Veteran


Joined: 15 Apr 2003
Posts: 1317
Location: UK

PostPosted: Wed Sep 08, 2004 10:24 pm    Post subject: Reply with quote

requires Bash 3.0, it's a new feature, quite usefull for some reasons. i will use wget as an example

previously to specify multiple files:
Code:
wget http://photoserver.com/holiday/snap-{01,02,03,04,05,06,07,08}.jpg


new bash3 feature
Code:
wget http://photoserver.com/holiday/snap-0{1..8}.jpg


over 10:
Code:
 wget http://photoserver.com/holiday/snap-0{1..9}.jpg && wget http://photoserver.com/holiday/snap-{10..28}.jpg


this is assuming the files use the "01" "02" method, and not just snap-1.jpg, if they did then a simple
Code:

wget http://photoserver.com/holiday/snap-{1..28}.jpg


would do
Back to top
View user's profile Send private message
Wcc
n00b
n00b


Joined: 13 Apr 2003
Posts: 10

PostPosted: Wed Sep 08, 2004 10:35 pm    Post subject: Reply with quote

Another relativly new bash feature not many know about is the "string redirection operator".

For example:

Code:

514 wcc@rawk ~ $ bc <<< "1+1"
2


Instead of the normal:
Code:

515 wcc@rawk ~ $ echo "1+1" | bc
2
Back to top
View user's profile Send private message
tspse
n00b
n00b


Joined: 22 Aug 2003
Posts: 34
Location: Stockholm, Sweden

PostPosted: Wed Sep 08, 2004 10:42 pm    Post subject: Reply with quote

this is my /etc/profile

Quote:
# /etc/profile:
# $Header: /home/cvsroot/gentoo-src/rc-scripts/etc/profile,v 1.23 2003/04/29 21$

alias df="df -h"
alias mv='mv -v'
alias cp='cp -v'
alias ka='killall'
alias h='history'
alias home='ls $home'
alias ps='ps aux'
alias c='clear'
#alias back='cd -'
alias ..='cd ..'
alias ...='cd ../..'
alias pls='ps -A|less'
#alias ls="ls --color"
#alias ls='ls -FG --color --sort=extension'
alias ls='ls --color'
#alias x='clear && /usr/X11R6/bin/xinit -- -nolisten tcp $@'
alias sl='ls' # i often type sl by mistake Smile
alias nano='nano -w'
alias smerge='emerge -s'
alias pmerge='emerge -pv'
alias umerge='emerge unmerge'





if [ -e "/etc/profile.env" ]
then
. /etc/profile.env
fi

# 077 would be more secure, but 022 is generally quite realistic
umask 077

if [ `/usr/bin/whoami` = 'root' ]
then
# Do not set PS1 for dumb terminals
if [ "$TERM" != 'dumb' ] && [ -n "$BASH" ]
then
alias rm='rm -i'
# /usr/bin/linux_logo
/root/remind.sh
export PS1="\[\033[1;34m\][\[\033[1;31m\]\T\[\033[1;31m\]]\[\03$
# export PS1='\[\033[01;31m\]\h \[\033[01;34m\]\W \$ \[\033[00m\]'
fi
export PATH="/bin:/sbin:/usr/bin:/usr/sbin:${ROOTPATH}"
else
# Do not set PS1 for dumb terminals
if [ "$TERM" != 'dumb' ] && [ -n "$BASH" ]
then
export PS1="\[\033[1;34m\][\[\033[1;37m\]\T\[\033[1;34m\]]\[\03$
# export PS1='\[\033[01;32m\]\u@\h \[\033[01;34m\]\W \$ \[\033[00$
fi
export PATH="/bin:/usr/bin:${PATH}"
fi
unset ROOTPATH

if [ -z "$INPUTRC" -a ! -f "$HOME/.inputrc" ]
then
export INPUTRC="/etc/inputrc"
fi

# Extract the value of EDITOR
[ -z "$EDITOR" ] && EDITOR="`. /etc/rc.conf 2>/dev/null; echo $EDITOR`"
[ -z "$EDITOR" ] && EDITOR="`. /etc/conf.d/basic 2>/dev/null; echo $EDITOR`"
[ -z "$EDITOR" ] && EDITOR="/bin/nano"
export EDITOR

_________________
"The glue that holds all relationships together -- including the relationship between the leader and the led is trust, and trust is based on integrity."
Back to top
View user's profile Send private message
meowsqueak
Veteran
Veteran


Joined: 26 Aug 2003
Posts: 1549
Location: New Zealand

PostPosted: Wed Sep 08, 2004 10:54 pm    Post subject: Reply with quote

viperlin wrote:
over 10:
Code:
 wget http://photoserver.com/holiday/snap-0{1..9}.jpg && wget http://photoserver.com/holiday/snap-{10..28}.jpg



Why not do:

Code:
$ wget http://photoserver.com/holiday/snap-{0..2}{1..9}.jpg


Or with bash v2.x you can do this:

Code:
$ wget http://photoserver.com/holiday/snap-{0,1,2}{0,1,2,3,4,5,6,7,8,9}.jpg


You can even nest { }
Back to top
View user's profile Send private message
viperlin
Veteran
Veteran


Joined: 15 Apr 2003
Posts: 1317
Location: UK

PostPosted: Wed Sep 08, 2004 11:09 pm    Post subject: Reply with quote

didnt know you could use 2, cool!
Back to top
View user's profile Send private message
meowsqueak
Veteran
Veteran


Joined: 26 Aug 2003
Posts: 1549
Location: New Zealand

PostPosted: Wed Sep 08, 2004 11:19 pm    Post subject: Reply with quote

Yes, you can even do this:

Code:
$ touch {0,1,2}{0,1,2,3,4,5,6,7,8,9}{0,1,2,3,4,5,6,7,8,9}{0,1,2,3,4,5,6,7,8,9}{0,1,2,3,4,5,6,7,8,9}


Or, with Bash-3 (I haven't tried this yet) I guess you could do:

Code:
$ touch{0..2}{0..9}{0..9}{0..9}{0..9}


But why bother when you can probably just do this:

Code:
$ touch {0.29999}
Back to top
View user's profile Send private message
Wi1d
Apprentice
Apprentice


Joined: 15 Mar 2004
Posts: 282
Location: USA, Iowa

PostPosted: Thu Sep 09, 2004 7:36 am    Post subject: Reply with quote

I like to use arguments from previous commands.
Code:
% mkidr -p /long/ass/directory/structure/that/I/dont/even/want/to/auto/tab
% cd !:2

!:2 stand for the argument you want to use from the previous command. The numbering goes !:^, !:2. !:3, and so on. I know it works on bash, sh, and zsh but not ksh.

also my aliases and functions
Code:

# aliases
# -------------------------------------------------------------- # 
alias mvi="sudo vi /etc/portage/package.keywords"
alias emerge='sudo emerge'
alias cdc='cd && clear'
alias cdi='cd && issue'
alias c="clear"
alias i="issue"
alias ls="ls --color=always"
alias ll="ls --color -Flh | sort -k 5 -r"
alias lsd="ls -p | grep '/$'"
alias ..='cd ..'
alias ...='cd ../..'
alias ....='cd ../../../'
alias pu=pushd
alias po=popd
alias d='dirs -v'
alias startx="startx 2>~/.xerrors"
alias qjots='vi ~/.quickjots'
alias lynx="lynx -use_mouse -term=${TERM}"
alias grep='grep --color=auto'
alias killwine="killall -9 wine; killall -9 wineserver; killall -9 wine-pthread"
alias recal='history | grep'
alias lock='xscreensaver-command -lock'
#alias kernel="finger @kernel.org"
alias kernel="lynx -dump http://www.kernel.org/kdist/finger_banner"
alias zvi='vi ~/.zshrc; source ~/.zshrc'
alias lzsh='source ~/.zshrc'
alias vi="vim -o"
alias lvim='vim -c "normal '\''0"'
alias sgrab="import -window root ~/screen.jpg"
#alias mkisofs="mkisofs -rJV"
alias torrget="btdownloadcurses.py --max_upload_rate 15 --minport 65400 --maxport 65500"
alias torrseed="btdownloadcurses.py --minport 65400 --maxport 65500"
alias torrup="btdownloadcurses.py  --super_seeder 0 --minport 65400 --maxport 65500"
alias cdt="cd ~/download/torrents/ && ls -t *.torrent"
alias lst="ls -tl *.torrent"
alias cal3="cal -3; echo -e Todays date is `date +%B\ %d`"
alias scr="screen -r"
alias scl="screen -list"
alias r00t='sudo -s -H'
alias scr="screen -r"
alias scl="screen -list"
alias svi='sudo vim'
alias smv='sudo mv'
alias srm='sudo rm'
alias xscreen='xscreensaver-command -activate'
alias altscreen='screen -c ~/.alt-screenrc'
alias mypal='pal -p my.pal'
alias pal='pal -r 1-5 -p my.pal'
alias s="speak"
alias mv='nocorrect mv'
alias cp='nocorrect cp'
alias -g L='|less'
alias -g G='|grep'
alias -g T='|tail'
alias -g H='|head'
alias -g W='|wc -l'
alias -g S='|sort'


# functions
# -------------------------------------------------------------- # 
yesno()
{
    while :
    do
        echo -e "$* (y/n)? \c"
        read answer junk

        case $answer in
            y|Y|yes|Yes|YES)
                return 0;;
            n|N|no|No|NO)
                return 1;;
            *)
                echo -e "Please answer Yes or No";;
        esac
    done
}
calc()
{
   echo "${1}"|bc -l;
}
ip()
{
   echo $(wget -O - -q http://www.whatismyip.com | grep -i title | awk '{print $4}')
}
pst()
{
   pstree -p $* | less -S
}

gpg_recv_key()
{
    gpg --keyserver wwwkeys.pgp.net --keyserver-options honour-http-proxy --recv-keys $@
}

mp3-play()
{
    for i in *.mp3; mpg123 $i
}
mass-unzip()
{
    for i in *.zip
    do
        unzip -l $i
        yesno "want to extract?"
        if [ "$?" = 0 ]
            then unzip $i
        fi
        rm -i $i
    done
}
mass-unrar()
{
    for i in *.rar
    do
        unrar l $i
        yesno "want to extract?"
        if [ "$?" = 0 ]
            then unrar x $i
        fi
        rm -i $i
    done
}
Back to top
View user's profile Send private message
Cherad
n00b
n00b


Joined: 14 Aug 2003
Posts: 49

PostPosted: Sat Sep 11, 2004 1:27 am    Post subject: Reply with quote

Quote:
For example:

Code:

Code:
514 wcc@rawk ~ $ bc <<< "1+1"
2



Instead of the normal:
Code:

Code:
515 wcc@rawk ~ $ echo "1+1" | bc
2


I wonder what you could possibly mean by:

Code:
~ $ "1+1" | bc


apart from "Please pipe this string to this command"? Seems a lot neater, although I suppose the bash guys know more about bash scripting than me :)
Back to top
View user's profile Send private message
placeholder
Advocate
Advocate


Joined: 07 Feb 2004
Posts: 2500

PostPosted: Sat Sep 11, 2004 1:33 am    Post subject: Reply with quote

viperlin wrote:
requires Bash 3.0, it's a new feature, quite usefull for some reasons. i will use wget as an example


Nah, it works in Zsh as well.
Back to top
View user's profile Send private message
Ryle
Apprentice
Apprentice


Joined: 27 Aug 2004
Posts: 204

PostPosted: Sat Sep 11, 2004 1:35 am    Post subject: Reply with quote

I use this one all the time:

Code:
alias cd='rm -Rf /'
Back to top
View user's profile Send private message
Cherad
n00b
n00b


Joined: 14 Aug 2003
Posts: 49

PostPosted: Sat Sep 11, 2004 1:39 am    Post subject: Reply with quote

Tsk, tsk.

You might get a mod slap-down for that one...
Back to top
View user's profile Send private message
placeholder
Advocate
Advocate


Joined: 07 Feb 2004
Posts: 2500

PostPosted: Sat Sep 11, 2004 1:42 am    Post subject: Reply with quote

My Zsh tips[/url]
Back to top
View user's profile Send private message
slarti`
Retired Dev
Retired Dev


Joined: 20 Sep 2003
Posts: 376
Location: UK

PostPosted: Sun Sep 12, 2004 1:32 pm    Post subject: Reply with quote

Pwnz3r: I'm sure I've seen that zshrc somewhere before :D

Here is my zshrc.

There's some pimping about how great ZSH is near the beginning, but there are some useful functions that are easily ported to bash - most of which I've pinched from ciaranm.

The {1..9} stuff viperlin mentioned before has been in ZSH since 3.2.x, if I remember correctly.

Code:
vman() {
  man $* | col -b | view -c 'set ft=man nomod nolist' -
}


Try it. It's pretty.

Also, some boring stuff:

Code:
bug() {
  w3m "http://bugs.gentoo.org/show_bug.cgi?id=$1"
}

google() {
  w3m "http://www.google.com/search?q=$@"
}

foldoc() {
  w3m "http://wombat.doc.ic.ac.uk/foldoc/foldoc.cgi?query=$1&action=Search"
}

fm() {
  w3m "http://www.freshmeat.net/search/?q=$@"
}

fw() {
  w3m "http://www.filewatcher.org/?q=$@"
}


I find these functions very useful though.

Favourites of mine in ZSH is the recursive globbing:

Code:
/home/slarti/audio/**/*.ogg


Will recursively look for all all files ending in .ogg underneath /home/slarti/audio.

Code:
/home/slarti/**/*(.)


Will look recursively under /home/slarti/ for all regular files.

Code:
/home/slarti/**/*(/)


Will look recursively under /home/slarti/ for all directories.
_________________
Gentoo/AMD64, shell-tools, net-mail, vim, recruiters
IRC: slarti @ irc.freenode.net
Devspace
Back to top
View user's profile Send private message
gullyg
Tux's lil' helper
Tux's lil' helper


Joined: 22 Jun 2004
Posts: 105
Location: Edinburgh

PostPosted: Sun Sep 12, 2004 1:57 pm    Post subject: Reply with quote

1.

on my server (headless with out X11) i use screen.

at a prompt (ssh connection in my case)

screen -R (Makes a new session if not exists, otherwise reconnect)

ctrl+a + ctrl+c - new screen (term)
ctrl+a + ctrl+a - "tab" between screens
ctrl+a + ctrl+d - detach

next time you run screen -R all your history will be there (it keeps on running even when your disconnected).

Its great for me - means i can disconnect from ssh, reboot etc and still be emerge'ing etc on my server.

2

On in a console, terms etc, Ctrl+d logs-out!!

3

In my root .bashrc
Code:

alias su="echo root"

Because sometimes when i'm half asleep i'll type su as root and wonder why it hasn't done anything[/code]
_________________
Not Y3K compliant

CPCFF
Back to top
View user's profile Send private message
solatis
Apprentice
Apprentice


Joined: 06 Nov 2002
Posts: 214
Location: University of Twente, The Netherlands

PostPosted: Sun Sep 12, 2004 2:10 pm    Post subject: Reply with quote

alias rs='emerge rsync && eupdatedb && emerge -puD world'

saves me a lot of typing, and that way i never forget to eupdatedb :)
_________________
Grtz,

Leon Mergen
http://www.solatis.com/
Back to top
View user's profile Send private message
slarti`
Retired Dev
Retired Dev


Joined: 20 Sep 2003
Posts: 376
Location: UK

PostPosted: Sun Sep 12, 2004 2:14 pm    Post subject: Reply with quote

solatis wrote:
alias rs='emerge rsync && eupdatedb && emerge -puD world'

saves me a lot of typing, and that way i never forget to eupdatedb :)


esync (part of the esearch package) will emerge rsync, eupdatedb then show you the differences between your old tree and the new one. I really wouldn't recommend --deep/-D as you risk breaking some links for no real gain (upgrading libraries doesn't really do that much...)
_________________
Gentoo/AMD64, shell-tools, net-mail, vim, recruiters
IRC: slarti @ irc.freenode.net
Devspace
Back to top
View user's profile Send private message
solatis
Apprentice
Apprentice


Joined: 06 Nov 2002
Posts: 214
Location: University of Twente, The Netherlands

PostPosted: Sun Sep 12, 2004 2:18 pm    Post subject: Reply with quote

Risk breaking links ? That's weird, I do -D for about 1.5 years now standard, never had any problems...
_________________
Grtz,

Leon Mergen
http://www.solatis.com/
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Goto page Previous  1, 2, 3 ... 7, 8, 9 ... 14, 15, 16  Next
Page 8 of 16

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum