All commands (14,187)

  • make password randomly, default 8 char


    -1
    genpass() { local h x y;h=${1:-8};x=( {a..z} {A..Z} {0..9} );y=$(echo ${x[@]} | tr ' ' '\n' | shuf -n$h | xargs);echo -e "${y// /}"; }
    twfcc · 2009-10-24 04:05:42 4
  • Use multiple patterns with grep -v. So you can print all lines in a file except those containing the multiple patterns you specify.


    16
    grep 'test' somefile | grep -vE '(error|critical|warning)'
    zlemini · 2009-10-23 23:21:36 12
  • Alternative to the ping check if your firewall blocks ping. Uses curl to get the landing page silently, or fail with an error code. You can probably do this with wget as well. Show Sample Output


    2
    curl -fs brandx.jp.sme 2&>1 > /dev/null || echo brandx.jp.sme ping failed | mail -ne -s'Server unavailable' joker@jp.co.uk
    mccalni · 2009-10-23 14:29:06 4
  • Strip my code to: wmctrl -o 0,0 # autorotates to the first face. In fact [0-1279],0 wmctrl - 1280,0 # goes to the second face wmctrl -o 2560,0 # goes to the third face, and so on. # Use multiples of the horizontal display resolution. My example work for 1280x800 display, been 1280 the number of interest. Tweak the number, try a biiiig one and see your cube spinning... I put a complex example to show how fun things can be, even for my ademco and paradox alarm central network advisor interface xpto etc. It rotates two faces, print the alarm message, and goes back tho where it was. Tested on BIGLINUX 4.2, equivalent to ubuntu LTS hardy. Do not forget to activate 3D efects ( compiz cube ) Show Sample Output


    5
    wmctrl -o 2560,0 ;sleep 2 ; echo "FIRE 001" | osd_cat -o 470 -s 8 -c red -d 10 -f -*-bitstream\ vera\ sans-*-*-*--250-*-*-*-*-*-*-* ; sleep 1; wmctrl -o 0,0
    m33600 · 2009-10-23 10:00:51 17
  • already described on the other two versions, this one uses ascii characters on game style to display elapsed time. Show Sample Output


    0
    export I=$(date +%s); watch -t -n 1 'T=$(date +%s);E=$(($T-$I));hours=$((E / 3600)) ; seconds=$((E % 3600)) ; minutes=$((seconds / 60)) ; seconds=$((seconds % 60)) ; echo $(printf "%02d:%02d:%02d" $hours $minutes $seconds) | toilet -f shadow'
    m33600 · 2009-10-23 07:56:30 10
  • Variation of the theme, this one blinks in low profile on top level of X, ie, it is visible, indeed small. Try changing fonts and sizes of osd_cat


    0
    export I=$(date +%s); watch -t -n 1 'T=$(date +%s);E=$(($T-$I));hours=$((E / 3600)) ; seconds=$((E % 3600)) ; minutes=$((seconds / 60)) ; seconds=$((seconds % 60)) ; echo $(printf "%02d:%02d:%02d" $hours $minutes $seconds) | osd_cat -o 20 -d 1 -p bottom'
    m33600 · 2009-10-23 07:47:11 3
  • Works on real time clock, unix time based, decrementing the actual time from initial time saved in an environment variable exported to child process inside watch Shows elapsed time from start of script in hh:mm:ss format Non afected by system slow down due to the use of date.


    3
    export I=$(date +%s); watch -t -n 1 'T=$(date +%s);E=$(($T-$I));hours=$((E / 3600)) ; seconds=$((E % 3600)) ; minutes=$((seconds / 60)) ; seconds=$((seconds % 60)) ; echo $(printf "%02d:%02d:%02d" $hours $minutes $seconds)'
    m33600 · 2009-10-23 07:31:44 8
  • simple function , floating point number is supported.


    12
    calc(){ awk "BEGIN{ print $* }" ;}
    twfcc · 2009-10-23 06:03:07 52
  • My firefox overheats my cpu, sometimes above 90 degrees Celsius ( hence the name? ) To keep an eye on temperature, I put this command inside KAlarm ( a kind of cron) to be repeated every minute, for 5 seconds, color red ( default for osd_cat). Its pretty, ultra small, displays a micro 2 lines text on every desktop and over everything and do not steal focus or interrupt any task. I get the information passively, in the low profile bottom of the screen. Of course you can use it inside a terminal. Just do it: watch -n 60 'acpi -t | osd_cat -p bottom'


    2
    acpi -t | osd_cat -p bottom
    m33600 · 2009-10-23 05:22:01 3
  • Usefull as a light blink to remember events, mails, intrusions, etc... yet another output Since nobody ever uses the scroll lock function... Usefull to interface a linux system with some hardware, for example, opto interfacing the keyboard led to a relay to remotely reset, etc. ( a simple LDR glued over the LED will do the trick ) xset led 3 turns on the third led, ie, Scroll lock xset -led 3 turns it off xset led 1 turns on Numerical Lock led ( doesn t work on all computer ) xset led 2 turns on Caps Lock led ( idem ) Using it as a reset watchdog, the relay expected light pulses. Shall the computer hangs, the relay releases and reset the machine ( discharge of a capacitor ) ;-)


    5
    xset led 3
    m33600 · 2009-10-23 00:25:56 15
  • If you omit the function name, the command will display all definitions Show Sample Output


    5
    declare -f [ function_name ]
    haivu · 2009-10-22 17:52:47 6
  • If you issue the "set" command, you'll see a list of variables and functions. This command displays just those functions' names. Show Sample Output


    1
    set | fgrep " ()"
    haivu · 2009-10-22 17:48:54 6
  • Handled all within awk. Takes the value from $PWD and constructs directory structures and runs commands against them. The gsub() call is not necessary, but added for better visibility. If a variable DIR is given on the awk command-line, then that directory is used instead: awk -vDIR=$HOME/.ssh 'BEGIN{dir=DIR?...}' Show Sample Output


    -1
    awk 'BEGIN{dir=DIR?DIR:ENVIRON["PWD"];l=split(dir,parts,"/");last="";for(i=1;i<l+1;i++){d=last"/"parts[i];gsub("//","/",d);system("ls -ld \""d"\"");last=d}}'
    arcege · 2009-10-22 16:28:07 5
  • note the xargs at the end


    5
    shuf -i 1-49 | head -n6 | sort -n| xargs
    ioggstream · 2009-10-22 12:54:08 93
  • Can easily be scripted in order to show permission "tree" from any folder. Can also be formated with column -t { pushd .> /dev/null; cd /; for d in `echo $OLDPWD | sed -e 's/\// /g'`; do cd $d; echo -n "$d "; ls -ld .; done; popd >/dev/null ; } | column -t from http://www.commandlinefu.com/commands/view/3731/using-column-to-format-a-directory-listing Show Sample Output


    0
    pushd .> /dev/null; cd /; for d in `echo $OLDPWD | sed -e 's/\// /g'`; do cd $d; echo -n "$d "; ls -ld .; done; popd >/dev/null
    syladmin · 2009-10-22 12:32:11 3

  • 7
    echo $(shuf -i 1-49 | head -n6 | sort -n)
    twfcc · 2009-10-22 06:48:20 4
  • One character less...


    0
    flip -u <filenames>
    linuxmonkey · 2009-10-21 21:25:43 3
  • atime and mtime timestamps of $FILE2 is changed according to the ones of $FILE1. If $FILE2 doesn't exist is created. Show Sample Output


    2
    touch -r "$FILE1" "$FILE2"
    kobayashison · 2009-10-21 13:53:59 6

  • 0
    shopt -s dotglob
    sharfah · 2009-10-21 13:31:20 3
  • This could be added to .bashrc. Background: Linux usually saves history only on clean exit of shell. If shell ends unclean, history is lost. Also numerous terminals might confuse their history. With this variable set, history is immedeately written, accessible to all other open shells.


    2
    PROMPT_COMMAND="history -a"
    danam · 2009-10-21 12:33:25 4
  • set directly the wallpaper on windowmaker , use this command with display of imagemagick :) Show Sample Output


    1
    wmsetbg -s -u path_to_wallpaper
    eastwind · 2009-10-21 11:23:54 4
  • syntax : mencoder mf://filemask -mf option availble for mf : * w=value : the width of the output, by d?fault : autodetected * h=value : height of the output, by default : autodetected * fps=value : framerate of the output, by default : 25 * type=value : file format type input , avaible: jpeg, png, tga, sgi


    -1
    mencoder mf://image1.jpg,image2.jpg,image3.jpg -mf w=800:h=600:fps=25:type=jpeg -ovc copy -oac copy -o output.avi
    eastwind · 2009-10-21 09:17:22 3
  • syntax : mencoder mf://filemask -mf option availble for mf : * w=value : the width of the output, by d?fault : autodetected * h=value : height of the output, by default : autodetected * fps=value : framerate of the output, by default : 25 * type=value : file format type input , avaible: jpeg, png, tga, sgi Show Sample Output


    0
    mencoder mf://*.jpg -mf w=800:h=600:fps=25:type=jpeg -ovc lavc -lavcopts vcodec=mpeg4 -oac copy -o output.avi
    eastwind · 2009-10-21 09:14:04 3
  • Convert those .mov files that your digital camera makes to .avi Adjust the bitrate (-b) to get the appropriate file size. A larger bitrate produces a larger (higher quality) .avi file and smaller bitrate produces a smaller (lower quality) .avi file. Requires ffmpeg (see man page for details) (tested with canon camera MOV files) Other examples: ffmpeg -i input.mov -sameq -vcodec msmpeg4v2 -acodec pcm_u8 output.avi ffmpeg -i input.mov -b 1024k -vcodec msmpeg4v2 -acodec pcm_u8 output.avi


    1
    ffmpeg -i input.mov -b 4096k -vcodec msmpeg4v2 -acodec pcm_u8 output.avi
    oracular · 2009-10-21 05:44:31 9
  • Just one character longer than the sed version ('FNR==5' versus -n 5p). On my system, without using "exit" or "q", the awk version is over four times faster on a ~900K file using the following timing comparison: testfile="testfile"; for cmd in "awk 'FNR==20'" "sed -n '20p'"; do echo; echo $cmd; eval "$cmd $testfile"; for i in {1..3}; do time for j in {1..100}; do eval "$cmd $testfile" >/dev/null; done; done; done Adding "exit" or "q" made the difference between awk and sed negligible and produced a four-fold improvement over the awk timing without the "exit". For long files, an exit can speed things up: awk 'FNR==5{print;exit}' <file>


    2
    awk 'FNR==5' <file>
    dennisw · 2009-10-20 22:52:41 5
  • ‹ First  < 434 435 436 437 438 >  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

