All commands (14,187)

  • I must monitorize a couple of ftp servers every morning WITHOUT a port-scanner Instead of ftp'ing on 100 ftp servers manually to test their status I use this loop. It might be adaptable to other services, however it may require a 'logout' string instead of 'quit'. The file ftps.txt contains the full list of ftp servers to monitorize.


    1
    for host in $(cat ftps.txt) ; do if echo -en "o $host 21\nquit\n" |telnet 2>/dev/null |grep -v 'Connected to' >/dev/null; then echo -en "FTP $host KO\n"; fi done
    vlan7 · 2010-01-26 15:34:18 3
  • Recursive grep through directory for file.


    -5
    find directory/ |xargs grep -i "phrase"
    tuxtutorials · 2010-01-26 14:56:56 3
  • no loop, only one call of grep, scrollable ("less is more", more or less...)


    12
    ls /usr/bin | xargs whatis | grep -v nothing | less
    michelsberg · 2010-01-26 12:59:47 32
  • Useful for Maven multimodule projects, where you want to extract all packaged jar files.


    -3
    find . -iname "*.jar" -exec cp '{}' /tmp/ \;
    unixmonkey6754 · 2010-01-26 12:19:15 3
  • This command has been used to overwrite corrupted "entries" files of a corrupted subversion working copy. Note the --files-from input format.


    3
    rsync -vd --files-from=<(find . -name entries -print ) . ../target_directory
    samyboy · 2010-01-26 09:41:12 6
  • This command toggles the touchpad on and off, when it's on, the right side scroll strip (annoying) and the tap-clicking are disabled, you can change this by changing occurances of 2 in the command to 0. this whole command can then be given a keyboard shortcut so that the touchpad is disableable without using a special fn key (which linux doesn't recognize on some computers) or a seperate button.


    -3
    if [ $(synclient -l | grep TouchpadOff | awk '{print $3}') = "2" ]; then synclient TouchpadOff=1; elif [ $(synclient -l | grep TouchpadOff | awk '{print $3}') == "1" ]; then synclient TouchpadOff=2; else synclient TouchpadOff=2; fi
    GinoMan2440 · 2010-01-26 07:52:55 5

  • 1
    find . -maxdepth 1 -type d -exec 'mv "{}" "{}-old" && svnadmin create "{}" && svnadmin recover "{}-old" && svnadmin dump "{}-old" | svnadmin load "{}" && rm -rf "{}-old"' \;
    raspi · 2010-01-26 07:06:43 3

  • 7
    for i in $(ls /usr/bin); do whatis $i | grep -v nothing; done | more
    Abiden · 2010-01-26 06:15:54 7

  • -2
    7za x \*.zip
    andrew112358 · 2010-01-25 21:50:15 2
  • Traditionally we rewind a tape using this syntaxis: mt -f /dev/rmt/0cbn rewind Redirecting the dispositive to nothing as shown above is faster. Less typing is always better.


    2
    < /dev/rmt/0cbn
    vlan7 · 2010-01-25 20:32:38 3

  • -1
    find . -maxdepth 1 -type f| xargs sha1sum | sed 's/^\(\w*\)\s*\(.*\)/\2 \1/' | while read LINE; do mv $LINE; done
    foremire · 2010-01-25 20:21:01 11
  • for example if you did a: ls -la /bin/ls then ls !$ is equivalent to doing a ls /bin/ls


    9
    !$
    ringlerun · 2010-01-24 17:59:52 23
  • running top command in batch mode. it is usefull if you want to redirect the output in a file. Show Sample Output


    2
    top -b -n 1
    r00t4u · 2010-01-24 16:17:30 5

  • 0
    dpkg -l | grep ^rc | awk '{print $2}' | sudo xargs dpkg -P
    kayowas · 2010-01-24 14:23:37 4
  • Use find's built-in ability to call programs. Alternatively, find -maxdepth 1 -type f -name "*.7z" -print0 | xargx -0 -n 1 7zr e would work, too.


    -1
    find -maxdepth 1 -type f -name "*.7z" -exec 7zr e '{}' ';'
    minnmass · 2010-01-23 19:50:10 4

  • 0
    find . -type f -exec stat \{\} \; | grep Modify: | awk '{a[$2]++}END{for(i in a){print i " : " a[i] }}' | sort
    pepin · 2010-01-23 07:55:16 6
  • Restores the keyboard so your partner who expects the keys to correspond to what they're labelled can type (in qwerty).


    -2
    setxkbmap us
    keturn · 2010-01-23 04:08:46 4
  • What to type to fix the keyboard when it's all qwerty and/or the modifier key to the left of the 'a' is doing something unexpected. In addition, I've also been known to use the altwin:meta_win and compose:ralt flags.


    0
    setxkbmap dvorak '' ctrl:nocaps
    keturn · 2010-01-23 04:04:59 3
  • A command to post a message to Twitter that includes your geo-location and a short URL. The link shortening service is provide by TinyURL, the geo-location service is provided by HostIP and the IP address lookup service is provided by AppSpot. This is an upgrade of an of one of my previous contributions: http://tinyurl.com/yd2xtzv.


    4
    curl --user "USERNAME:PASSWORD" -d status="MESSAGE_GOES_HERE $(curl -s tinyurl.com/api-create.php?url=URL_GOES_HERE) $(curl -s api.hostip.info/get_html.php?ip=$(curl ip.appspot.com))" -d source="cURL" twitter.com/statuses/update.json -o /dev/null
    o0110o · 2010-01-23 02:21:57 11

  • -7
    scp /home/svnlabs.txt root@92.178.0.56:/home/
    bakhru · 2010-01-22 21:19:37 5

  • 10
    nmap -T4 -sP 192.168.2.0/24 && egrep "00:00:00:00:00:00" /proc/net/arp
    wincus · 2010-01-22 20:36:43 8

  • 3
    for file in *.7z; do 7zr e "$file"; done
    jmcantrell · 2010-01-22 18:42:20 11
  • Connect EC2 server with public keys "/root/.ec2/id_rsa-gsg-keypair" or "/root/.ec2/keypair.pem"


    -2
    rsync -avvvz -e "ssh -i /root/.ec2/id_rsa-gsg-keypair" --archive --progress /root/.ec2/id_rsa-gsg-keypair root@ec2-75-101-212-113.compute-1.amazonaws.com:/root
    lalit241 · 2010-01-22 17:21:58 3
  • Upload file to remote server using SCP


    -9
    scp -P 22 /home/svnlabs.txt root@92.178.0.56:/home/svnlabs.txt
    lalit241 · 2010-01-22 17:21:07 3
  • Upload file to remote server using SCP


    -6
    scp -P 22 /home/svnlabs.txt root@92.178.0.56:/home/svnlabs.txt
    svnlabs · 2010-01-22 16:55:25 4
  • ‹ First  < 406 407 408 409 410 >  Last ›

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands


Check These Out

Find usb device
I often use it to find recently added ou removed device, or using find in /dev, or anything similar. Just run the command, plug the device, and wait to see him and only him

Find usb device in realtime
Using this command you can track a moment when usb device was attached.

Convert all WMF images to SVG recursively ignoring file extension case
This assumes you have the package installed necessary for converting WMF files. On my Ubuntu box, this is libwmf-bin. I used this command, as libwmf is not on my wife's iMac, so I archived the directories containing the WMF files from OS X, ran them on my Ubuntu box, archived the resulting SVGs, and sent them back to her. Quick, simple and to the point. Searches directories recursively looking for extensions ignoring case. This is much more readable and clean than -exec for find. The while loop also gives further flexibility on complex logic. Also, although there is 'wmf2svg --auto', it expects lowercase extensions, and not uppercase. Because I want to ignore case, I need to use the -o option instead. Works in ZSH and BASH. Haven't tested in other shells.

Find out current working directory of a process
This is an alternative to another command using two xargs. If it's a command you know there's only one of, you can just use: $ ls -l /proc/$(pgrep COMMAND)/cwd

Capture data in ASCII. 1500 bytes
Sniffing traffic on port 80 only the first 1500 bytes

Update all packages installed via homebrew
As of March 7, 2012: $ brew update - downloads upgraded formulas $ brew upgrade [FORMULA...] - upgrades the specified formulas $ brew outdated - lists outdated installations Note updating all packages may take an excruciatingly long time. You might consider a discriminating approach: run `brew outdated` and select specific packages needing an upgrade. For more information see homebrew's git repository: https://github.com/mxcl/homebrew

dont log current session to history

Find the package that installed a command

GREP a PDF file.
PDF files are simultaneously wonderful and heinous. They are wonderful in being ubiquitous and mostly being cross platform. They are heinous in being very difficult to work with from the command line, search, grep, use only the text inside the PDF, or use outside of proprietary products. xpdf is a wonderful set of PDF tools. It is on many linux distros and can be installed on OS X. While primarily an open PDF viewer for X, xpdf has the tool "pdftotext" that can extract formated or unformatted text from inside a PDF that has text. This text stream can then be further processed by grep or other tool. The '-' after the file name directs output to stdout rather than to a text file the same name as the PDF. Make sure you use version 3.02 of pdftotext or later; earlier versions clipped lines. The lines extracted from a PDF without the "-layout" option are very long. More paragraphs. Use just to test that a pattern exists in the file. With "-layout" the output resembles the lines, but it is not perfect. xpdf is available open source at http://www.foolabs.com/xpdf/

Generic shell function for modifying files in-place
Some commands (such as sed and perl) have options to support in-place editing of files, but many commands do not. This shell function enables any command to change files in place. See the sample output for many examples. The function uses plain sh syntax and works with any POSIX shell or derivative, including zsh and bash.


Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: