All commands (14,187)

  • There is no need to 'zcat textfile.gz | less' with newer distros. This is useful for reading archived log files without having to extract, read, and zip when done.


    -5
    less textfile.gz
    allbad · 2009-03-15 23:51:17 24
  • if you lose your sound, this will restart alsa and you will get your sound back


    -5
    sudo alsa force-reload
    oreo · 2009-02-16 03:30:13 170

  • -5
    oumou sangare
    gabougabou · 2010-04-12 21:45:02 5
  • fb


    -5
    lynx -useragent=Opera -dump 'http://www.facebook.com/ajax/typeahead_friends.php?u=4&__a=1' |gawk -F'\"t\":\"' -v RS='\",' 'RT{print $NF}' |grep -v '\"n\":\"' |cut -d, -f2
    pdan_23 · 2010-04-13 12:44:08 5

  • -5
    ntop
    theIndianMaiden · 2009-08-16 05:24:31 4
  • _ff(){ cd /mnt; echo /mnt/*/* |sed ' s/ \/mnt\//\&/g; '|sed '/'"$1"'/!d'; cd -; } ff(){ case $# in 0) echo "usage: ff glob [sed-cmds] [--|var-name]" ;; 1) _ff $1 |sed = ;; [2-9]) case $2 in --) _ff $1 |less -SN ;; *) _ff $1 |sed -n ''"$2"''|tr '\n' '\040' |sed 's/.*/export '"$3"'=\"&/;s/=\" /=\"/;s/ $/\"/' > $HOME/.ff; case $# in 3) . $HOME/.ff ;; esac; sed ' s/export .*=\"/\$'"$3"' = \"/;' $HOME/.ff;\ ;; esac ;; esac; } v(){ local a=$HOME; sed ' s/export /less -n \$/; s/=.*//; ' $a/.ff > $a/.v ; . $a/.v ; } Another approach using ls(1) lsl(){ _lsl () { ls -l $3 /mnt/*/$1* 2>/dev/null; }; case $# in 0) echo "usage: lsl pat [ls-options|result-no]"; echo "usage: lsle pat [sed-cmds]" ;; 1) _lsl $1 |sed = ;; 2) case $2 in -*) _lsl $1 $@;; *) _lsl $1 |sed 's/.* //; '"$2"'!d; '"$2"'q' > $HOME/.lsl ; export v=$(sed 1q $HOME/.lsl); echo \$v = $v ;; esac ;; esac; } exp(){ echo "%s/\$/ /"; echo "%j"; echo "s/^/export v=\""; echo "s/\$/\""; echo "s/ \"\$/\""; echo "."; echo "wq"; } lsle(){ lsl $1 -1 |sed $2 > .lsl&& exp |ed -s .lsl >&-&& . .lsl&& echo \$v = $v; }


    -5
    _ff(){ cd /mnt;echo /mnt/*/* |sed 's/ \/mnt\//\&/g' |sed '/'"$1"'/!d'; cd -;}
    argv · 2011-12-30 23:25:31 5

  • -5
    rehash
    Octave · 2010-06-18 15:29:17 6
  • only during session


    -5
    export PATH=$PATH:/home/user/my_prog
    sentenza · 2014-11-04 20:50:19 7
  • A simple but effective replacement for ps aux. I used to waste my time running ps over and over; top is the way to go. It also allows complex sorting options. Press q to exit "nicely" (Ctrl + C is always an option, of course). Note that the list updates each second, resorting in the process; if you're trying to grab a specific PID, you might be better off with ps. htop Alternatively, htop is available, though it may not come pre-installed. htop is slightly more interactive than top and includes color coding, visuals, and a nice interface for selecting and then killing processes. (Thanks to bwoodacre for this great tool.) Show Sample Output


    -5
    top
    Zenexer · 2009-03-18 00:03:42 10
  • The pgrep retrieves the PID, then the KILL receive it, and kill it... It works also if the application has more than one instance.... Show Sample Output


    -5
    kill -9 `pgrep $PROCESS_NAME`
    juanse006 · 2010-06-18 20:43:24 9

  • -5
    lsb_release -a
    ShaneEaston · 2012-03-27 15:47:29 61
  • Just find out the daemon with $ netstat -atulpe. Then type in his name and he gets the SIGTERM.


    -5
    kill_daemon() { echo "Daemon?"; read dm; kill -15 $(netstat -atulpe | grep $dm | cut -d '/' -f1 | awk '{print $9}') }; alias kd='kill_daemon
    P17 · 2009-05-26 20:39:56 7
  • IMVHO if you are using cpan to install perl modules you are doing it wrong. Show Sample Output


    -5
    dpkg-query -W | grep perl
    unixmonkey10924 · 2010-07-20 16:14:04 4
  • Aside from curl one will need iconv windows binary since windows lacks a native utf-8 cli interface. In my case I need a proxy in China and iconv to convert gbk status string into utf-8. GnuWin32 is a good choice with loads of coreutils natively ported to Windows "FOR /f" is the solution to pass iconv output to curl.


    -5
    FOR /f %%g in ('echo %1 ^| iconv -f gbk -t utf-8') DO curl -x proxy:port -u user:pass -d status=%%g -d source="cURL" http://twitter.com/statuses/update.xml
    MeaCulpa · 2010-07-21 04:53:54 3
  • If you need to print some portion of a huge file, let's say you want to print from line 200 to 300, you can use this command to print the line from LINE1 to LINE2 of file FILE.


    -5
    Printing portion of a big file
    acirulli · 2009-03-30 11:08:38 6

  • -5
    shred -v filename
    techie · 2013-05-07 14:58:17 6
  • Sends random beeps to your PC-speaker. Think... You can also run it remotely on another computer using SSH and scare its user! Don't forget to run it on your dedicated hosting server and watch sysadmin's action from data-center's live remote cameras!


    -5
    dd if=/dev/urandom of=/dev/speaker bs=1
    khashmeshab · 2010-10-27 09:22:40 7

  • -5
    awk 'END {print NR}' /etc/passwd
    Leo_Gutierrez · 2011-06-23 00:33:40 3
  • Sends random sounds to your sound card output (e.g. your speaker). Think... You can also run it remotely on another computer using SSH and scare its user!


    -5
    dd if=/dev/urandom of=/dev/dsp
    khashmeshab · 2010-10-27 09:25:02 3

  • -5
    echo 1+1|bc
    gnawa · 2009-02-19 13:46:58 5
  • This can be used in scripts, to find out the origin of target IP etc. Show Sample Output


    -5
    x=192.168.1.1; whois $x > $x.txt
    sxiii · 2011-01-17 03:33:49 9

  • -5
    echo -en "$USER@$HOSTNAME:${PWD##*/}> ";while read x;do echo $x>>/tmp/log.txt;echo $x|$0 2>&1;echo -en "$USER@$HOSTNAME:${PWD##*/}> ";done
    Nikon · 2011-01-17 20:53:28 13
  • This will kill a specific process you don't know the PID of, when pidof and pgrep are not available, for example on OS X. var1 is created so that the whitespace can be trimmed before passing off to kill. Show Sample Output


    -5
    export var1=`ps -A | grep '[u]nique' | cut -d '?' -f 1`; echo${var1/ /}; kill -9 $var1
    headyadmin · 2010-03-22 21:06:58 5

  • -6
    join file1.txt file2.txt > file3.txt
    olafrv · 2009-03-01 05:12:07 5
  • replace apt-get with your distro's package manager. Where 'something' is the package name, and 'specific' is what you're specifically looking for. This helps if your query is 2+ words long. Show Sample Output


    -6
    apt-get search something | grep specific
    ProfOak · 2010-09-27 07:10:39 30
  • ‹ First  < 552 553 554 555 556 >  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

Show all current listening programs by port and pid with SS instead of netstat

files and directories in the last 1 hour
added alias in ~/.bashrc alias lf='find ./* -ctime -1 | xargs ls -ltr --color'

Make vim open in tabs by default (save to .profile)
I always add this to my .profile rc so I can do things like: "vim *.c" and the files are opened in tabs.

Install pip with Proxy
Installs pip packages defining a proxy

Remove old unused kernels from Red Hat Enterprise Linux 5 & Fedora 12/13
Install using yum install yum-utils Options include: --oldkernels Remove old kernel and kernel-devel packages --count=KERNELCOUNT Number of kernel packages to keep on the system (default 2) use package-cleanup --help for a complete list

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"

list files recursively by size

command line to optimize all table from a mysql database

Create a QR code image in MECARD format
Add the QR code image on your webpage, business card ., etc, so people can scan it and quick add to their Contact Address Book. Tested on iPhone with QRreader.

Limit the transfer rate and size of data over a pipe
This example will close the pipe after transferring 100MB at a speed of 3MB per second.


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: