All commands (14,187)

  • When browsing java source code (for example) it's really annoying having to type the first letter of the package when there is only one package in the subdir. man bash for more info about FIGNORE


    13
    export FIGNORE=.svn
    peter0081 · 2010-04-09 15:26:00 9
  • 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. Show Sample Output


    1
    inplace() { eval F=\"\$$#\"; "$@" > "$F".new && mv -f "$F".new "$F"; }
    inof · 2010-04-09 11:36:31 11

  • 3
    sudo dmidecode --type=processor | grep -i -A 1 charac
    bzaman · 2010-04-09 11:12:27 3
  • This command will return a full list of Error 404 pages in the given access log. The following variables have been given to awk Hostname ($2), ERROR Code ($9), Missing Item ($7), Referrer ($11) You can then send this into a file (>> /path/to/file), which you can open with OpenOffice as a CSV


    1
    sudo awk '($9 ~ /404/)' /var/log/httpd/www.domain-access_log | awk '{print $2,$9,$7,$11}' | sort | uniq -c
    ninjasys · 2010-04-09 10:31:50 6
  • This command modifies the preferences file of Firefox that is located in .mozilla/firefox/*.default/prefs.js. It edits the file with sed and the -i option. Then it searches the string "browser.startup.homepage", and the string next to it (second string). Finally, it replaces the second string with the new homepage, that is http://sliceoflinux.com in the example. It doesn't work if you haven't set any homepage.


    3
    sed -i 's|\("browser.startup.homepage",\) "\(.*\)"|\1 "http://sliceoflinux.com"|' .mozilla/firefox/*.default/prefs.js
    sliceoflinux · 2010-04-09 08:00:22 6
  • This will list your phone's filesystem with bitpim. (works on many LG, Samsung, and Sanyo) See http://www.bitpim.org/help/phones-featuressupported.htm for full list.


    0
    bitpim -p $PHONE_PORT ls
    matthewbauer · 2010-04-09 02:20:53 10
  • Run the alias command, then issue ps aux | head and resize your terminal window (putty/console/hyperterm/xterm/etc) then issue the same command and you'll understand. ${LINES:-`tput lines 2>/dev/null||echo -n 12`} Insructs the shell that if LINES is not set or null to use the output from `tput lines` ( ncurses based terminal access ) to get the number of lines in your terminal. But furthermore, in case that doesn't work either, it will default to using the deafault of 12 (-2 = 10). The default for HEAD is to output the first 10 lines, this alias changes the default to output the first x lines instead, where x is the number of lines currently displayed on your terminal - 2. The -2 is there so that the top line displayed is the command you ran that used HEAD, ie the prompt. Depending on whether your PS1 and/or PROMPT_COMMAND output more than 1 line (mine is 3) you will want to increase from -2. So with my prompt being the following, I need -7, or - 5 if I only want to display the commandline at the top. ( https://www.askapache.com/linux/bash-power-prompt/ ) 275MB/748MB [7995:7993 - 0:186] 06:26:49 Thu Apr 08 [askapache@n1-backbone5:/dev/pts/0 +1] ~ In most shells the LINES variable is created automatically at login and updated when the terminal is resized (28 linux, 23/20 others for SIGWINCH) to contain the number of vertical lines that can fit in your terminal window. Because the alias doesn't hard-code the current LINES but relys on the $LINES variable, this is a dynamic alias that will always work on a tty device. Show Sample Output


    27
    alias head='head -n $((${LINES:-`tput lines 2>/dev/null||echo -n 12`} - 2))'
    AskApache · 2010-04-08 22:37:06 14
  • Finds the top ten pages returning an http response code of 404 in an apache log.


    8
    awk '$9 == 404 {print $7}' access_log | uniq -c | sort -rn | head
    zlemini · 2010-04-08 21:40:53 7
  • Add permanent line numbers to a file without creating a temp file. The rm command deletes file10 while the nl command works on the open file descriptor of file10 which it outputs into a new file again named file10. The new file10 will now be numbered in the same directory with the same file name and content as before, but it will in fact be a new file, using (ls -i) to show its inode number will prove this.


    3
    { rm -f file10 && nl > file10; } < file10
    zlemini · 2010-04-08 21:08:23 8
  • Get a list of all the unique hostnames from the apache configuration files. Handy to see what sites are running on a server. A slightly shorter version.


    2
    cat /etc/apache2/sites-enabled/* | egrep 'ServerAlias|ServerName' | tr -s ' ' | sed 's/^\s//' | cut -d ' ' -f 2 | sed 's/www.//' | sort | uniq
    chronosMark · 2010-04-08 15:50:34 2
  • Several people have submitted commands to do this, but I think this is the simplest solution. It also happens to be the most portable one: It should work with any sh or csh derived shell under any UNIX-like OS. Oh by the way, with my German locale ($LC_TIME set appropriately) it prints "g" most of the time, and sometimes (on Wednesdays) it prints "h". It never prints "y". Show Sample Output


    3
    date +%A | tail -2c
    inof · 2010-04-08 15:14:06 6
  • you may create an alias also, which I did ;-) alias sshu="ssh -o UserKnownHostsFile=/dev/null "


    9
    ssh -o UserKnownHostsFile=/dev/null root@192.168.1.1
    oernii2 · 2010-04-08 14:55:58 5

  • -3
    ls -lS
    javamaniac · 2010-04-08 14:37:46 4
  • 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 Show Sample Output


    4
    history | perl -F"\||<\(|;|\`|\\$\(" -alne 'foreach (@F) { print $1 if /\b((?!do)[a-z]+)\b/i }' | sort | uniq -c | sort -nr | head
    alperyilmaz · 2010-04-08 13:46:09 4
  • Get a list of all the unique hostnames from the apache configuration files. Handy to see what sites are running on a server.


    0
    cat /etc/apache2/sites-enabled/* | egrep 'ServerAlias|ServerName' | tr -s " " | sed 's/^[ ]//g' | uniq | cut -d ' ' -f 2 | sed 's/www.//g' | sort | uniq
    chronosMark · 2010-04-08 08:51:17 5
  • Unpack and build a WebLogic 9 or 10 domain Show Sample Output


    0
    unpack.sh -domain=[PATH]/domains/mydomain -template=[PATH]/mydomain.jar
    andresaquino · 2010-04-08 01:51:06 4

  • 0
    pack.sh -domain=[PATH]/domains/mydomain -template=[PATH]/mydomain.jar -template_name="mydomain"
    andresaquino · 2010-04-08 00:20:55 4

  • -1
    svn log | grep "$LOGNAME" | grep `date '+%Y-%m-%d'`
    jimthunderbird · 2010-04-07 22:12:12 7
  • Not really an easier solution. But an example using && for (if last command returned 0). You can use || for (if last command returned other than 0).. Show Sample Output


    -2
    prefix="10.0.0" && for i in `seq 25`; do ping -c 1 $prefix.$i &> /dev/null && echo "Answer from: $prefix.$i" ; done
    xeor · 2010-04-07 17:17:21 4
  • Usefull for when you don't have nmap and need to find a missing host. Pings all addresses from 10.1.1.1 to 10.1.1.254, modify for your subnet. Timeout set to 1 sec for speed, if running over a slow connection you should raise that to avoid missing replies. This will clean up the junk, leaving just the IP address: for i in {1..254}; do ping -c 1 -W 1 10.1.1.$i | grep 'from' | cut -d' ' -f 4 | tr -d ':'; done Show Sample Output


    14
    for i in {1..254}; do ping -c 1 -W 1 10.1.1.$i | grep 'from'; done
    SuperJediWombat · 2010-04-07 16:57:53 7

  • 2
    find . \( -type d -empty \) -and \( -not -regex ./\.git.* \) -exec touch {}/.gitignore \;
    rpavlick · 2010-04-07 14:40:14 6
  • By default bash expands an unbound variable to an empty string. This can be dangerous, if a critical variable name (a path prefix for example) has a typo. The -u option causes bash to treat this as an error, and the -e option causes it to exit in case of an error. These two together will make your scripts a lot safer against typos. The default behaviour can be explicitly requested using the ${NAME:-} syntax. A (less explicit) variation: #!/bin/bash -eu Show Sample Output


    8
    set -eu
    wipu · 2010-04-07 11:54:40 8
  • Count the occurences of the word 'Berlekamp' in the DJVU files that are in the current directory, printing file names from the one having the least to the most occurences.


    0
    find ./ -iname "*.djvu" -execdir perl -e '@s=`djvutxt \"$ARGV[0]\"\|grep -c Berlekamp`; chomp @s; print $s[0]; print " $ARGV[0]\n"' '{}' \;|sort -n
    unixmonkey4437 · 2010-04-07 11:15:26 8
  • every 1sec sends DD the USR1 signal which causes DD to print its progress. Show Sample Output


    10
    while :;do killall -USR1 dd;sleep 1;done
    oernii2 · 2010-04-07 09:23:31 9
  • piping through 'pv' shows a simple progress/speed bar for dd. This is a replacement for my otherwise favorite 'while :;do killall -USR1 dd;sleep 1;done' Show Sample Output


    9
    dd if=/dev/nst0 |pv|dd of=restored_file.tar
    oernii2 · 2010-04-07 09:21:18 22
  • ‹ First  < 383 384 385 386 387 >  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

Which processes are listening on a specific port (e.g. port 80)
swap out "80" for your port of interest. Can use port number or named ports e.g. "http"

HTTP GET request on wireshark remotly

cycle through everything sox knows how to read, playing only the first three seconds
I wasted two hours reading the sox documentation and searching on the web for the format of some obscure fscking sound sample, and then finally came up with this. This plays only the first three seconds of your unknown formatted sound file using every one of sox's built-in filetypes. If you don't get an exact match, you may get close. . I could not fit every single type in and keep it under 127 characters, so you will have to replace "..." with the full list obtainable by `$ sox --help` (or try `Show sample output`) . note: /usr/bin/play should be linked to sox on most systems.

kill all foo process
Kill all processes with foo in them. Similar to pkill but more complete and also works when there is no pkill command. Works on almost every Linux/Unix platform I have tried.

List out classes in of all htmls in directory
Lists out all classes used in all *.html files in the currect directory. usefull for checking if you have left out any style definitions, or accidentally given a different name than you intended. ( I have an ugly habit of accidentally substituting camelCase instead of using under_scores: i would name soemthing counterBox instead of counter_box) WARNING: assumes you give classnames in between double quotes, and that you apply only one class per element.

Remove the first character of each line in a file

Hide or show Desktop Icons on MacOS
Hides all Files and Folders on the MacOS Desktop. To show files and folders, type "true" instead of "false". "Finder" at the end is case sensitive, "finder" doesn’t work

generate random tone

Show crontabs for all users
This is flatcaps tweaked command to make it work on SLES 11.2

print crontab entries for all the users that actually have a crontab
This is how I list the crontab for all the users on a given system that actually have a crontab. You could wrap it with a function block and place it in your .profile or .bashrc for quick access. There's prolly a simpler way to do this. Discuss.


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: