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, ... 13, 14, 15  Next  
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
H-Pi
Apprentice
Apprentice


Joined: 26 Jun 2002
Posts: 175
Location: Delft (NL)

PostPosted: Wed Jan 15, 2003 4:25 pm    Post subject: Reply with quote

but why not just type the first few characters and then press Page Up to scroll trough the history of that particular thing? seems faster to me as finding a number and type !number
Back to top
View user's profile Send private message
zojas
Veteran
Veteran


Joined: 22 Apr 2002
Posts: 1138
Location: Phoenix, AZ

PostPosted: Wed Jan 15, 2003 4:52 pm    Post subject: Reply with quote

H-Pi wrote:
but why not just type the first few characters and then press Page Up to scroll trough the history of that particular thing? seems faster to me as finding a number and type !number


sometimes I do just scroll up. it depends though.

here's an example where typing 'h' (which is aliased to 'history') and then !number is a lot easier than searching backward for the leading substring:

Code:

    32  9:43    make && make install && pu && make
    33  9:43    gvim source_stat.cpp
    34  9:44    make
    35  9:46    make
    36  9:47    make
{now imagine an arbitrary number of more 'make's}
    37  9:47    pu
    38  9:47    h
!32


for all the little makes, I typically just hit the up arrow and enter or !m

but when I need to do the long make command again (which rebuilds a library) then it's time to pull up the history.

btw, 'pu' is an alias for 'pushd'. the directory stack is another cool feature best explained in the man page.
Back to top
View user's profile Send private message
red_over_blue
Guru
Guru


Joined: 16 Dec 2002
Posts: 310

PostPosted: Wed Jan 15, 2003 5:02 pm    Post subject: Reply with quote

Also, look at my alias for "recal"

Code:

alias recal='history | grep"


Now suppose you want to see a list of all the commands you just typed that contain "scp" for example

Code:

recal scp


Then just pick the one you were looking for out of the list. The history command used just by itself is not that powerful, but piping it to grep or some other filter is where things get interesting.
Back to top
View user's profile Send private message
zojas
Veteran
Veteran


Joined: 22 Apr 2002
Posts: 1138
Location: Phoenix, AZ

PostPosted: Wed Jan 15, 2003 5:05 pm    Post subject: Reply with quote

also I do stuff like this:

Code:
rsync -uav junk cash sheets rav:~
rsync -uav rav:~/\{cash,sheets,junk\} .


then later if I want to do it again, I can simply do this:

Code:

h
!12 && !13


then later now that I've combined them I can do

Code:

!rs


(i could probably just type '!r' but I don't like to do that in case I have any stray 'rm' commands in the history 8O)
Back to top
View user's profile Send private message
really
Guru
Guru


Joined: 27 Aug 2002
Posts: 430
Location: nowhere

PostPosted: Wed Jan 15, 2003 5:36 pm    Post subject: Reply with quote

Code:
alias ls="ls -ls --color"
alias killshit="killall -9 wine;killall -9 wineserver"
alias kazaa="cd ~/fakewin/Program\ Files/KaZaA\ Lite/;wine Kazaa.exe"

ctrl+r and you do a "reverse search"
saves typing the arrowkey up to search for some long command your lazy to type again, ;)

i also have "ugasi" in roots .bashrc which means turnoff on coratian.
alias ugasi="shutdown -h now"
im usually very tired in the morning (03:30) and dont want to type that command... :D
(i have to switch to dvorak soon.)
_________________
NoManNoProblem

Get lost before you get shot.
Back to top
View user's profile Send private message
zojas
Veteran
Veteran


Joined: 22 Apr 2002
Posts: 1138
Location: Phoenix, AZ

PostPosted: Wed Jan 15, 2003 5:54 pm    Post subject: Reply with quote

antonik wrote:

(i have to switch to dvorak soon.)


I have these aliases:

Code:

alias asdfg='loadkeys dvorak'
alias aoeui='loadkeys us'


for switching keymaps on the console. it uses the home row keys on the left hand in each keymap. (if you're in 'us', then the home keys are asdf, and typing them gets you to 'dvorak')

I have aliases for 'aoeu' and 'asdf' for toggling the map in X.
Back to top
View user's profile Send private message
really
Guru
Guru


Joined: 27 Aug 2002
Posts: 430
Location: nowhere

PostPosted: Wed Jan 15, 2003 8:30 pm    Post subject: Reply with quote

zojas wrote:
antonik wrote:

(i have to switch to dvorak soon.)


I have these aliases:

Code:

alias asdfg='loadkeys dvorak'
alias aoeui='loadkeys us'


for switching keymaps on the console. it uses the home row keys on the left hand in each keymap. (if you're in 'us', then the home keys are asdf, and typing them gets you to 'dvorak')

I have aliases for 'aoeu' and 'asdf' for toggling the map in X.
coool tip 8)
_________________
NoManNoProblem

Get lost before you get shot.
Back to top
View user's profile Send private message
tactless
l33t
l33t


Joined: 14 Jul 2002
Posts: 642
Location: Mitzpe Adi, Israel

PostPosted: Fri Jan 24, 2003 3:01 pm    Post subject: Reply with quote

Okay, here's one for resuming wget transfers by their log files: ($1 being the log file)

Code:
function wgetresume {
        wget -ba $1 `head -n 1 $1 | sed s/^[0-9\ :-]*//g`
}


I've just learned regular expressions... please tell me if there's any way to improve this.
_________________
Tactless

"If it wasn't for fog, the world would run at a really crappy framerate."

Jabber: tactless@amessage.info
Back to top
View user's profile Send private message
Sven Vermeulen
Developer
Developer


Joined: 29 Aug 2002
Posts: 1341
Location: Mechelen, Belgium

PostPosted: Fri Jan 24, 2003 5:18 pm    Post subject: Reply with quote

Next is in ~/.inputrc:
Code:

"\e[[A":"\C-Aman \C-M"
"\e[[B":"mutt\C-M"
"\e[[C":"slrn\C-M"
"\e[[D":"links www.google.com/linux\C-M"
"\e[[E":"startx\C-M"

These aren't aliases, but shortcuts.

F.i.
Code:

~$ ps

(without return) and pressing "F1" will evoke the ps manpage. Issuing F2 starts mutt, F3 slrn, F4 links and F5 startx.

Very handy !
Back to top
View user's profile Send private message
Munck
n00b
n00b


Joined: 06 Feb 2003
Posts: 35
Location: Skive, Denmark

PostPosted: Fri Feb 07, 2003 1:20 pm    Post subject: Magic with the CLI Reply with quote

Unix Guru Universe has a mailing list that sends one command line tip to your mailbox everyday. You can also see them on their homepage.
Worth checking out.

http://www.ugu.com/sui/ugu/show?tip.today 8)
_________________
Why?
- because I can !
Back to top
View user's profile Send private message
S_aIN_t
Guru
Guru


Joined: 11 May 2002
Posts: 488
Location: Ottawa

PostPosted: Wed Feb 26, 2003 8:42 pm    Post subject: Reply with quote

Empty_One wrote:
dumb question, but how is the hisory better than just cycling through the list with the up arrow? Seems like you would have to read thru the list anyway


when cycling you have to press up all the time to get to the next command. with history you can grep it to find the command you are looking for and excute it. it is especially nice when you are currently at command 1234 and you remember typing out something really long a few hours ago. so you grep history for a portion of that really long command. it will return the number of the command and you can execute the really long command again :)

it would be nice to bind a key to "history|grep $var" so when you are at the console. however, i am not sure how to map keys with bash.
_________________
"That which is overdesigned, too highly
specific, anticipates outcome; the anicipation of
outcome guatantees, if not failure, the
absence of grace."
- William Gibson, "All Tomorrow's Parties"
----
http://petro.tanreisoftware.com
Back to top
View user's profile Send private message
sa
Guru
Guru


Joined: 10 Jun 2002
Posts: 450

PostPosted: Wed Feb 26, 2003 10:40 pm    Post subject: Reply with quote

S_aIN_t wrote:

it would be nice to bind a key to "history|grep $var" so when you are at the console. however, i am not sure how to map keys with bash.


try typing "CTRL r" then start typing the command. It will autocomplete it from what you have written in your history file.
Back to top
View user's profile Send private message
hooligan
n00b
n00b


Joined: 18 Feb 2003
Posts: 48

PostPosted: Thu Feb 27, 2003 12:47 am    Post subject: Reply with quote

I worked with sco for awhile, and got used to these
Code:

alias ls="ls --color"
alias l="ls -latr --color"
alias la="ls -a --color"

then there are these... just other easy ones
Code:

alias untar="tar -xvzf"
alias kernlconf="make dep && make clean bzImage modules modules_install"
Back to top
View user's profile Send private message
steveb
Advocate
Advocate


Joined: 18 Sep 2002
Posts: 4564

PostPosted: Thu Feb 27, 2003 2:33 am    Post subject: Reply with quote

hooligan wrote:
I worked with sco for awhile, and got used to these
Code:

alias ls="ls --color"
alias l="ls -latr --color"
alias la="ls -a --color"

then there are these... just other easy ones
Code:

alias untar="tar -xvzf"
alias kernlconf="make dep && make clean bzImage modules modules_install"


how about this one?
Code:
alias kernlconf="if [ ! -f ./Makefile ];then echo -ne '\a\n\\033[1;31mYou must bin in the kernel directory to execute this command.\\033[0;39m\n\n';else make dep && make clean && make bzImage && make modules && make modules_install && export kernel_ver=\$(grep -i '^VERSION[ ]*=' Makefile|sed -n 's/.*[ ]*=[ ]*\(.*\)/\1/gIp').\$(grep -i '^PATCHLEVEL[ ]*=' Makefile|sed -n 's/.*[ ]*=[ ]*\(.*\)/\1/gIp').\$(grep -i '^SUBLEVEL[ ]*=' Makefile|sed -n 's/.*[ ]*=[ ]*\(.*\)/\1/gIp')\$(grep -i '^EXTRAVERSION[ ]*=' Makefile|sed -n 's/.*[ ]*=[ ]*\(.*\)/\1/gIp');mount /boot;for i in vmlinux System.map .config;do cp -i ./\$i /boot/\${i}-\${kernel_ver};done;for i in bzImage;do cp -i ./arch/i386/boot/\$i /boot/\${i}-\${kernel_ver};done;unset kernel_ver;umount /boot;fi"


cheers

SteveB
Back to top
View user's profile Send private message
Lactic
n00b
n00b


Joined: 18 Jun 2002
Posts: 34
Location: Earth [Minneapolis]

PostPosted: Tue Mar 04, 2003 6:56 am    Post subject: Re: quick console tricks Reply with quote

carambola5 wrote:
Yes, we all know how to alias stuff in /etc/profile or ~/.bashrc or whatever. Some favorites of (seemingly) everyone are:
Code:
alias ls='ls --color'
alias sl='ls --color'


Here's mine:
Code:
alias d="ls --color"
alias ls="ls --color"
alias sl="ls --color -lA"
alias ll="ls --color -l"
alias la="ls --color -lA"
alias rd="rmdir"
alias md="mkdir"
alias cd..="cd .."
Back to top
View user's profile Send private message
zypher
Retired Dev
Retired Dev


Joined: 10 Jun 2002
Posts: 413
Location: Cologne, ger.

PostPosted: Tue Mar 04, 2003 11:18 am    Post subject: Reply with quote

Just one I always do at first and can't understand why it never made into a standard /etc/profile:

Code:
alias updatedb="updatedb --prunepaths='/dev /mnt /proc /tmp /usr/src /usr/portage /var/tmp'"

_________________
linux user 65882
Back to top
View user's profile Send private message
drakonite
l33t
l33t


Joined: 02 Nov 2002
Posts: 768
Location: Lincoln, NE

PostPosted: Tue Mar 04, 2003 11:36 am    Post subject: Reply with quote

zypher wrote:
Just one I always do at first and can't understand why it never made into a standard /etc/profile:

Code:
alias updatedb="updatedb --prunepaths='/dev /mnt /proc /tmp /usr/src /usr/portage /var/tmp'"


There are quite a few people who want /mnt /usr/src and /usr/portage to be in the locate database. /tmp and /var/tmp are pruned by default, and I think /dev and /proc are as well but I don't know for sure about that... What would be really nice to have in /etc/profile would be to have it prune out /bin and /usr .... Those put way too many files in the database ;)

My tip...

I find it very useful to have a script that looks something like the following:
Code:

#!/bin/bash
nice emerge rsync
nice emerge -up world
date
rdate -sup time.nist.gov

which updates the portage tree, spits out all of the updates that would be done, then syncs the time, echoing both previous and new time to let you see how much the time was adjusted by.

Meh... I know it's not much but it's saves me a lot of typing..
_________________
Shoot Pixels Not People

My GPG/PGP Public key
Back to top
View user's profile Send private message
nephros
Advocate
Advocate


Joined: 07 Feb 2003
Posts: 2137
Location: Graz, Austria (Europe - no kangaroos.)

PostPosted: Tue Mar 04, 2003 12:36 pm    Post subject: Reply with quote

speaking of history, the ^R (Ctrl-R) command does also have its uses, just hit it and type away whatever you are searching for.

Now for something completely different. I got tired of typing tar -xjf boo.tar.gz and vice versa, so I wrote this (I call it untar):
Code:

#!/bin/bash

TAR=$(which tar)
UNZIP=$(which unzip)
RAR=$(which rar)

if [ ! -e $1 ]; then
   echo "no filename given"
   exit 1
fi

# returns gzip, bzip2 or Zip
TYPE=$(file $1 | cut -d " " -f 2)
NOEXT=$(echo $1 |cut -d "." -f 1)

if [ $TYPE == "gzip" ]; then
  $TAR -xzf $1
elif [ $TYPE == "bzip2" ]; then
  $TAR -xjf $1
elif [ $TYPE == "Zip" ]; then
  echo file is a .zip!
  unzip -d $NOEXT $1
elif [ $TYPE == "RAR" ]; then
  echo file is a .rar!
  rar x $1 $NOEXT
fi
echo done.

far from perfect, I know, but it works (not having it done with a "case $TYPE in" bugs me a bit, but after all laziness is a virtue or a sysadmin. Also, I should probably refresh my sed and awk knowledge.
_________________
Please put [SOLVED] in your topic if you are a moron.
Back to top
View user's profile Send private message
ViCToR:
n00b
n00b


Joined: 16 Aug 2002
Posts: 46
Location: Barcelona, ES

PostPosted: Tue Mar 04, 2003 1:58 pm    Post subject: Reply with quote

carambola5 wrote:
screenie:
Code:

#!/bin/bash
PICPATH=$HOME/pictures/screenshots
INDEX=`cat $PICPATH/index.dat`
import -window root $PICPATH/ss$INDEX.png
echo $(($INDEX + 1)) > $PICPATH/index.dat


I mapped this to my printscreen key through .fluxbox/keys


My two cents: I have this in my .fluxbox/keys
Code:
Mod1 F12 :ExecCommand import -window root /home/httpd/htdocs/shots/screenshot-`date +%m%d%H%M%S`.png


Which takes a screenshot, names it with the current timestamp and puts it directly on a public path for www access.
_________________
.:: ViCToR ::.
Back to top
View user's profile Send private message
iKiddo
Guru
Guru


Joined: 27 Jun 2002
Posts: 329
Location: Europe?

PostPosted: Tue Mar 04, 2003 1:59 pm    Post subject: Reply with quote

Which package does "import" belong to?
Back to top
View user's profile Send private message
Kaali
Tux's lil' helper
Tux's lil' helper


Joined: 12 May 2002
Posts: 80

PostPosted: Tue Mar 04, 2003 2:56 pm    Post subject: Reply with quote

Less known feature in 'ls' that is in par with "--color".

`ls -F`, Suffix each directory name with `/', each FIFO name with `|', and each name of an executable with `*'.
Back to top
View user's profile Send private message
carambola5
Apprentice
Apprentice


Joined: 10 Jul 2002
Posts: 214
Location: Madtown, WI

PostPosted: Tue Mar 04, 2003 3:13 pm    Post subject: Reply with quote

iKiddo wrote:
Which package does "import" belong to?


ImageMagick (in portage: imagemagick)

Comes with a bunch of useful tools such as "import" and "convert."

If you want to create your own bootsplash images ala "Tip of the Year," you're gonna need convert to downsize your color depth.

Of course, import is the screenshot taker.

While you're at it, grab fbgrab from portage too. It does the same thing as import, but only for the console (framebuffer).
_________________
Get Firefox!

Proper Web Development

I'm done at 999.
Back to top
View user's profile Send private message
Jimbow
Guru
Guru


Joined: 18 Feb 2003
Posts: 597
Location: Silver City, NM

PostPosted: Tue Mar 04, 2003 3:34 pm    Post subject: Reply with quote

Many great ideas. I learned a lot. Thanks. Here are some of mine:
Code:
#-------- long ls listings /w pager --------
function ll  { ls -lF   $@ | more;}
function lla { ls -lAF  $@ | more;}
function llt { ls -lAFt $@ | more;}

#-------- Clean: removes emacs *~ and #*# files --------
function clean {
    if [[ "$#" == "0" ]] ; then set '.'; fi;
    for dir in $@; do
        if [[ -d $dir ]]; then
            rm -f ${dir}/*~ $dir/#*#;
        else
            echo "clean: missing directory '${dir}'"
        fi
    done;
}

#-------- ls -F if directory, less if file --------
function li {
    if [[ -d $1 ]] ; then
         ls -F $1;
    elif [[ -f $1 ]] ; then
        less $1;
    else
        ls -F $1
    fi
}
Back to top
View user's profile Send private message
iKiddo
Guru
Guru


Joined: 27 Jun 2002
Posts: 329
Location: Europe?

PostPosted: Tue Mar 04, 2003 5:05 pm    Post subject: Reply with quote

carambola5 wrote:
While you're at it, grab fbgrab from portage too. It does the same thing as import, but only for the console (framebuffer).


Thanks, I figure the framebuffer should be enabled (kernel/USE/etc.) to use fbgrab? (I don't have them enabled, had some bug switching between X and VCs.)
Back to top
View user's profile Send private message
jleidigh
n00b
n00b


Joined: 19 Apr 2002
Posts: 2

PostPosted: Wed Apr 09, 2003 8:24 am    Post subject: What about CTRL-R Reply with quote

Use CTRL-R for reverse text matching search against history, better than seeing all the output of history if you have an idea of the command previously executed but are unsure of the syntax and definitly better than using the up arrow
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, ... 13, 14, 15  Next
Page 2 of 15

 
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