find all non-html files

Show a prettified list of nearby wireless APs

Parse YouTube url (get youtube video id)
url can be like any one of followings: $url="MejbOFk7H6c" $url="http://youtu.be/MejbOFk7H6c" $url="https://youtube.com/watch?feature=player_embedded&v=MejbOFk7H6c#t" $url="//www.youtube.com/v/MejbOFk7H6c?hl=ru_RU&version=3&rel=0" $url="http://www.youtube.com/embed/MejbOFk7H6c?feature=player_embedded" If url mismatching, whole url will be returned.

Copy a file to a new directory created on the fly
You need to cp, mv, scp, ..., some files around from one place to another, and after having laboriously typed out the source path, you remember that the destination directory doesn't yet exist, and so the command will fail. So rather than killing the command line and starting over, just interpolate the results of creating the directory and echo its name. You could DRY this with a for; do; done, but that may be more trouble than it's worth.

Repeat a command until stopped
In this case it runs the command 'curl localhost:3000/site/sha' waiting the amount of time in sleep, ie: 1 second between runs, appending each run to the console. This works well for any command where the output is less than your line width This is unlike watch, because watch always clears the display.

static compilation

Batch-Convert text file containing youtube links to mp3

list files recursively by size

Draw a Sierpinski triangle
OK, not the most useful but a good way to impress friends. Requires the "display" command from ImageMagick.

Numeric zero padding file rename
This uses Perl's rename utility (you may have to call it as prename on your box) and won't choke on spaces or other characters in filenames. It will also zero pad a number even in filenames like "vacation-4.jpg".


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: