Page 1 of 3 123 LastLast
Results 1 to 10 of 22

Thread: Little Known Linux commands

  1. #1
    Senior Member
    Join Date
    Nov 2002
    Posts
    339

    Little Known Linux commands

    I tried to get this topic off the ground on a couple other sites and it didn't quite grab, so let's see what you people have to say. I want this thread to be one that others can come to to find...well..just what the title is...little known linux commands. Do you have a easier way of doing something? Do you have a work around for a service? Have you found some way of stoppping something from happening that would otherwise take 10 lines in the console? Or vise versa. Whatever it is, share with us. I know you guys have some. With out further adue, here is my first one to share.


    Let's say you have to work on a nix system that doesn't have alot of rc.d scripts. Many daemons like to put scripts in "/var/run/". You'll prolly find something like "/var/run/sshd.pid". Other daemons may have similary named files there ie. daemonname.pid.
    Let's say you want to HUP sshd to have it re-read it's config (This will NOT kill your current connection) You can do something like this:

    kill -HUP `cat /var/run/sshd.pid`

    This results in sending the sshd process a HUP signal. The stuff between the backticks will be executed, so this is the equivlent of 'Cat'ing' the /var/run/sshd.pid file, reading the result (which is just the process id of the parent sshd process) and then typing "kill -HUP xxx".
    Now let's say you've got some daemon process that is just running away. It's spawning more and more processes and "service blah stop" is not doing anything for you. Here's a cute way to kill all of those processes with the "big hammer":

    ps -auxwww | grep "daemonname" | awk '{print $2}' | xargs kill -9


    That will seek out all processes running named "daemonname", awk is snatching the second column that has the pid number, and xargs passes that as an argument to the big hammer called "kill -9". Use that one wisely, or start with a "-1". You can match on anything in the ps output as well, such as a particular username. I use a lot of "w's" with ps in case the program is started with an insanely long path.Now note to self that using the -aux switch for ps will choke on a solaris system. Try using -efa for that.
    Don\'t be a bitch! Use Slackware.

  2. #2
    Senior Member
    Join Date
    Jun 2002
    Posts
    394
    ps -auxwww | grep "daemonname" | awk '{print $2}' | xargs kill -9
    i'd normally use killall instead of doing this sort of thing.
    Hmm...theres something a little peculiar here. Oh i see what it is! the sentence is talking about itself! do you see that? what do you mean? sentences can\'t talk! No, but they REFER to things, and this one refers directly-unambigeously-unmistakably-to the very sentence which it is!

  3. #3
    Just Another Geek
    Join Date
    Jul 2002
    Location
    Rotterdam, Netherlands
    Posts
    3,401
    Here's one I use regularly:

    Code:
    ssh username@remotehost tar -C /usr -cf - src | tar -C /usr -xvf -
    This will securely copy /usr/src from the remotehost to the host you're on.
    Oliver's Law:
    Experience is something you don't get until just after you need it.

  4. #4
    Leftie Linux Lover the_JinX's Avatar
    Join Date
    Nov 2001
    Location
    Beverwijk Netherlands
    Posts
    2,534
    Sirdice, what are the advantages of your way above

    Code:
    scp -rp username@remotehost:/usr/src .
    I myselve like to do multiline stuff, for example to unrar all .rar files in a folder, bash lets you enter it just the way shown, the >'s are the way bash is shoing you are still working on the ame line.. and abreviates it when you look at the bash command cahce..

    Code:
    for rar in *.rar
    >do
    >unrar x "$rar"
    >rm "$rar"
    >done
    this gets compressed to
    Code:
    for rar in *.rar; do unrar x "$rar"; rm "$rar"; done
    I think it's easier to enter it multiline, no need to worry about the ;'s

    it would be safer to check error code ( $? ) before the rm part, that would make it
    Code:
    for rar in *.rar
    > do
    > unrar x "$rar"
    > if [[ $? == 0 ]]
    > then
    > rm "$rar"
    > fi
    > done
    or
    Code:
    for rar in *.rar; do unrar x "$rar"; if [[ $? == 0 ]]; then rm "$rar"; fi; done
    ASCII stupid question, get a stupid ANSI.
    When in Russia, pet a PETSCII.

    Get your ass over to SLAYRadio the best station for C64 Remixes !

  5. #5
    Just Another Geek
    Join Date
    Jul 2002
    Location
    Rotterdam, Netherlands
    Posts
    3,401
    Originally posted here by the_JinX
    Sirdice, what are the advantages of your way above

    Code:
    scp -rp username@remotehost:/usr/src .
    Tar has more options. Things like exclude and such.. I also believe mine is faster..but i'm not sure.. I had some trouble once with scp, after that I used ssh+tar. Worked like a charm. I don't remember what exactly went wrong..

    A variation on the same theme:

    Code:
    ssh username@remotehost tar -C /usr -cf - src | gzip > src.tgz
    This will create a src.tgz from the remotehost's /usr/src. Great for remote backups.
    It also splits the load a bit, tar on remotehost and gzip on the localhost.

    Redirection rulez!
    Oliver's Law:
    Experience is something you don't get until just after you need it.

  6. #6
    Leftie Linux Lover the_JinX's Avatar
    Join Date
    Nov 2001
    Location
    Beverwijk Netherlands
    Posts
    2,534
    It sure does..

    a cool little oneliner to read last ten lines of logfiles in a "more natural" way
    Code:
    tac /var/log/messages | head -n 10
    I use it on loads of log files..
    ASCII stupid question, get a stupid ANSI.
    When in Russia, pet a PETSCII.

    Get your ass over to SLAYRadio the best station for C64 Remixes !

  7. #7
    Senior Member
    Join Date
    Nov 2002
    Posts
    339
    A good one for packing up a Gentoo installation should you happen to forget to emerge your system using the -b (create a binary package as well as compile and install source) flag to emerge.


    emerge sync ; emerge -up world

    for i in `qpkg -I -nc`
    do
    quickpkg $i
    done

    tar -cvf ~/portage-`date +%y%m%d`.tar /usr/portage


    This will make a binary package of every package you've compiled and installed. Using this instead of a tarfile from / allows you to reinstall any single package or even use them elsewhere on another system.
    Don\'t be a bitch! Use Slackware.

  8. #8
    Senior Member
    Join Date
    Dec 2004
    Posts
    107
    Hi all,

    I was wondering, me being a win user and all, if there's any way to display devices loaded on the system? Kind of like the equivalent of the hardware manager in win...

    Thanks all, and keep em coming.. this thread is really cool -- kudos to hatebreed.

    -ik
    Alright Brain, you don\'t like me, and I don\'t like you. But let\'s just do this, and I can get back to killing you with beer.
    -- Homer S.

  9. #9
    Senior Member
    Join Date
    Sep 2001
    Posts
    144
    jinx, have you heard of tail ??? tail -n N filename where N = number of lines you want to see..

  10. #10
    Senior Member
    Join Date
    Jun 2002
    Posts
    394
    Originally posted here by Iron-Kurton
    Hi all,

    I was wondering, me being a win user and all, if there's any way to display devices loaded on the system?

    -ik
    check out /proc or /sys. there are pseudo or virtual files in these directories. that is to say, the files don't exist, their content is created on the fly.

    Code:
    cat /proc/devices
    cat /proc/bus/usb/devices | less
    jinx, have you heard of tail ??? tail -n N filename where N = number of lines you want to see..
    tail puts the most recent entries at the bottom, the "more natural" way puts the newest entries at the top. tail -f is great for monitoring log files. it keeps the file open.
    Hmm...theres something a little peculiar here. Oh i see what it is! the sentence is talking about itself! do you see that? what do you mean? sentences can\'t talk! No, but they REFER to things, and this one refers directly-unambigeously-unmistakably-to the very sentence which it is!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •