Find the answer to your Linux question:
Results 1 to 8 of 8
Like Tree4Likes
  • 1 Post By atreyu
  • 1 Post By elija
  • 1 Post By Lakshmipathi
  • 1 Post By awc
So my new favorite command is watch Code: $ man watch NAME watch - execute a program periodically, showing output fullscreen SYNOPSIS watch [-bdehpvtx] [-n seconds] [--beep] [--color] [--differences[=cumulative]] [--errexit] ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    awc
    awc is offline
    Just Joined! awc's Avatar
    Join Date
    Aug 2012
    Location
    North America
    Posts
    40

    Favorite command?


    So my new favorite command is watch

    Code:
    $ man watch
    NAME
           watch - execute a program periodically, showing output fullscreen
    
    SYNOPSIS
           watch [-bdehpvtx] [-n seconds] [--beep] [--color] [--differences[=cumulative]] [--errexit] [--exec] [--help] [--interval=seconds] [--no-title] [--precise] [--ver‐
           sion] command
    Quite a few programs have the ability to continuously update output, but it usually takes over the screen and gets messy.

    However, watch clears the screen, keeps the output in one place AND displays the current time, among other things.

    Code:
     $ watch -n 1 netstat -tuan
    vs

    Code:
     $ netstat -tuanc 1

  2. #2
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    yeah, love watch. sometimes it doesn't like my complicated commands that i want to watch, so i often do:

    Code:
    while :; do clear;date;command 1;command 2|command 3;blah;usleep 500000;done
    which will run all those commands twice a second. seems like overkill, but sometimes you need that granularity!

    as to my current favorite command, i have to go with !command. for example, if the below ssh command is in my bash history:

    Code:
    ssh -Y user@remove_server1
    then i can just type:
    Code:
    !ssh
    and history will grab the most recently run ssh command and run it for me. a serious time saver...
    jayd512 likes this.

  3. #3
    Penguin of trust elija's Avatar
    Join Date
    Jul 2004
    Location
    Either at home or at work or down the pub
    Posts
    3,488
    !! is probably my current favourite. It re-runs the previous command. Usually it goes like this:
    Code:
    some long command with lots of parameters
    ERROR: permission denied
    sudo !!
    jayd512 likes this.
    What do we want?
    Time machines!

    When do we want 'em?
    Doesn't really matter does it!?


    Conkybots: Interactive plugins for your Conkys!

  4. #4
    Linux Guru Lakshmipathi's Avatar
    Join Date
    Sep 2006
    Location
    3rd rock from sun - Often seen near moon
    Posts
    1,757
    I like this: Sometimes you want to copy some command from 'history' command's output and modify it and re-run them

    For example,if history has following output:
    Code:
      778  cat /etc/sudoers
      779  vim /etc/sudoers
      780  ls
      781  cat fabfile.py
      782 vim /etc/sudoers
       783 ls
    to change 'filename' in cat command do :
    Code:
    !781:p
    Now press up-arrow , go and edit the command
    elija likes this.
    First they ignore you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
    -----
    FOSS India Award winning ext3fs Undelete tool www.giis.co.in. Online Linux Terminal http://www.webminal.org

  5. #5
    Administrator jayd512's Avatar
    Join Date
    Feb 2008
    Location
    Kentucky
    Posts
    5,023
    atreyu and elija... you both just introduced me to some sweet little tricks!
    That's why I love the Linux Community!
    Jay

    New users, read this first.
    New Member FAQ
    Registered Linux User #463940
    I do not respond to private messages asking for Linux help. Please keep it on the public boards.

  6. #6
    awc
    awc is offline
    Just Joined! awc's Avatar
    Join Date
    Aug 2012
    Location
    North America
    Posts
    40
    Another good command line trick is to use !$ to reuse the last argument from the previous command

    Code:
    $ ping foo.bar
    $ nmap !$
    nmap foo.bar
    elija likes this.

  7. #7
    Linux Newbie
    Join Date
    Jun 2012
    Location
    SF Bay area
    Posts
    151
    OK, this isn't really a command line exactly, but it's one of my favorite features about command line customization in bash.

    Say you have a complicate command you want to use a couple times, sort of a "mini script", but you don't think you'll want it forever and don't want to create an actual script. Maybe something like to print an IP address and it's associated hostname.

    Code:
    echo "199.59.148.10 $(dig -x 199.59.148.10 | gawk '/PTR/ && $NF != "PTR" { print $NF; exit; }')"
    You can just recall the command with (^P in emacs mode, something else in VI mode), then edit it to make it a shell function by tweaking it to look like this.

    Code:
    REV() { echo "$1 $(dig -x $1 | gawk '/PTR/ && $NF != "PTR" { print $NF; exit; }')"; }
    You basically added a "name() {" at the front, insert the commands you want run, then end with "; }". You can also convert things you want to pass in to arguments, just like any other shell script. In this case, the IP address is passed in.

    Then you can just type things like,

    Code:
    $ REV 199.59.148.10
    199.59.148.10 r-199-59-148-10.twttr.com.
    If you decide you want that function around all the time, you can enter the same "REV() { ...}" line into your ".bash_profile" and you'll have in memory commands that run scripts as if they were on disk.

  8. #8
    Just Joined!
    Join Date
    Oct 2012
    Location
    Fort Worth, Texas
    Posts
    8
    Weekly back-up of my work flash-drive on a Debian-based machine;
    Code:
    cp -auv //media/flash_drive/work/ Backup/
    Results in everything saved in Backup/work/. If stuff is already living there, only new or changed files are copied over.
    Code:
    tar -cvf Backup/Work20121101.tar Backup/Work/
    Creates a tar-ball of Work I can save someplace else.
    It's paranoid, I know, but it's also my data...
    Last edited by merelyjim; 11-01-2012 at 05:54 AM. Reason: Ooops. Typo!

Posting Permissions

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