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

Install pip with Proxy
Installs pip packages defining a proxy

Multi-thread any command
For instance: $ find . -type f -name '*.wav' -print0 |xargs -0 -P 3 -n 1 flac -V8 will encode all .wav files into FLAC in parallel. Explanation of xargs flags: -P [max-procs]: Max number of invocations to run at once. Set to 0 to run all at once [potentially dangerous re: excessive RAM usage]. -n [max-args]: Max number of arguments from the list to send to each invocation. -0: Stdin is a null-terminated list. I use xargs to build parallel-processing frameworks into my scripts like the one here: http://pastebin.com/1GvcifYa

Create a video that is supported by youtube
Takes an mpeg video and coverts it to a youtube compatible flv file. The -r 25 sets the frame rate for PAL, for NTSC use 29.97

output absolute path of the present working directory
I've seen a lot of overly complicated attempts at figuring out "where am I?" I think this is a part of the problem: type -a pwd force the use of the binary version of `pwd` instead of the built-in with "/bin/pwd -P" -P option provides an absolute path to the present working directory for the overly cautious type: $(which pwd) -P

Display a list of all PHP classes that are called statically
Searches all .php files for a static instantiation of a class and displays the class names along with their frequencies.

Dump dvd from a different machine onto this one.
You can use this to directly dump from machine A (with dvd drive) to machine B (without dvd drive) . I used this to copy dvd using my friend's machine to my netbook. Above command is to be issued on machine B. Advantages : 1) No wasting time dumping first to machine A and then copying to Machine B. 2) You dont need to use space on Machine A. In fact, this will work even when Machine A doesnt have enough hdd space to dump the DVD. Use -C ssh option on slow networks (enables compression). you can replace "dd if=/dev/dvd" with any ripping command as long as it spews the iso to stdout.

Dump audio from video without re-encoding.
This removes the video and subsequent file size and directly copies the audio.

Connect-back shell using Bash built-ins
Connect-back shell using Bash built-ins. Useful in a web app penetration test, if it's the case of a locked down environment, without the need for file uploads or a writable directory. -- /dev/tcp and /dev/udb redirects must be enabled at compile time in Bash. Most Linux distros enable this feature by default but at least Debian is known to disable it. -- http://labs.neohapsis.com/2008/04/17/connect-back-shell-literally/

find the biggest files recursively, no matter how many
This command will find the biggest files recursively under a certain directory, no matter if they are too many. If you try the regular commands ("find -type f -exec ls -laSr {} +" or "find -type f -print0 | xargs -0 ls -laSr") the sorting won't be correct because of command line arguments limit. This command won't use command line arguments to sort the files and will display the sorted list correctly.

Install a basic FreeBSD system
Install a basic FreeBSD system on a distant server. I use this to install FreeBSD on servers that can only boot a Linux rescue system. This sytem loads on ram when booted, so it is possible to install freely. You can even install on ZFS root !


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: