All commands (14,187)

  • This will run stat on each file in the directory. Show Sample Output


    1
    find -name `egrep -s '.' * | awk -F":" '{print $1}' | sort -u` -exec stat {} \;
    unixmonkey8594 · 2010-04-26 20:01:44 5
  • Very handy way to perform a host scan if you don't have nmap,ncat,nc ...or other tools installed locally. When executing a command on a /dev/tcp/$host/$port pseudo-device file, Bash opens a TCP connection to the associated socket and UDP connection when using /dev/udp/$host/$port.A simlpe way to get servers banner is to run this command "cat < /dev/tcp/localhost/25" , here you will get mail server's banner. NOTE: Bash, as packaged for Debian, does not support using the /dev/tcp and /dev/udp pseudo-device it's not enabled by default Because bash in Debian is compiled with ?disable-net-redirections. Show Sample Output


    4
    for p in {1..1023}; do(echo >/dev/tcp/localhost/$p) >/dev/null 2>&1 && echo "$p open"; done
    benyounes · 2010-04-26 18:09:22 41
  • Reports all local partitions having more than 90% usage. Just add it in a crontab and you'll get a mail when a disk is full. (sending mail to the root user must work for that) Show Sample Output


    2
    df -l | grep -e "9.%" -e "100%"
    dooblem · 2010-04-26 17:57:54 3
  • This will generate 3 paragraphs with random text. Change the 3 to any number. Show Sample Output


    5
    lynx -source http://www.lipsum.com/feed/xml?amount=3|perl -p -i -e 's/\n/\n\n/g'|sed -n '/<lipsum>/,/<\/lipsum>/p'|sed -e 's/<[^>]*>//g'
    houghi · 2010-04-26 17:26:44 5
  • Sprunge.us is a code/text sharing site like pastebin, but it is easy to post stuff from the command line. How it works: :w !command In vim, w writes the current tab to a file when a filename is given afterwards, but if !command is given, the output is piped to the stdin of command. curl -F "sprunge=<-" http://sprunge.us curl is an HTTP client. The -F option does an HTTP post to the given address. The data in the quotes is passed in the post. The "sprunge=" part sets up a fieldname - the part that follows is what is associated with the name. The "<" tells curl to send data from the file descriptor that follows it. The "-" in bash is a file descriptor that points to stdin instead of an actual file; in this case, stdin is being piped in from vim. After we send the HTTP post to sprunge.us, it will give back a url that points to the data you just sent. | xclip xclip is a utility that lets you put stuff in your clipboard or selection buffer. This part uses a bash pipe ( | ) to redirect the stdout of the previous command to the stdin of the next command. So, we're capturing the URL that curl gave us and putting it into the selection buffer, ready to paste into IRC or a forum. Notes: Of course, for this to work, you must have curl (which comes by default on most distroes), and xclip installed. When you share the url, you can append "?lang" to highlight and have line numbers. Check out http://sprunge.us/BZXV?log for line numbers and http://sprunge.us/BZXV?ruby for highlighting. If you prefer to use ctrl-v (paste from clipboard) instead of middle-click (paste from selection buffer), look up options on xclip - you can do that. Show Sample Output


    18
    :w !curl -F "sprunge=<-" http://sprunge.us | xclip
    shawnjgoff · 2010-04-25 00:43:37 33
  • ffmpeg -i = input file name -s = set frame size, qcif=176x144 -vcodec = force video codec -r = frame-rate [default = 25] -b = bit-rate [200 kb/s] -acodec = force audio codec -ab = audio bitrate in bits/s [64k] -ac = no. of audio channels [1] -ar = audio sampling frequency [44100 Hz] optional: -sameq = use same video quality as source (implies VBR) -f = force format -y = overwrite output files


    3
    ffmpeg -i input.avi -s qcif -vcodec h263 -r 20 -b 180k -acodec libfaac -ab 64k -ac 2 -ar 22050 output.3gp
    mariusbutuc · 2010-04-24 23:01:21 4
  • Open up vi or vim at the first instance of a pattern in [file]. Useful if you know where you want to be, like "PermitRootLogin" in sshd_config. Also, vi +10 [file] will open up a file at line 10. VERY useful when you get "error at line 10" type of output.


    25
    vi +/pattern [file]
    punkwalrus · 2010-04-24 22:15:12 7
  • see the TIME_WAIT and ESTABLISHED nums of the network Show Sample Output


    7
    netstat -n | awk '/^tcp/ {++B[$NF]} END {for(a in B) print a, B[a]}'
    healthly · 2010-04-24 12:11:52 4
  • This little function will smarten 'cd'. If you try to cd into a file (which I guess we all have done), it cd's into the directory of that file instead. I had to use nesten if's, to get cd to still work with 'cd' (to get to $HOME), 'cd -' (to get to last directory), and 'cd foo\ bar'. Show Sample Output


    9
    cd() { if [ -z "$1" ]; then command cd; else if [ -f "$1" ]; then command cd $(dirname "$1"); else command cd "$1"; fi; fi; }
    xeor · 2010-04-23 19:17:43 6
  • This shows you which files are most in need of commenting (one line of output per file)


    1
    find ./ -name *.h -exec egrep -cH "// | /\*" {} \; | awk -F':' '{print $2 ":" $1}' | sort -gr
    blocky · 2010-04-23 19:00:07 3
  • similar to the previous command, but with more friendly output (tested on linux)


    10
    strace -ff -e write=1,2 -s 1024 -p PID 2>&1 | grep "^ |" | cut -c11-60 | sed -e 's/ //g' | xxd -r -p
    systemj · 2010-04-23 16:22:17 4
  • show your current iptable rules from every available iptable table


    1
    for i in `cat /proc/net/ip_tables_names`; do iptables -nL -v --line-numbers -t $i ; done
    bw · 2010-04-23 13:53:49 9
  • No comment... it's easy! Using the VBoxManage list and the switch 'hdds' or 'dvds' you can show the list of hard disks and DVD registered on the system.


    0
    VBoxManage openmedium dvd "/path/name.iso"
    0disse0 · 2010-04-23 06:56:42 5
  • No comment: it's easy!


    -1
    VBoxManage createvm --name "vm-name" --ostype Ubuntu --register
    0disse0 · 2010-04-23 06:54:26 4
  • If you want to know what OS are supported on "guest" machines on the Sun VirtualBox server.


    -1
    VBoxManage list ostypes
    0disse0 · 2010-04-23 06:50:42 8
  • where "cicciobox" is the name of your virtual machine in a Sun VirtualBox server


    -1
    VBoxManage showvminfo "cicciobox" --details
    0disse0 · 2010-04-23 06:45:29 3
  • How to show the system properties of a Sun VirtualBox server


    -1
    VBoxManage list systemproperties
    0disse0 · 2010-04-23 06:43:49 6
  • One of my favorite ways to impress newbies (and old hats) to the power of the shell, is to give them an incredibly colorful and amazing version of the top command that runs once upon login, just like running fortune on login. It's pretty sweet believe me, just add this one-liner to your ~/.bash_profile -- and of course you can set the height to be anything, from 1 line to 1000! G=$(stty -g);stty rows $((${LINES:-50}/2));top -n1; stty $G;unset G Doesn't take more than the below toprc file I've added below, and you get all 4 top windows showing output at the same time.. each with a different color scheme, and each showing different info. Each window would normally take up 1/4th of your screen when run like that - TOP is designed as a full screen program. But here's where you might learn something new today on this great site.. By using the stty command to change the terminals internal understanding of the size of your terminal window, you force top to also think that way as well. # save the correct settings to G var. G=$(stty -g) # change the number of rows to half the actual amount, or 50 otherwise stty rows $((${LINES:-50}/2)) # run top non-interactively for 1 second, the output stays on the screen (half at least) top -n1 # reset the terminal back to the correct values, and clean up after yourself stty $G;unset G This trick from my [ http://www.askapache.com/linux-unix/bash_profile-functions-advanced-shell.html bash_profile ], though the online version will be updated soon. Just think what else you could run like this! Note 1: I had to edit the toprc file out due to this site can't handle that (uploads/including code). So you can grab it from [ http://www.askapache.com/linux-unix/bash-power-prompt.html my site ] Note 2: I had to come back and edit again because the links weren't being correctly parsed Show Sample Output


    3
    G=$(stty -g);stty rows $((${LINES:-50}/2));top -n1; stty $G;unset G
    AskApache · 2010-04-22 18:52:49 13
  • "killall -USR1 dd" does not work in OS X for me. However, sending INFO instead of USR1 works. Show Sample Output


    16
    killall -INFO dd
    jearsh · 2010-04-22 18:38:37 5

  • 3
    echo StrinG | tr '[:upper:]' '[:lower:]'
    hm2k · 2010-04-22 15:09:49 5
  • First of all you need to run this command. X :12.0 vt12 2>&1 >/dev/null & This command will open a X session on 12th console. And it will show you blank screen. Now press Alt + Ctrl + F7. You will get your original screen. Now run given command "xterm -display :12.0 -e ssh -X user@remotesystem &". After this press Alt + Ctrl + F12. You will get a screen which will ask you for password for remote linux system. And after it you are done. You can open any window based application of remote system on your desktop. Press Alt + Ctrl + F7 for getting original screen.


    8
    xterm -display :12.0 -e ssh -X user@server &
    vishalce · 2010-04-22 10:29:24 5

  • -2
    /sbin/ifconfig|grep -B 1 inet |head -1 | awk '{print $5}'
    octopus · 2010-04-22 06:35:29 6
  • Prints the type of computer you have. I think this should be used more in distros and other applications because it is so easy to get. This can also be asked by tutorials as an easy way to get your base hardware. Some alternatives: sudo dmidecode -s system-product-name and sudo smbios-sys-info-lite | sed -n 's/^Product Name: *\(.*\)/\1/p' Show Sample Output


    -2
    cat /sys/devices/virtual/dmi/id/board_name
    matthewbauer · 2010-04-22 03:21:40 9

  • -8
    sed -i -e 's/^#$//g' /path/to/file
    leonardovaz · 2010-04-22 02:40:22 4

  • -7
    grep -v ^# file.conf | grep -v ^$ > new_file.conf
    valessiobrito · 2010-04-22 02:28:34 36
  • ‹ First  < 378 379 380 381 382 >  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

list block level layout

awk date convert
Convert readable date/time with `date` command

Alias TAIL for automatic smart output
Run the alias command, then issue $ps aux | tail 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 default of 80. The default for TAIL is to output the last 10 lines, this alias changes the default to output the last x lines instead, where x is the number of lines currently displayed on your terminal - 7. The -7 is there so that the top line displayed is the command you ran that used TAIL, 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. ( http://www.askapache.com/linux/bash-power-prompt.html ) 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.

generate a unique and secure password for every website that you login to
usage: sitepass MaStErPaSsWoRd example.com description: An admittedly excessive amount of hashing, but this will give you a pretty secure password, It also eliminates repeated characters and deletes itself from your command history. tr '!-~' 'P-~!-O' # this bit is rot47, kinda like rot13 but more nerdy rev # this avoids the first few bytes of gzip payload, and the magic bytes.

Route outbound SMTP connections through a addtional IP address rather than your primary

View all images
So you are in directory with loads of pictures laying around and you need to quickly scan through them all

Renaming a file without overwiting an existing file name
Sometimes in a hurry you may move or copy a file using an already existent file name. If you aliased the cp and mv command with the -i option you are prompted for a confirmation before overwriting but if your aliases aren't there you will loose the target file! The -b option will force the mv command to check if the destination file already exists and if it is already there a backup copy with an ending ~ is created.

Extract the MBR ID of a device
Useful when you want to know the mbrid of a device - for the purpose of making it bootable. Certain hybridiso distros, for eg the OpenSUSE live ISO uses the mbrid to find the live media. Use this command to find out the mbrid of your USB drive and then edit the /grub/mbrid file to match it.

Convert CSV to JSON
Replace 'csv_file.csv' with your filename.

Find files that were modified by a given command
Traces the system calls of a program. See http://linuxhelp.blogspot.com/2006/05/strace-very-powerful-troubleshooting.html for more information.


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: