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 51
  • 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

force unsupported i386 commands to work on amd64
The above was done using the i386 flashplayer plugin, and was installed on a AMD64 machine running an AMD64 kernel and AMD64 programs. the resulting plugin install ultimately didn't work for swiftfox (but worked for iceweasel) without also covering it with a nspluginwrapper which took a bit of fenangaling to get to work (lots of apt-getting) but it is a nice feature to be able to trick installers that think you need i386 into running on a amd64, or at least attempting to run on amd64. Enjoy

Gets the english pronunciation of a phrase
Usage examples: say hello say "hello world" say hello+world

Generat a Random MAC address
Generate a random MAC address with capital letters

Extract tarball from internet without local saving

Check whether laptop is running on battery or cable
The original proc file doesn't exist on my system.

Install pip with Proxy
Installs pip packages defining a proxy

Track X Window events in chosen window
After executing this, click on a window you want to track X Window events in. Explaination: "xev will track events in the window with the following -id, which we get by greping window information obtained by xwininfo"

dont execute command just add it to history as a comment, handy if your command is not "complete" yet

list files recursively by size

Get the IP address
gives u each configured IP in a seperate line.


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: