Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Discussion & Documentation Documentation, Tips & Tricks
  • Search

Console / shell tips & tricks

Unofficial documentation for various parts of Gentoo Linux. Note: This is not a support forum.
Post Reply
Advanced search
376 posts
  • Page 14 of 16
    • Jump to page:
  • Previous
  • 1
  • …
  • 12
  • 13
  • 14
  • 15
  • 16
  • Next
Author
Message
Bones McCracker
Veteran
Veteran
User avatar
Posts: 1611
Joined: Tue Mar 14, 2006 8:23 am
Location: U.S.A.

  • Quote

Post by Bones McCracker » Thu Dec 13, 2007 4:20 am

ppurka wrote:
BoneKracker wrote:
ppurka wrote:duh!
http://www.amazon.com/How-Win-Friends-I ... 0671723650
eww! Who reads all that :roll:
People who used to say "duh!" when offering someone a tip? :)
patrix_neo wrote:The human thought: I cannot win.
The ratbrain in me : I can only go forward and that's it.
Top
swimmer
Veteran
Veteran
User avatar
Posts: 1330
Joined: Mon Jul 15, 2002 10:42 am
Location: Netherlands

  • Quote

Post by swimmer » Thu Dec 13, 2007 2:20 pm

ppurka wrote:duh!

Code: Select all

echo "bindkey "^R"                history-incremental-search-backward
bindkey "^S"                history-incremental-search-forward" >> .zshrc
. .zshrc
Luckily I don't know what "duh!" means and I think I don't want to know ;-)

Thanks for the tip ppurka :)
Top
Alanceil
n00b
n00b
User avatar
Posts: 36
Joined: Tue Aug 14, 2007 10:25 pm
Location: Regensburg, Germany

  • Quote

Post by Alanceil » Sat Dec 15, 2007 12:41 am

Why didn't I find this thread earlier ? *beats himself*
There were some really nice gems in here. ( Feels like "You just gained a level in Bash Magic!" )

In return, part of my bash config:

Code: Select all

shopt -s cdspell
shopt -u extdebug

complete -d cd
complete -c which
complete -c man
complete -c killall

alias ..='cd ..'
alias ...='cd ../..'
alias ....='cd ../../..'
alias .....='cd ../../../..'
alias l='ls -lF --color=always'
alias la='ls -la --color=always'
alias lh='ls -lh --color=always'
alias ll='ls -l --color=always'
alias ls='ls --color=always'
alias lS='ls -lS'
alias c='cd'
alias o='/usr/bin/less'
alias vo='/usr/bin/vim'
alias bi='/usr/bin/vim'
alias vu='/usr/bin/vim'
alias suvi='sudo /usr/bin/vim'
alias xc='/usr/bin/xv'

PS1='\[\033[0;32m\]\u@\h\[\033[0m\]:\[\033[0;36m\]\A\[\033[0m\]:\[\033[1;30m\]${?}\[\033[0m\]:\[\033[1;34m\]\w\[\033[0m\]>\[\033[0m\] '
I sometimes hit the wrong keys when I want to start vi, so there are some aliases to catch that. (In case you ask)
Top
ppurka
Advocate
Advocate
Posts: 3257
Joined: Sun Dec 26, 2004 5:05 pm

  • Quote

Post by ppurka » Sat Dec 15, 2007 3:11 am

Alanceil wrote:I sometimes hit the wrong keys when I want to start vi, so there are some aliases to catch that. (In case you ask)
I believe there is some shell setting which makes the shell suggest you the correct alternative if you had a typo in the previous command.
emerge --quiet redefined | E17 vids: I, II | Now using kde5 | e is unstable :-/
Top
purpler
n00b
n00b
User avatar
Posts: 38
Joined: Thu Jan 11, 2007 7:38 pm
Location: /v*/l*/p*/world

  • Quote

Post by purpler » Wed Dec 19, 2007 10:22 am

oh yes, that setting is called ZSH :)

/etc/zsh/zshrc:
setopt correctall
Our system, who art on raised tile,hallowed be thy OS..
Gentoo.
Top
Alanceil
n00b
n00b
User avatar
Posts: 36
Joined: Tue Aug 14, 2007 10:25 pm
Location: Regensburg, Germany

  • Quote

Post by Alanceil » Thu Dec 20, 2007 12:13 am

Then I'll still have to use my vi aliases ;)
I tried zsh several times, and never liked it.

... and sth. for the topic:

Code: Select all

function path(){
        test -e "$1" && echo "`pwd`/${1}"
}
Top
Dralnu
Veteran
Veteran
User avatar
Posts: 1919
Joined: Wed May 24, 2006 5:33 pm

  • Quote

Post by Dralnu » Sat Dec 22, 2007 6:27 am

purpler wrote:oh yes, that setting is called ZSH :)

/etc/zsh/zshrc:
setopt correctall
bash has a similar feature.
The day Microsoft makes a product that doesn't suck, is the day they make a vacuum cleaner.
Top
arcanex
n00b
n00b
Posts: 1
Joined: Sun Jun 10, 2007 8:36 am

  • Quote

Post by arcanex » Tue Mar 04, 2008 7:31 am

BashFAQ

http://wooledge.org:8000/BashFAQ

BashPitfalls

http://wooledge.org:8000/BashPitfalls

Between them, just about everything you might ever want to know about BASH.
Top
MartyParish
n00b
n00b
Posts: 40
Joined: Fri Oct 08, 2004 1:27 pm
Location: Maryland-US

  • Quote

Post by MartyParish » Sun Mar 09, 2008 8:09 pm

Hey, here's a list that contains plenty of stuff that's been mentioned already but some stuff that I did not see. I read the whole thread too! It was great.

Ctrl + A - Go to the beginning of the line you are currently typing on

Ctrl + E - Go to the end of the line you are currently typing on

Ctrl + L - Clears the Screen, similar to the clear command

Ctrl + U - Clears the line before the cursor position. If you are at the end of the line, clears the entire line.

Ctrl + H - Same as backspace

Ctrl + R - Let’s you search through previously used commands

Ctrl + C - Kill whatever you are running

Ctrl + D - Exit the current shell

Ctrl + Z - Puts whatever you are running into a suspended background process. fg restores it.

Ctrl + W - Delete the word before the cursor

Ctrl + K - Clear the line after the cursor

Ctrl + T - Swap the last two characters before the cursor

Esc + T - Swap the last two words before the cursor

Alt + F - Move cursor forward one word on the current line

Alt + B - Move cursor backward one word on the current line

Tab - Auto-complete files and folder names

Ctrl + W - erase word before cursor

Ctrl + Y - to paste it (as in delete and copy) all text in front of the cursor

Esc + . (or Esc + Underscore) - Insert Last Argument

Ctrl + b - Move back a character

Ctrl + f - Move forward a character

Ctrl + r - Search the history backwards

Ctrl + xx - Move between EOL and current cursor position

Ctrl + x @ - Show possible hostname completions

Alt + < - Move to the first line in the history

Alt + > - Move to the last line in the history

Alt + ? - Show current completion list

Alt + * - Insert all possible completions

Alt + / - Attempt to complete filename

Alt + . - Yank last argument to previous command

Alt + c - Capitalize the word

Alt + d - Delete word

Alt + l - Make word lowercase

Alt + n - Search the history forwards non-incremental

Alt + p - Search the history backwards non-incremental

Alt + r - Recall command

Alt + t - Move words around

Alt + u - Make word uppercase

Alt + back-space - Delete backward from cursor

Here "2T" means Press TAB twice

$ 2T - All available commands(common)

$ (string) 2T - All available commands starting with (string)

$ /2T - Entire directory structure including Hidden one

$ 2T - Only Sub Dirs inside including Hidden one

$ *2T - Only Sub Dirs inside without Hidden one

$ ~2T - All Present Users on system from "/etc/passwd"

$ $2T - All Sys variables

$ @2T - Entries from "/etc/hosts"

$ =2T - Output like ls or dir
Top
devsk
Advocate
Advocate
User avatar
Posts: 3039
Joined: Fri Oct 24, 2003 1:16 am
Location: Bay Area, CA

  • Quote

Post by devsk » Sat Mar 29, 2008 5:48 am

put this in your ~/.bashrc if you just want to override part of the DIR_COLORS and don't want to copy the full file to ~/.dir_colors and maintain it in future if /etc/DIR_COLORS changes:

Code: Select all

eval `cat /etc/DIR_COLORS ~/.dir_colors | dircolors -
Top
David Serrano
n00b
n00b
Posts: 16
Joined: Wed Mar 26, 2008 10:04 am

  • Quote

Post by David Serrano » Mon Apr 14, 2008 2:43 pm

Great thread!!
tam1138 wrote:Also, using the ":p" option on any potentially-dangerous bash replacement tricks is useful: it prints out the command that WOULD be run and also appends it to your history. That is, if you think you want to run the last command starting with 'r' in your history but don't want to hose yourself before verifying the command:

Code: Select all

$ !r:p
rm -rf /
I use:

Code: Select all

shopt -s histverify
With this, you get confirmation for all history expansions. That's useful not only for verifying potentially harmful 'rm' commands, but also to change some parameters, files and whatever before actually running the command.

Here are my aliases and functions:

Code: Select all

function del() {
  /bin/mv -f "$@" $HOME/.trash/;
}
alias cd='cd -P'
alias ls='ls -F -N --color=tty --time-style="+%Y%m%d:%H%M%S%z"'
alias ll='ls -l'
alias cl='clear; logout'
alias cv='clear; vlock -a'
alias lless='ll -R --color=always | less -r'
## allows 'h emerge -s' without quoting the space
function h() { HISTTIMEFORMAT= history | grep "$*"; }

alias ltrace='ltrace -S -tt -C'
alias strace='strace -s 500 -tt -ff'
alias vim='vim -X -o'
alias bc='bc ~/.bcrc'  ## set up default number of decimals, .bcrc contains "scale=4"
alias perl='perl -Mstrict -w'
alias pf='perldoc -f'
alias pd='perldoc'
alias pq='perldoc -q'
alias xev='xev | grep keycode'

function rmoz() {
    ## ripped from      https://bugzilla.mozilla.org/attachment.cgi?id=151958
    ## which appears in https://bugzilla.mozilla.org/show_bug.cgi?id=246168
    if [ "$1" ]; then 
        if [ -f "$PWD/$1" ]; then
            LOCAL="file://$PWD/$1"
        elif [ -f "$1" ]; then 
            LOCAL="file://$1"
        else 
            LOCAL="$1"
            [[ $LOCAL =~ ^http:// ]] || LOCAL="http://$LOCAL"
        fi
        DISPLAY=:0 mozilla -remote "openurl($LOCAL,new-tab)"
    fi
}
## show version of specified perl modules
function pmver() { perl -le "eval { require ${1} } and print qq{${1}: },\$${1}::VERSION or print qq{${1}: none}"; }
function ls-() { ls -"$@"; }
Environment variables:

Code: Select all

export HISTCONTROL=ignoredups:erasedups
export HISTIGNORE="date:df:fg:jd:jobs:ll:ls"
export HISTTIMEFORMAT="%Y%m%d:%H%M%S%z"
export IGNOREEOF=1
export LESS='-c -h1 -y1 -j2 -S'
export LESS="$LESS -P B%bt-%bB?B/%B.?pt(%pt\%). ?ltL%lt-%lb.?L/%L.?Pt(%Pt\%). .?f%f:-.?e (END).?m (file %i of %m).%t"
unset LESSOPEN  ## hate this
## use with 'ps -eH' or 'ps -e f'
export PS_FORMAT="pid,pgid,euid,egid,nlwp:2=NT,ni:2,rtprio:2=RT,cls:2,vsz:6,rss:6,pcpu,pmem,stat:3=ST,tname:6,stime,bsdtime,args"
export TIMEFORMAT=$'\nreal: %3R, user: %3U, sys: %S'
export TMPDIR=~/tmp
export TMP=$TMPDIR

unset PERL5LIB;
DIRS=(~/em/perl-modules/{lib,share}/perl/*);
local IFS=":";
export PERL5LIB="${DIRS[*]}";
Misc:

Code: Select all

shopt -s cdable_vars checkhash checkwinsize cmdhist extquote histappend histreedit histverify
shopt -u force_fignore

if [[ "`tty`" =~ ^/dev/tty ]]; then  ## things for console only
  setterm -blength 10 -bfreq 10000   ## barely hearable, prevents waking up people
fi
.inputrc:

Code: Select all

set horizontal-scroll-mode off
## 'audible' or 'visible'
set bell-style audible
set meta-flag on
set input-meta on
set output-meta on
set convert-meta off
set history-preserve-point on
set editing-mode vi-command
set keymap vi-command
set page-completions off
set visible-stats on
## todo: yank-nth-arg
## todo: yank-last-arg
.xbindkeysrc:

Code: Select all

"xkbcomp /home/hue/.hue-xkb/es-qwerty-hue :0"
  control+F1

"xkbcomp /home/hue/.hue-xkb/es-dvorak-hue :0"
  control+F2

"xwd -root -silent | convert xwd:- png:/home/hue/xwd-$(date +%Y%m%d:%H%M%S.png)"
 Print
The ~/.hue-xkb files were generated by using xkbcomp; then further tweaked. It's like using xmodmap.

Last, I'd like to bump this excellent tip (not for obtaining the IP, but for its use of 'set'):
dub.wav wrote:

Code: Select all

alias currentip='set `/sbin/ifconfig eth0` && echo ${7#*:}'
David Serrano
Top
faux
n00b
n00b
Posts: 61
Joined: Fri Oct 26, 2007 9:32 am
Location: Linz, Austria
Contact:
Contact faux
Website

  • Quote

Post by faux » Tue Apr 29, 2008 2:14 pm

Nice thread. Read the whole one, really useful!

Job Management

Code: Select all

%<job ID>
recalls a running or suspended job.

Code: Select all

jobs
lists jobs of current session.
Ctrl+Z suspends current job and sends it to background.

Code: Select all

<command> &
starts a job in backgroud.

screen usage in my .bashrc

Code: Select all

if [ $SHLVL -eq 1 ]; then
  /usr/bin/screen -xRR
fi
Resumes the last screen session (or starts a new one, if nothing to resume) if using an tty (not a terminal like xterm) or SSH session. Very useful on SSH sessions if connection times out.

view ebuild of package

Code: Select all

eview() {
        FILE=$(equery which $1)
        if [ -f "$FILE" ]; then
                view $FILE
        fi
}
Top
notHerbert
Advocate
Advocate
User avatar
Posts: 2228
Joined: Tue Mar 11, 2008 11:55 pm
Location: 45N 73W

  • Quote

Post by notHerbert » Fri Oct 03, 2008 2:38 pm

It has happened that I mistyped an append command in an important file.

My desire is to do something like this

Code: Select all

echo "some configuration" >> /etc/somefile
But instead I type

Code: Select all

echo "some configuration" > /etc/somefile
Consider

Code: Select all

# echo "something something" > /etc/passwd
This command would overwrite /etc/passwd, and would be a real pain to repair - even if the error is caught before logging out.


If I add this to .bashrc (then source .bashrc)

Code: Select all

set -o noclobber
Then I can do this

Code: Select all

# echo "a bunch of crap" > /etc/passwd
-su: /etc/passwd: cannot overwrite existing file
Now I caught my typo before making a mess.

Now if my intention really is to overwrite a file, a pipe character will allow me to do that.
To clear the contents of $HOME/.xsession-errors, type

Code: Select all

$ :>| $HOME/.xsession-errors
Top
a.b.
Apprentice
Apprentice
User avatar
Posts: 218
Joined: Sun Mar 23, 2008 12:37 pm
Location: Anus Mundi, Germany
Contact:
Contact a.b.
Website

  • Quote

Post by a.b. » Fri Oct 03, 2008 5:17 pm

The only interesting things in my .zshrc are:

Code: Select all

# With -p, Paludis should have normal niceness
# Else, it should be extremly friendly
function paludis(){
    if echo $@ | egrep '\-.*p\ ' > /dev/null; then
        /usr/bin/paludis $@
    else
        nice -n19 /usr/bin/paludis $@
    fi
}
and

Code: Select all

# For the really bullish processes
function murder(){
    while [[ $? = 0 ]]; do
        kill -9 $@
    done
}
The rest:
http://shellium.org/~aeebee/dotfiles/zshrc
Top
a.b.
Apprentice
Apprentice
User avatar
Posts: 218
Joined: Sun Mar 23, 2008 12:37 pm
Location: Anus Mundi, Germany
Contact:
Contact a.b.
Website

  • Quote

Post by a.b. » Fri Oct 03, 2008 5:19 pm

notHerbert wrote:It has happened that I mistyped an append command in an important file.
That has happened to me several times as well. Backups more or less solve that ;)
Top
notHerbert
Advocate
Advocate
User avatar
Posts: 2228
Joined: Tue Mar 11, 2008 11:55 pm
Location: 45N 73W

  • Quote

Post by notHerbert » Sun Oct 19, 2008 10:02 pm

A bash command prompt that prints the return value in the prompt if it is not equal to zero. :)

Code: Select all

PS1='\w \u$(r=$?; test $r -ne 0 && echo " \[\e[1;31m\]ret:$r")\e[0m\] \$ '
Top
mv
Watchman
Watchman
User avatar
Posts: 6795
Joined: Wed Apr 20, 2005 12:12 pm

  • Quote

Post by mv » Mon Oct 20, 2008 7:50 am

notHerbert wrote:A bash command prompt that prints the return value in the prompt
This is once more an example why it is wiser to use zsh as the interactive shell. There you can just include %? or (for analogous behaviour to your case) %(?||ret:%?) within PS1 (coloring omitted for simplicity). Or even simpler and IMHO more convenient for daily usage: setopt print_exit_value.
Top
Dralnu
Veteran
Veteran
User avatar
Posts: 1919
Joined: Wed May 24, 2006 5:33 pm

  • Quote

Post by Dralnu » Sat Jan 03, 2009 12:40 pm

renice <nice_value> `pgrep <proccess to renice>`

Or

renice <nice_val> $(pgrep <proc>) if you don't want the folks in #bash to yell at you
The day Microsoft makes a product that doesn't suck, is the day they make a vacuum cleaner.
Top
a.b.
Apprentice
Apprentice
User avatar
Posts: 218
Joined: Sun Mar 23, 2008 12:37 pm
Location: Anus Mundi, Germany
Contact:
Contact a.b.
Website

  • Quote

Post by a.b. » Sat Jan 03, 2009 2:02 pm

Code: Select all

function wi() { vi $(equery which $@) 

Code: Select all

function usegrep() { grep $@ /var/repos/*/profiles/use.* }
and a couple of functions like

Code: Select all

function bugz() { if [[ $1 == get ]]; then =bugz $@ | less; else =bugz $@; fi }
Top
Dralnu
Veteran
Veteran
User avatar
Posts: 1919
Joined: Wed May 24, 2006 5:33 pm

  • Quote

Post by Dralnu » Sat Jan 03, 2009 2:05 pm

a.b. wrote:

Code: Select all

function usegrep() { grep $@ /var/repos/*/profiles/use.* }
I don't have a var/repos dir on my system. Are you talking about /usr/portage/profiles/use.desc?
The day Microsoft makes a product that doesn't suck, is the day they make a vacuum cleaner.
Top
a.b.
Apprentice
Apprentice
User avatar
Posts: 218
Joined: Sun Mar 23, 2008 12:37 pm
Location: Anus Mundi, Germany
Contact:
Contact a.b.
Website

  • Quote

Post by a.b. » Sat Jan 03, 2009 3:04 pm

Dralnu wrote:
a.b. wrote:

Code: Select all

function usegrep() { grep $@ /var/repos/*/profiles/use.* }
I don't have a var/repos dir on my system. Are you talking about /usr/portage/profiles/use.desc?
I've put the stuff in more logical places:

Code: Select all

# Folders
REPODIR="/var/repos"
PORTDIR="$REPODIR/gentoo"
PORTDIR_OVERLAY="$REPODIR/local $REPODIR/imported"
source "/var/repos/.layman/make.conf"
DISTDIR="/var/cache/distfiles"
In the default setup it's of course /usr/portage/etc..
Top
Ormaaj
Guru
Guru
User avatar
Posts: 319
Joined: Mon Jan 28, 2008 8:04 am

  • Quote

Post by Ormaaj » Sat Apr 11, 2009 3:30 pm

deleteme
Last edited by Ormaaj on Wed Oct 20, 2010 3:49 am, edited 2 times in total.
Top
loudmax
n00b
n00b
User avatar
Posts: 7
Joined: Wed Mar 30, 2005 5:52 am

smileys

  • Quote

Post by loudmax » Mon Apr 13, 2009 10:33 pm

Here's my prompt string:

Code: Select all

PS1='\[\033[01;32m\]\u@\[\033[01;31m\]\h[\w]:`if [[ $? != 0 ]]; then echo "( "; else echo ") "; fi`\[\033[00m\]'
If the previous command succeeds it shows me it's happy:

Code: Select all

user@host[~]:) /bin/true 
user@host[~]:)
If the previous command fails, it's sad

Code: Select all

user@host[~]:) /bin/false
user@host[~]:( 
Top
nendzd
n00b
n00b
Posts: 68
Joined: Mon Apr 10, 2006 10:38 pm

  • Quote

Post by nendzd » Fri Apr 24, 2009 4:45 pm

^^^^ That is great!

Unfortunately I don't have any tips and tricks to post, although I am getting a lot of use out of this thread, thanks!
Top
coolsnowmen
Veteran
Veteran
User avatar
Posts: 1479
Joined: Wed Jun 30, 2004 6:52 pm
Location: No.VA

Re: smileys

  • Quote

Post by coolsnowmen » Fri Apr 24, 2009 5:04 pm

loudmax wrote:Here's my prompt string:

Code: Select all

PS1='\[\033[01;32m\]\u@\[\033[01;31m\]\h[\w]:`if [[ $? != 0 ]]; then echo "( "; else echo ") "; fi`\[\033[00m\]'
If the previous command succeeds it shows me it's happy:

Code: Select all

user@host[~]:) /bin/true 
user@host[~]:)
If the previous command fails, it's sad

Code: Select all

user@host[~]:) /bin/false
user@host[~]:( 
HAHAHAHAHHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHA
edit: my most recent alias -

Code: Select all

alias ghistory="history | grep"
alias gh="ghistory"
emerge: there are no ebuilds to satisfy "moo"
Top
Post Reply

376 posts
  • Page 14 of 16
    • Jump to page:
  • Previous
  • 1
  • …
  • 12
  • 13
  • 14
  • 15
  • 16
  • Next

Return to “Documentation, Tips & Tricks”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy

 

 

magic