All commands (14,187)

  • This doesn't make any assumptions about your IP address and prints out one IP address per line if you have multiple network interfaces. Show Sample Output


    -3
    ifconfig | sed '/.*addr.*Bcast.*/ ! d'| sed 's/.*addr:\([0-9\.]*\).*/\1/'
    Haegin · 2010-03-26 08:13:13 3
  • This assumes your local ip starts with 192.something (e.g. 192.168), it greps ifconfig output for an ip that starts with 192, then strips the extra garbage (besides the ip) Maybe `ifconfig | grep addr | grep Bcast` would also do it Show Sample Output


    -5
    ifconfig | grep addr:192 | sed s/Bcast.*// | sed 's/^.*inet addr://'
    hasenj · 2010-03-26 07:37:21 4
  • This is useful for examining the path. Show Sample Output


    6
    printf ${PATH//:/\\n}
    haivu · 2010-03-26 04:37:33 5
  • Okay, Jimmy, the command 'optical-monitor' is needed within the global config. for this command to work (and if supported by your licsense: yada yada, blah, blah). But, like its mad PHAT Kid, you dig? Basically, a Foundry/Brocade switch is reading the Laser light levels just like those Fiber test kits from Owl that cost 4k. I know, I also find it hard to contain myeself ;-) No really..... Show Sample Output


    -3
    show optic <slot #>
    rootgeek · 2010-03-26 03:07:22 3
  • You need all those commands, in the sample output. I had some of this, but had to play, add remove, type random stuff like a monkey to finally get this working (clearly those IP's are fake to protect the guilty, and so is the key). Show Sample Output


    -3
    aaa authentication login default local tacacs+
    rootgeek · 2010-03-26 02:58:03 3
  • This is how you make sure that ports in a VLAN remain, root ports. Typically, you would use this command on all your Core-1 switch VLAN ports, and then use 'rstp priority 1' on all your Core-2 switches. This is if you have a dual L3 core that is. Show Sample Output


    -3
    rstp priority 0
    rootgeek · 2010-03-26 02:51:54 3
  • 'no untag' is applied to _all_ ports under the default VLAN. Otherwise the default VLAN runs untagged over all physical ports. Pretty good idea to 'prune' your VLANs and define which ones pass over and across trunks that carry the default VLAN traffic. Show Sample Output


    -3
    no untag
    rootgeek · 2010-03-26 02:45:32 3
  • The sample output, is the command with a ?, to show you all the stuff you can look at. Show Sample Output


    -4
    dm ?
    rootgeek · 2010-03-26 02:42:21 3
  • The sample output, is a display of the values you can change, using this command. After a change of of these settings you will need to reload the box, by typing...wait...wait for IT: 'reload'. This comes in handy when working with the RX hardware, for example, which has a base limitation of 32 (RSTP (802-1w) instances. For all of you paying attention that means if you run RSTP on a RX you can only have 32 VLANs. Sure, you can have common groups of VLANs, like back in the day style MSTP, PVST, PVST+ (and all that old STP (802.1d) mess), before "per vlan spanning-tree", RSTP (802-1w), was made. But who wants to do all that? Show Sample Output


    -2
    system max <some value>
    rootgeek · 2010-03-26 02:39:00 5

  • -4
    sh default values
    rootgeek · 2010-03-26 02:36:57 4
  • Here "^M" is NOT "SHIFT+6" and "M". Type CTRL+V+M to get it instead. Its shortest and easy. And its sed!, which is available by default in all linux flavours.. no need to install extra tools like fromdos.


    4
    sed -i 's/^M//' file
    sata · 2010-03-25 19:34:08 7
  • This is easy to type if you are looking for a few (hundred) "missing" megabytes (and don't mind the occasional K slipping in)... A variation without false positives and also finding gigabytes (but - depending on your keyboard setup - more painful to type): du -hs *|grep -P '^(\d|,)+(M|G)'|sort -n (NOTE: you might want to replace the ',' according to your locale!) Don't forget that you can modify the globbing as needed! (e.g. '.[^\.]* *' to include hidden files and directories (w/ bash)) in its core similar to: http://www.commandlinefu.com/commands/view/706/show-sorted-list-of-files-with-sizes-more-than-1mb-in-the-current-dir Show Sample Output


    3
    du -hs *|grep M|sort -n
    tuxlifan · 2010-03-25 19:20:24 4
  • Finds all C++, Python, SWIG files in your present directory (uses "*" rather than "." to exclude invisibles) and counts how many lines are in them. Returns only the last line (the total). Show Sample Output


    2
    find * \( -name "*.[hc]pp" -or -name "*.py" -or -name "*.i" \) -print0 | xargs -0 wc -l | tail -n 1
    neologism · 2010-03-25 18:58:29 4

  • 2
    ls -d $(echo ${PATH//:/ }) > /dev/null
    ger · 2010-03-25 17:38:57 3
  • Using this command one can cut a piece from the end of an audio file.


    1
    sox input.wav output.wav reverse trim 00:00:00.3 reverse
    bodo · 2010-03-25 13:38:44 3

  • -2
    printf "%.50d" 0 | tr 0 -
    sata · 2010-03-25 12:52:45 3
  • essentially the ruby one, but perhaps has a larger installed base


    9
    python -c 'print "-"*50'
    funky · 2010-03-25 11:09:30 6
  • This feels more intuitive to me.


    1
    for i in `seq 1 1 50`; do echo -n -; done
    Gosha · 2010-03-25 10:22:19 3

  • 5
    svn log -r {`date +"%Y-%m-%d" -d "1 month ago"`}:HEAD|grep '^r[0-9]' |cut -d\| -f2|sort|uniq -c
    ivanatora · 2010-03-25 09:43:15 4
  • Get there by going backwards and forgetting the numbers.


    5
    seq -s" " -50 -1 | tr -dc -
    DoNotRememberMe · 2010-03-25 06:00:24 32
  • If you want to relocate a package on your own, or you just want to know what those PREIN/UN and POSTIN/UN scripts will do, this will dump out all that detail simply. You may want to expand the egrep out other verbose flags like CHANGELOGTEXT etc, as your needs require. It isn't clear, but the formatting around $tag is important: %{$tag} just prints out the first line, while [%{$tag }] iterates thru multi-line output, joining the lines with a space (yes, there's a space between the g and } characters. To break it out for all newlines, use [%{$tag\n}] but the output will be long. This is aside from rpm2cpio | cpio -ivd to extract the package files.


    0
    rpm --querytags | egrep -v HEADERIMMUTABLE | sort | while read tag ; do rpm -q --queryformat "$tag: [%{$tag} ]\n" -p $SomeRPMfile ; done
    DoNotRememberMe · 2010-03-25 05:40:48 3
  • The example is a little bit bogus, but applies to any command that takes a while interactively, or might be a bit of a drag on system resources. Once the command's output is saved to a variable, you can then echo "$OUTPUT" to see it in multi-line glory after that. The use of double-quotes around the backticks and during the variable expansion disables any IFS conversion during those two operations. Very useful for reporting that might pull different lines out, like from dmidecode, inq or any other disk detail command. The only caveat is that storing too much in a variable might make your shell process grow.


    0
    OUTPUT="`find / -type f`" ; echo "$OUTPUT" | grep sysrq ; echo "$OUTPUT" | grep sysctl ; echo "$OUTPUT" | less
    DoNotRememberMe · 2010-03-25 05:02:10 5
  • I had problems in Ubuntu while trying to edit /etc/resolv.conf, even with sudo I couldn't make any change. After a 2 minutes search on google I found this command. Hope someone finds it useful. It works like chmod, with + and - to denote which attributes are being added and which are being removed. See other attributes on man pages or on wikipedia http://en.wikipedia.org/wiki/Chattr


    1
    sudo chattr -i <file that cannot be modified>
    leovailati · 2010-03-25 03:14:34 4

  • 2
    aptitude search '~i!~E' | grep -v "i A" | cut -d " " -f 4
    XORwell · 2010-03-25 00:40:51 6
  • Write a file you edited in Vim but that you do not have the permissions to write to (unless you use sudo.) Same as #1204 but without the echo to stdout that I find annoying.


    32
    :w !sudo tee > /dev/null %
    idemal · 2010-03-24 20:04:26 13
  • ‹ First  < 388 389 390 391 392 >  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

most used commands in history (comprehensive)
Most of the "most used commands" approaches does not consider pipes and other complexities. This approach considers pipes, process substitution by backticks or $() and multiple commands separated by ; Perl regular expression breaks up each line using | or < ( or ; or ` or $( and picks the first word (excluding "do" in case of for loops) note: if you are using lots of perl one-liners, the perl commands will be counted as well in this approach, since semicolon is used as a separator

check open ports without netstat or lsof

Move a folder and merge it with another folder
This will move a folder and merge it with another folder which may contain duplicates. Technically it's just creating hardlinks of everything in the folder, and after it's done, delete the source (with rm -r source/ ) to complete the move. This is much faster than, for example, using rsync to merge folders which would actually copy the entire contents and so for a lot of files would take much longer. This uses macutils gcp port of cp so it can be used on osx/MacOS. If using in linux or some unix where cp includes the ability to create links with -l you can just use cp instead of gcp.

download a list of urls

Find the package that installed a command

Generate a random password 30 characters long

Generate a random left-hand password
Generates a random 8-character password that can be typed using only the left hand on a QWERTY keyboard. Useful to avoid taking your hand off of the mouse, especially if your username is left-handed. Change the 8 to your length of choice, add or remove characters from the list based on your preferences or kezboard layout, etc.

vi a new file with execution mode
$ vix /tmp/script.sh Open a file directly with execution permission. Put the function in your .bashrc You can also put this in your vimrc: $ command XX w | set ar | silent exe "!chmod +x %" | redraw! and open a new file like this: $ vi +XX /tmp/script.sh

Extract tarball from internet without local saving

Swap a file or dir with quick resotre
This lets you replace a file or directory and quickly revert if something goes wrong. For example, the current version of a website's files are in public_html. Put a new version of the site in public_html~ and execute the command. The names are swapped. If anything goes wrong, execute it again (up arrow or !!).


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: