All commands (14,187)

  • Search in "filename" for the first line to match regex, and print to stdout from the matching line to the end of the file.


    1
    sed -n '/regex/,$p' filename
    SuperFly · 2010-07-08 19:24:43 3
  • the block of the loop is useful whenever you have huge junks of similar jobs, e.g., convert high res images to thumbnails, and make usage out of all the SMP power on your compute box without flooding the system. note: c is used as counter and the random sleep r=`echo $RANDOM%5 |bc`; echo "sleep $r"; sleep $r is just used as a dummy command. Show Sample Output


    5
    c=0; n=8; while true; do r=`echo $RANDOM%5 |bc`; echo "sleep $r"; sleep $r& 2>&1 >/dev/null && ((c++)); [ `echo "$c%$n" | bc` -eq 0 ] && echo "$c waiting" && wait; done
    cp · 2010-07-08 13:56:28 6
  • cu (call UNIX) establishes a full-duplex connection to another machine (*BSD) using a serial console. It becames more useful than screen if you have to send a BREAK signal. using cu just type "~#". man cu http://www.openbsd.org/cgi-bin/man.cgi?query=cu&apropos=0&sektion=0&manpath=OpenBSD+Current&arch=i386&format=html Show Sample Output


    5
    cu -s 9600 -l /dev/ttyS0
    cp · 2010-07-08 06:33:55 9
  • You need to have fortune and cowsay installed. It uses a subshell to list cow files in you cow directory (this folder is default for debian based systems, others might use another folder). you can add it to your .bashrc file to have it great you with something interesting every time you start a new session. Show Sample Output


    10
    fortune | cowsay -f $(ls /usr/share/cowsay/cows/ | shuf -n1)
    zed · 2010-07-08 02:57:52 8
  • * Add comment with # in your command * Later you can search that command on that comment with CTRL+R In the title command, you could search it later by invoking the command search tool by first typing CTRL+R and then typing "revert" Show Sample Output


    1
    svn up -r PREV # revert
    unixmonkey10719 · 2010-07-07 23:09:00 16
  • Update all "ant" packages installed on Gentoo Show Sample Output


    2
    emerge -q1 $(eix -C dev-java -I --upgrade+ --only-names ant)
    neoriddle · 2010-07-07 22:22:02 5
  • Define commands that you always invoke with an appended '&disown'. In the example: gvim foo.txt will open gvim dettached from the current terminal.


    0
    __disown(){ local cmd=$1 ; shift ; $cmd "$@" &> /dev/null &disown }; for i in gvim ; do alias $i="__disown $i"; done
    smolav · 2010-07-07 20:46:45 4
  • Calculator for shell. Similar performance and basic usage as 'bc', but with more advanced features. Not installed on most systems by default. Show Sample Output


    1
    wcalc -q <<< '3/5'
    smolav · 2010-07-07 20:31:21 4

  • -3
    ps -axgu | cut -f1 -d' ' | sort -u
    dfaulkner · 2010-07-07 12:29:46 4
  • Shows a list of users that currently running processes are executing as. YMMV regarding ps and it's many variants. For example, you might need: ps -axgu | cut -f1 -d' ' | sort -u Show Sample Output


    2
    ps -eo user | sort -u
    dfaulkner · 2010-07-07 12:28:44 6

  • -2
    cut -d: -f1 /etc/passwd | sort
    dog · 2010-07-07 12:12:02 5
  • Most systems (at least my macbook) have system users defined, such as _www and using "users" for example will not list them. This command allows you to see who the 'virtual' users are on your system. Show Sample Output


    -4
    sudo lsof|sed 's/ */ /g'|cut -f3 -d' '|sort -u
    binaryten · 2010-07-07 08:20:28 7
  • We normally get tasks in which one has to sort a data file according to some column. For a single file say foo, we would use sort -k 3 foo >tmp && tmp foo The for loop is useful when we have to do it on a number of files.


    -2
    for x in *.dat;do sort -k 3 $x >tmp && mv -f tmp $x;done
    rajarshi · 2010-07-07 07:57:37 5
  • You can install filterous with sudo apt-get install libxslt1-dev; sudo easy_install -U filterous Show Sample Output


    2
    filterous -dntb --tag Bash < bookmarks.xml
    l0b0 · 2010-07-07 07:42:11 4
  • Thanks to flatcap for optimizing this command. This command takes advantage of the ext4 filesystem's resistance to fragmentation. By using this command, files that were previously fragmented will be copied / deleted / pasted essentially giving the filesystem another chance at saving the file contiguously. ( unlike FAT / NTFS, the *nix filesystem always try to save a file without fragmenting it ) My command only effects the home directory and only those files with your R/W (read / write ) permissions. There are two issues with this command: 1. it really won't help, it works, but linux doesn't suffer much (if any ) fragmentation and even fragmented files have fast I/O 2. it doesn't discriminate between fragmented and non-fragmented files, so a large ~/ directory with no fragments will take almost as long as an equally sized fragmented ~/ directory The benefits i managed to work into the command: 1. it only defragments files under 16mb, because a large file with fragments isn't as noticeable as a small file that's fragmented, and copy/ delete/ paste of large files would take too long 2. it gives a nice countdown in the terminal so you know how far how much progress is being made and just like other defragmenters you can stop at any time ( use ctrl+c ) 3. fast! i can defrag my ~/ directory in 11 seconds thanks to the ramdrive powering the command's temporary storage bottom line: 1. its only an experiment, safe ( i've used it several times for testing ), but probably not very effective ( unless you somehow have a fragmentation problem on linux ). might be a placebo for recent windows converts looking for a defrag utility on linux and won't accept no for an answer 2. it's my first commandlinefu command Show Sample Output


    2
    find ~ -maxdepth 20 -type f -size -16M -print > t; for ((i=$(wc -l < t); i>0; i--)) do a=$(sed -n ${i}p < t); mv "$a" /dev/shm/d; mv /dev/shm/d "$a"; echo $i; done; echo DONE; rm t
    LinuxMan · 2010-07-07 04:29:22 9
  • My variation on an audio burning command from commandlinefu - this one doesn't crap out if you want to burn a CD in a directory whose permissions don't allow it, and instead rips everything to /tmp. If you mount your music partition like I do using Samba, you probably don't have write permission inside that file system in order to create the temporary directory other audio burning commands here use. Not a bad idea to add cdrom to your groups, and /bin/eject with visudo.


    2
    goburncd() { d=/tmp/goburncd_$RANDOM; mkdir $d && for i in *.[Mm][Pp]3; do lame --decode "$i" "$d/${i%%.*}.wav"; done; sudo cdrecord -pad $d/* && rm -r $d; eject }
    meathive · 2010-07-06 21:58:10 14
  • This does almost the same thing as the original, but it runs the full backtrace for _all_ the threads, which is pretty important when reporting a crash for a multithreaded software, since more often than not, the signal handler is executed in a different thread than the crash happened.


    6
    gdb --batch --quiet -ex "thread apply all bt full" -ex "quit" ${exe} ${corefile}
    Flameeyes · 2010-07-06 14:49:03 10
  • The output is only partial because runtime dependencies should count in also commands executed via system() and libraries loaded with dlopen(), but at least it gives an idea of what a package directly links to. Note: this is meaningful *only* if you're using -Wl,--as-needed in your LDFLAGS, otherwise it'll bring you a bunch of false positives. Show Sample Output


    2
    qlist --exact "$pkg" | sudo scanelf --needed --quiet --format '%n#F' | tr ',' '\n' | sort -u | qfile --from -
    Flameeyes · 2010-07-06 14:39:15 94
  • shows only folders, that are MB or GB in total size


    -2
    du -shc .[^.]* * | grep [MG]
    rubo77 · 2010-07-06 10:13:18 12
  • This command is suitable to use as application launching command for a desktop shortcut. It checks if the application is already running by pgrepping its process ID, and offer user to kill the old process before starting a new one. It is useful for a few x11 application that, if re-run, is more likely a mistake. In my example, x2vnc is an x11 app that does not quit when its connection is broken, and would not work well when a second process establish a second connection after the first broken one. The LC_ALL=C for xmesseng is necessary for OpenSUSE systems to avoid a bug. If you don't find needing it, remove the "env LC_ALL=C" part


    0
    sh -c 'if pgrep x2vnc && env LC_ALL=C xmessage -button "Kill it:0,Ignore it:1" "Another connection is already running. Should I kill it instead of ignoring it?"; then killall x2vnc; fi; x2vnc -passwd /home/Ariel/.vnc/passwd -east emerson:0'
    zhangweiwu · 2010-07-06 09:11:12 3
  • --basic --user username:password This will authenticate your Twitter username and password --data status="" Send data to the API with POST HTTP form.


    -3
    curl --basic --user username:password --data status="Twitter from commandline with curl" https://twitter.com/statuses/update.xml
    emacs · 2010-07-06 05:25:51 4

  • -4
    awk 'NR==linenumber' filename
    rajarshi · 2010-07-06 05:17:29 9
  • the second command 'vim !$' will open test.txt to edit Show Sample Output


    0
    vim !$
    emacs · 2010-07-06 01:39:22 3
  • used when modify several configuration files with a single command Show Sample Output


    1
    sed -i '<line_no>s/\(.*\)/#\1/' <testfile>
    Sunng · 2010-07-05 08:19:44 5
  • using cat WAR_AND_PEACE_By_LeoTolstoi.txt | tr -cs "[:alnum:]" "\n"| tr "[:lower:]" "[:upper:]" | sort -S16M | uniq -c |sort -nr | cat -n | head -n 30 ("sort -S1G" - Linux/GNU sort only) will also do the job but as some drawbacks (caused by space/time complexity of sorting) for bigger files... Show Sample Output


    11
    cat WAR_AND_PEACE_By_LeoTolstoi.txt | tr -cs "[:alnum:]" "\n"| tr "[:lower:]" "[:upper:]" | awk '{h[$1]++}END{for (i in h){print h[i]" "i}}'|sort -nr | cat -n | head -n 30
    cp · 2010-07-05 06:39:20 15
  • ‹ First  < 360 361 362 363 364 >  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

Shows size of dirs and files, hidden or not, sorted.

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"

Rename files in batch

Run a program transparently, but print a stack trace if it fails
For automated unit tests I wanted my program to run normally, but if it crashed, to add a stack trace to the output log. I came up with this command so I wouldn't have to mess around with core files. The one downside is that it does smoosh your program's stderr and stdout together.

Get AWS temporary credentials ready to export based on a MFA virtual appliance
You might want to secure your AWS operations requiring to use a MFA token. But then to use API or tools, you need to pass credentials generated with a MFA token. This commands asks you for the MFA code and retrieves these credentials using AWS Cli. To print the exports, you can use: `awk '{ print "export AWS_ACCESS_KEY_ID=\"" $1 "\"\n" "export AWS_SECRET_ACCESS_KEY=\"" $2 "\"\n" "export AWS_SESSION_TOKEN=\"" $3 "\"" }'` You must adapt the command line to include: * $MFA_IDis ARN of the virtual MFA or serial number of the physical one * TTL for the credentials

a short counter
Maybe you know shorter ?

run command on a group of nodes in parallel
The pee command is in the moreutils package.

back ssh from firewalled hosts
host B (you) redirects a modem port (62220) to his local ssh. host A is a remote machine (the ones that issues the ssh cmd). once connected port 5497 is in listening mode on host B. host B just do a ssh 127.0.0.1 -p 5497 -l user and reaches the remote host'ssh. This can be used also for vnc and so on.

Patator: A Hydra brute force alternative

Convert seconds to [DD:][HH:]MM:SS
Converts any number of seconds into days, hours, minutes and seconds. sec2dhms() { declare -i SS="$1" D=$(( SS / 86400 )) H=$(( SS % 86400 / 3600 )) M=$(( SS % 3600 / 60 )) S=$(( SS % 60 )) [ "$D" -gt 0 ] && echo -n "${D}:" [ "$H" -gt 0 ] && printf "%02g:" "$H" printf "%02g:%02g\n" "$M" "$S" }


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: