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 ... 8, 9, 10 ... 14, 15, 16  Next  
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
oberyno
Guru
Guru


Joined: 15 Feb 2004
Posts: 467
Location: /bin/zsh

PostPosted: Sun Sep 12, 2004 4:23 pm    Post subject: Reply with quote

About the whole {1..156}, what if numbers need to be generated like this: 001, 002,...056, 057,...156? This is still a pain with bash, but in zsh you can just use {001..156}.

Anyway, here's a few of my aliases.
Code:
alias psgrep="ps aux | grep -v 'grep --color=auto -e %MEM' | grep -e %MEM -e"
alias -- +='pushd +0'
alias -- -='pushd -1'
alias dirs="dirs -v"
alias zcalc="autoload -U zcalc; zcalc"
The first one gives an easy way to find out about a certain process. Edit: It also assumes that you have an alias for grep with --color=auto. The next three aid in quickly navigating the directory stack. I love being able to type dirs, get something like this:
Code:
oberyno % dirs                                                                                                           /usr/portage/sys-devel/gcc
0   /usr/portage/sys-devel/gcc
1   /usr/local/portage/games-strategy/wesnoth-cvs
2   ~
3   /usr/portage
4   ~dot-files
5   /var
And then just be able to type ~3<enter> to go to /usr/portage or - to go to the previous directory. Afaik, for ~3 to work, you also need auto_cd, cdable_vars, auto_pushd, and maybe some other options in your zshrc.

Another zsh feature that I like is completion within archives.
Code:
tar xzvf xterm-tranz.tar.gz <tab>
I generally use this when I only want one or two files in an archive.

My zshrc (based on slarti]'s) is here. Probably the main difference is that I modified some of ciaranm's functions to be more zshish, i.e., useexplain completes useflags, ecd completes packages and so on.
Back to top
View user's profile Send private message
Pyrates
Tux's lil' helper
Tux's lil' helper


Joined: 29 Apr 2004
Posts: 93

PostPosted: Wed Sep 15, 2004 12:21 pm    Post subject: Reply with quote

Sometimes, you login on a console (e.g. if you use ssh), but you are interrupted for some reason. Can't remember how much of the password you typed, and don't know if Backspace works? Try Ctr-u, works on many flavors of unix and clears the password, so you can retype...

Cheers
Philipp
_________________
" ... and the Vogon will do things to you that you wish you'd never been born, or, if you're a clearer minded thinker, that the Vogon had never been born."
Back to top
View user's profile Send private message
ahubu
Guru
Guru


Joined: 16 Aug 2003
Posts: 400
Location: Groningen, The Netherlands

PostPosted: Wed Sep 15, 2004 12:29 pm    Post subject: Reply with quote

Holy smoke, this thread kicks serious ass. Thanks guys for your incredible commands, I have a few I made myself:

Code:

alias fatso='du --max-depth=1 -m . |sort -rnk 1'
alias fatboys='find . -xdev -size +1024 -ls | sort -rnk 7 |head -n 20'
alias vl='clear&&vlock'
alias vla='clear&&vlock -a'
alias ontv='DISPLAY=:0.1'
alias gqcam='gqcam -v /dev/video1'
alias xlock="xscreensaver-command -lock"


The first 2 are for finding big files on your system.

I saw somewhere:

alias -g L='|less'

this gives me problems, bash wont parse em, doesn't recognize -g switch. I'll have to look into that, because I like the effect.[/quote]
Back to top
View user's profile Send private message
xmoy
Tux's lil' helper
Tux's lil' helper


Joined: 03 Aug 2004
Posts: 108
Location: .ch

PostPosted: Wed Sep 15, 2004 9:22 pm    Post subject: Reply with quote

Code:
alias tgz="tar -xvzpf"


If you use different kernels, this would be nice (in your /etc/conf.d/local.start):
Code:
ln -sf /usr/src/linux-$(uname -r) /usr/src/linux


And, as a result of being bored (local.start):
Code:
new_hostname=$(random_word.py 5)
echo "   setting hostname from $(hostname) to ${new_hostname}"
hostname $new_hostname
echo $new_hostname > /etc/hostname
echo "127.0.0.1 localhost ${new_hostname}" > /etc/hosts


the script random_word.py:
Code:
#!/usr/bin/python
import random
import string
import sys

def getchars():
    chars = []
    for char in string.ascii_lowercase:
        chars.append(char)
    return chars

def random_nmbr():
    chars = getchars()
    return int(random.random() * (len(chars) - 1))

def random_char(nmbr):
    chars = getchars()
    return chars[nmbr]

def random_word(length):
    word = ""
    for i in range(length):
        word = word + random_char(random_nmbr())
    return word

def main():
    try:
        length = int(sys.argv[1])
    except:
        sys.stderr.write("Usage:\n")
        sys.stderr.write("%s <length>\n" % (sys.argv[0]))
        sys.exit(0)
    print random_word(length)

main()


:wink:
_________________
:wq
Back to top
View user's profile Send private message
lynxnyl
Apprentice
Apprentice


Joined: 15 Aug 2004
Posts: 253
Location: Ljubljana, Slovenija

PostPosted: Thu Sep 16, 2004 1:57 pm    Post subject: Reply with quote

______________________
< Very nice thread! :) >
----------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||


I don't have any really special aliases or they've been mentioned before.
The most fun in ~/.bashrc is
Code:
cowsay -W 60 `fortune -a`

meatgrinded above :(

But I do have a neat script bound to my MM search button. :) It fires up a kosole, asks for params and emerge searches for them. Plus a prompt at the end if i like what i find. :)
Back to top
View user's profile Send private message
brain salad surgery
Apprentice
Apprentice


Joined: 21 Apr 2004
Posts: 216

PostPosted: Thu Sep 23, 2004 7:39 pm    Post subject: r u suing a lot ?? Reply with quote

i never log in root ...
but i do need root access a lot...



using su doesn't encrypt the password.

using ssh (dsa protocol) you don't even have to type the
passwd (and there is encryption)
but: 1- it brings you back to root's home
2- does not always read root's .bashrc
(had to put something in /etc/profile)

what would be interesting is to log in root
using ssh, without typing any passwd and
keeping the current directory and
the current history of the user...

here's how i do:

1- i put this function in my .bashrc:

function sup
{
# fonction pour se logger en root
echo $USER > /home/programs/.autre_user
echo $PWD >/home/n/.repertoire_root
history -a
ssh 127.0.0.1 -l root
}

and in root's .bashrc, i specify:

AUTRE_USER=$( cat /home/programs/.autre_user )
HISTFILE=/home/$AUTRE_USER/.bash_history



2- i put this in /etc/profile

if [ `/usr/bin/whoami` = 'root' ]
then
if [ $( ps aux | grep -c "ssh 127.0.0.1 -l root" ) -gt 0 ] ; then
REP=$( cat /home/n/.repertoire_root )
cd $REP
source /root/.bashrc
fi
fi



therefore, typing sup usually saves me a lot efforts !
any security issue anyone ??
Back to top
View user's profile Send private message
mattt416
n00b
n00b


Joined: 24 Sep 2004
Posts: 14

PostPosted: Fri Sep 24, 2004 12:34 am    Post subject: Reply with quote

although you can use the watch command, here's another way to keep a "real-time" monitor on things:

# while sleep 5; do clear; echo -n "Messages in queue: "; find /var/spool/mqueue -type f | wc -l; done
Back to top
View user's profile Send private message
perseguidor
Apprentice
Apprentice


Joined: 01 Aug 2004
Posts: 278
Location: West Kingdom of Buenos Aires

PostPosted: Fri Sep 24, 2004 11:15 pm    Post subject: Reply with quote

Keffin wrote:
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.


Perhaps you could also find this helpful:

(from man chmod)

Code:

(...) execute only if the file is a directory or already has execute permission for some user (X)


...so using X instead of x when using chmod like 'chmod -R a+x' could do the trick.
_________________
O make me a mask!
Back to top
View user's profile Send private message
electrofreak
l33t
l33t


Joined: 30 Jun 2004
Posts: 713
Location: Ohio, USA

PostPosted: Sat Sep 25, 2004 12:51 am    Post subject: Reply with quote

steveb wrote:
this one starts manny bash prcesses and you can watch the cpu going crazy:
Code:
:(){ :|:&};:


cheers

SteveB


btw: don't do it if you are not fast enought to do an killall bash!


Wow, um.... thats an instant killer if I've ever seen one... I was watching 'top' and...the second I ran it, I suddenly saw the load instantly jump to 187+ then the system was as good as done. :(

Great shit though! I could use that in the future!
_________________
Desktop: ABit AN8, Athlon64 X2 4400+ 939 2.75GHz, 2x1GB Corsair XMS DDR400, 2x160GB SATA RAID-0, 2x20"W, Vista Ultimate x64
Laptop: 15.4" MacBook Pro 2.4Ghz, 2x1GB RAM, 160GB, Mac OS X 10.5.1
Server: PIII 550Mhz, 3x128MB RAM, 160GB, Ubuntu Server 7.10
Back to top
View user's profile Send private message
Tsonn
Guru
Guru


Joined: 03 Jun 2004
Posts: 550

PostPosted: Sat Sep 25, 2004 2:15 am    Post subject: Reply with quote

Thanks for bash-completion :-)

Let's see... a handy one-liner, to play a random mp3 file:

mpg321 "$(find . -name \*.mp3 | head -n$(($RANDOM % $(find . -name \*.mp3 | wc -l))) | tail -n1)"

Change 'find .' to the path where your mp3s live, or it'll search under the current directory. Or change it to 'locate -r .mp3\$' to select from your entire PC. Replace mpg321 with your player of choice, of course...
_________________
If your question was answered, please edit the first post and add [SOLVED] to the title. Thanks!
Back to top
View user's profile Send private message
wilho
Apprentice
Apprentice


Joined: 22 Jul 2002
Posts: 169

PostPosted: Sat Sep 25, 2004 5:37 pm    Post subject: Reply with quote

steveb wrote:
this one starts manny bash prcesses and you can watch the cpu going crazy:
Code:
:(){ :|:&};:


Thank you for a heart attack. Really. Man, my pants are still wet. I did this and I didn't kill bashes quick enough, so I had to do reset. Well OK that's fine, but then before entering to grub menu started this GRUB GRUB GRUB GRUB... stuff on my screen. After reset bios doesn't understand the disk at all, chs 0 0 0. OK, I'm having my laptop in repair ATM because of hd fail, and there's all my backups on this box. Losing all would be a Very Bad Thing Indeed (tm).

Then I booted with knoppix, and suddenly everything seems ok again. Disks are readeble. It even booted fine, running fine, s.m.a.r.t says everything is fine... What a relief! I'm one big smile right now :lol:

Weird...
Back to top
View user's profile Send private message
mattt416
n00b
n00b


Joined: 24 Sep 2004
Posts: 14

PostPosted: Sat Sep 25, 2004 6:23 pm    Post subject: Reply with quote

perseguidor wrote:
Keffin wrote:
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.


Perhaps you could also find this helpful:

(from man chmod)

Code:

(...) execute only if the file is a directory or already has execute permission for some user (X)


...so using X instead of x when using chmod like 'chmod -R a+x' could do the trick.


or ...

find . -type f -exec chmod 444 {} \;
Back to top
View user's profile Send private message
hardcore
l33t
l33t


Joined: 01 Nov 2003
Posts: 626
Location: MSU, MI

PostPosted: Sat Sep 25, 2004 9:19 pm    Post subject: Reply with quote

wilho wrote:
steveb wrote:
this one starts manny bash prcesses and you can watch the cpu going crazy:
Code:
:(){ :|:&};:


Thank you for a heart attack. Really. Man, my pants are still wet. I did this and I didn't kill bashes quick enough, so I had to do reset. Well OK that's fine, but then before entering to grub menu started this GRUB GRUB GRUB GRUB... stuff on my screen. After reset bios doesn't understand the disk at all, chs 0 0 0. OK, I'm having my laptop in repair ATM because of hd fail, and there's all my backups on this box. Losing all would be a Very Bad Thing Indeed (tm).

Then I booted with knoppix, and suddenly everything seems ok again. Disks are readeble. It even booted fine, running fine, s.m.a.r.t says everything is fine... What a relief! I'm one big smile right now :lol:

Weird...


You may want to checkout editing /etc/limits before you do something like that again.
_________________
Nothing can stop me now, cuz I just don't care.
Back to top
View user's profile Send private message
PLum
Tux's lil' helper
Tux's lil' helper


Joined: 20 May 2004
Posts: 107
Location: /dev/world/poland/gliwice

PostPosted: Sun Sep 26, 2004 3:54 pm    Post subject: Reply with quote

okey, but how to set that limits ?

i try some configuration found on google
but then using system was not fun ...
what ever i try to run - there was "fork unavaliable ..."
and thats it ... :|
_________________
"Zlota zasada nauki i sztuki: Kto ma zloto ustala zasady."
Back to top
View user's profile Send private message
kamagurka
Veteran
Veteran


Joined: 25 Jan 2004
Posts: 1026
Location: /germany/munich

PostPosted: Tue Sep 28, 2004 5:58 pm    Post subject: Reply with quote

my best bash trick was installing zsh.
_________________
If you loved me, you'd all kill yourselves today.
--Spider Jerusalem, the Word
Back to top
View user's profile Send private message
nerdbert
l33t
l33t


Joined: 09 Feb 2003
Posts: 981
Location: Berlin

PostPosted: Fri Oct 08, 2004 9:36 am    Post subject: Reply with quote

regeya wrote:

For giggles, I just tried it on a Panther (MacOS X 10.3) box. It tied up the CPU for all of 3 seconds. :D


OSX has lower limits on processes a user can run. If you are fed up with 1337 friends logging into your box running :(){ :|:&};: you might consider setting "ulimit -u" to a lower value.


And btw: If anyone is still wondering what it really does look at it this way:

Code:
:()
{
  :|: &
}
:


That's the best explanation I ever found.
_________________
I'm really wondering what Lovechild is doing nowadays...
Back to top
View user's profile Send private message
Lord_Firlionel
Tux's lil' helper
Tux's lil' helper


Joined: 24 Apr 2004
Posts: 147
Location: /germany/hamburg

PostPosted: Sun Oct 10, 2004 3:55 pm    Post subject: Reply with quote

I'm having a directory with pictures in it. Some of them end with .JPG, the others with .jpg. How do I get all pictures ending in .jpg? I tried some things but didn't figure it out.

Edit: If it's easier it would be nice to have small letters all the way through, though.
_________________
LFS ID: 14252
Back to top
View user's profile Send private message
ciaranm
Retired Dev
Retired Dev


Joined: 19 Jul 2003
Posts: 1719
Location: In Hiding

PostPosted: Sun Oct 10, 2004 5:07 pm    Post subject: Reply with quote

ph34r my bashrc :twisted: :twisted: :twisted:
Back to top
View user's profile Send private message
Wi1d
Apprentice
Apprentice


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

PostPosted: Sun Oct 10, 2004 5:08 pm    Post subject: Reply with quote

Quote:
I'm having a directory with pictures in it. Some of them end with .JPG, the others with .jpg. How do I get all pictures ending in .jpg? I tried some things but didn't figure it out.

Edit: If it's easier it would be nice to have small letters all the way through, though.

For in is one of my favorite loops. Try this:
Code:
for i in *.JPG; do mv "$i" "`basename "$i" .JPG`.jpg"; done
Back to top
View user's profile Send private message
ciaranm
Retired Dev
Retired Dev


Joined: 19 Jul 2003
Posts: 1719
Location: In Hiding

PostPosted: Sun Oct 10, 2004 5:17 pm    Post subject: Reply with quote

Wi1d wrote:
Quote:
I'm having a directory with pictures in it. Some of them end with .JPG, the others with .jpg. How do I get all pictures ending in .jpg? I tried some things but didn't figure it out.

Edit: If it's easier it would be nice to have small letters all the way through, though.

For in is one of my favorite loops. Try this:
Code:
for i in *.JPG; do mv "$i" "`basename "$i" .JPG`.jpg"; done

Code:

rename .JPG .jpg *.JPG
for i in *.JPG ; do mv "$i" "${i%.JPG}.jpg" ; done
find -name '*.JPG' | while read i ; do mv "$i" "${i%.JPG}.jpg" ; done
Back to top
View user's profile Send private message
Deranger
Veteran
Veteran


Joined: 26 Aug 2004
Posts: 1215

PostPosted: Sun Oct 10, 2004 5:31 pm    Post subject: Reply with quote

ciaranm wrote:
ph34r my bashrc :twisted: :twisted: :twisted:

Man, that's sick! :D
Back to top
View user's profile Send private message
Lord_Firlionel
Tux's lil' helper
Tux's lil' helper


Joined: 24 Apr 2004
Posts: 147
Location: /germany/hamburg

PostPosted: Sun Oct 10, 2004 6:04 pm    Post subject: Reply with quote

Thanks to both!
_________________
LFS ID: 14252
Back to top
View user's profile Send private message
Tsonn
Guru
Guru


Joined: 03 Jun 2004
Posts: 550

PostPosted: Sun Oct 10, 2004 7:56 pm    Post subject: Reply with quote

If you want a whole variable made lowercase, the quickest way I've found is to run it through tr:

Code:

echo "fooBAR" | tr '[A-Z]' '[a-z]'


So, you could do something like:

Code:

for i in *; do j=$(echo $i | tr '[A-Z]' '[a-z]'); mv "$i" "$j"; done

_________________
If your question was answered, please edit the first post and add [SOLVED] to the title. Thanks!
Back to top
View user's profile Send private message
quirx
n00b
n00b


Joined: 27 Jul 2003
Posts: 14

PostPosted: Fri Oct 29, 2004 10:56 pm    Post subject: Reply with quote

I think it wasn't mentioned before:
hitting Alt+. gives you the argument of your previous command...
Back to top
View user's profile Send private message
Hauser
l33t
l33t


Joined: 27 Dec 2003
Posts: 650
Location: 4-dimensional hyperplane

PostPosted: Sun Oct 31, 2004 2:45 pm    Post subject: Reply with quote

Pyrates wrote:
Sometimes, you login on a console (e.g. if you use ssh), but you are interrupted for some reason. Can't remember how much of the password you typed, and don't know if Backspace works? Try Ctr-u, works on many flavors of unix and clears the password, so you can retype...

This is also a good trick to use when you've typed a long command and then suddenly want to change to another command.

Here're my aliases:
Code:
alias d="ls --color"
alias ls="ls --color=auto"
alias ll="ls --color -lh"
alias mdvd="mplayer -aop list=volume,extrastereo:volume=120 dvd://"
alias mso="mplayer -aop list=volume:volume=120"
alias mcd="mplayer -aop list=volume:volume=120 cdda://"
alias mvcd="mplayer -aop list=volume:volume=120 vcd://"
alias nos="killall xcompmgr"
alias sha="xcompmgr -c &"
alias rm="rm -i"
alias cp="cp -i"
alias na="nano -w"
alias pg="ps aux | grep"

_________________
AMD Athlon XP 2600+; 512M RAM;
nVidia FX5700LE; Hitachi 120Gb
2.6.9-nitro4, reiser4, linux26-headers+nptl

Do I like to compile everything?
Positive definite!
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 ... 8, 9, 10 ... 14, 15, 16  Next
Page 9 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