All commands (13,009)

  • List all text files in the current directory.


    0
    find . | xargs file | grep ".*: .* text" | sed "s;\(.*\): .* text.*;\1;"
    matthewbauer · 2009-09-22 01:50:25 1
  • The backtick operator, in general, will execute the text inside the backticks. On OS X, the pbpaste command will put the contents of the OS X clipboard to STDOUT. So if you put backticks around pbpaste, the text from the OS X clipboard is executed. If you add the pipeline | pbcopy, the output from executing the command on the clipboard is placed back on the clipboard. Note: make sure the clipboard is text only. Show Sample Output


    7
    `pbpaste` | pbcopy
    drewk · 2009-09-21 23:10:11 3
  • This pipeline will find, sort and display all files based on mtime. This could be done with find | xargs, but the find | xargs pipeline will not produce correct results if the results of find are greater than xargs command line buffer. If the xargs buffer fills, xargs processes the find results in more than one batch which is not compatible with sorting. Note the "-print0" on find and "-0" switch for perl. This is the equivalent of using xargs. Don't you love perl? Note that this pipeline can be easily modified to any data produced by perl's stat operator. eg, you could sort on size, hard links, creation time, etc. Look at stat and just change the '9' to what you want. Changing the '9' to a '7' for example will sort by file size. A '3' sorts by number of links.... Use head and tail at the end of the pipeline to get oldest files or most recent. Use awk or perl -wnla for further processing. Since there is a tab between the two fields, it is very easy to process. Show Sample Output


    3
    find $HOME -type f -print0 | perl -0 -wn -e '@f=<>; foreach $file (@f){ (@el)=(stat($file)); push @el, $file; push @files,[ @el ];} @o=sort{$a->[9]<=>$b->[9]} @files; for $i (0..$#o){print scalar localtime($o[$i][9]), "\t$o[$i][-1]\n";}'|tail
    drewk · 2009-09-21 22:11:16 4
  • inputfile.txt is a space-separated textfile, 1st column contains the items (id) I want to put into my SQL statement. 39 = charactercode for single tick ' 1 = first column If inputfile.txt is a CSV-file separated by "," use FS= to define your own field-separator: awk 'BEGIN {FS=","; }{printf "select * from table where id = %c%s%c;\n",39,$1,39; }' inputfile.txt Show Sample Output


    2
    $ awk '{printf "select * from table where id = %c%s%c;\n",39,$1,39; }' inputfile.txt
    alvinx · 2009-09-21 14:08:04 0
  • this is funny ;) alias sl="ls" ... is the useful solution, but that's boring ;P and You won't learn to think before You type !


    0
    apt-get install sl; sl
    alvinx · 2009-09-21 13:55:24 0
  • if "mail -a" fail, try "mutt -a" or "nail -a"


    1
    echo "see attached file" | mail -a filename -s "subject" email@address
    gnpf · 2009-09-21 11:58:49 1
  • Create subtitle file heading.ssa with just one entry for the entire video duration. Command line sets that entry's text on top of the video as text watermark. If text is an URL works nice for sending people back to your site from a YouTube clip. Output file is lossless encoded and suitable for further processing. Subtitle file can be a URL so it's saved remotely.


    0
    mencoder -sub heading.ssa -subpos 0 -subfont-text-scale 4 -utf8 -oac mp3lame -lameopts cbr=128 -ovc lavc -lavcopts vcodec=mjpeg -vf scale=320:-2,expand=:240:::1 -o output.avi input.flv
    ivalladt · 2009-09-21 11:56:55 0
  • Very useful in shell scripts because you can run a task nicely in the background using job-control and output progress until it completes. Here's an example of how I use it in backup scripts to run gpg in the background to encrypt an archive file (which I create in this same way). $! is the process ID of the last run command, which is saved here as the variable PI, then sleeper is called with the process id of the gpg task (PI), and sleeper is also specified to output : instead of the default . every 3 seconds instead of the default 1. So a shorter version would be sleeper $!; The wait is also used here, though it may not be needed on your system. echo ">>> ENCRYPTING SQL BACKUP" gpg --output archive.tgz.asc --encrypt archive.tgz 1>/dev/null & PI=$!; sleeper $PI ":" 3; wait $PI && rm archive.tgz &>/dev/null Previously to get around the $! not always being available, I would instead check for the existance of the process ID by checking if the directory /proc/$PID existed, but not everyone uses proc anymore. That version is currently the one at http://www.askapache.com/linux-unix/bash_profile-functions-advanced-shell.html but I plan on upgrading to this new version soon. Show Sample Output


    13
    sleeper(){ while `ps -p $1 &>/dev/null`; do echo -n "${2:-.}"; sleep ${3:-1}; done; }; export -f sleeper
    AskApache · 2009-09-21 07:36:25 1
  • I was looking for the fastest way to create a bunch of ansi escapes for use in echo -e commands throughout a lot of my shell scripts. This is what I came up with, and I actually stick that loop command in a function and then just call that at the beginning of my scripts to not clutter the environment with these escape codes, which can wreck havok on my terminal when I'm dumping the environment. More of a cool way to store escape ansi codes in an array. You can echo them like: echo -e "${CC[15]}This text is black on bright green background." I usually just use with a function: # setup_colors - Adds colors to array CC for global use # 30 - Black, 31 - Red, 32 - Green, 33 - Yellow, 34 - Blue, 35 - Magenta, 36 - Blue/Green, 37 - White, 30/42 - Black on Green '30\;42' function setup_colors(){ declare -ax CC; for i in `seq 0 7`;do ii=$(($i+7));CC[$i]="\033[1;3${i}m";CC[$ii]="\033[0;3${i}m";done;CC[15]="\033[30;42m"; export R='\033[0;00m';export X="\033[1;37m"; }; export -f setup_colors CC[15] has a background of bright green which is why it is separate. R resets everything, and X is my default font of bright white. CC[15]="\033[30;42m"; R=$'\033[0;00m'; X=$'\033[1;37m' Those are just my favorite colors that I often use in my scripts. You can test which colors by running for i in $(seq 0 $((${#CC[@]} - 1))); do echo -e "${CC[$i]}[$i]\n$R"; done See: http://www.askapache.com/linux-unix/bash_profile-functions-advanced-shell.html for more usage. Show Sample Output


    1
    declare -ax CC; for i in `seq 0 7`;do ii=$(($i+7)); CC[$i]="\033[1;3${i}m"; CC[$ii]="\033[0;3${i}m"; done
    AskApache · 2009-09-21 07:00:55 4
  • uuencode the file to appear as an attachment


    0
    cat filename | uuencode filename | mail -s "Email subject" user@example.com
    amaymon · 2009-09-21 04:13:50 6
  • This dup finder saves time by comparing size first, then md5sum, it doesn't delete anything, just lists them.


    73
    find -not -empty -type f -printf "%s\n" | sort -rn | uniq -d | xargs -I{} -n1 find -type f -size {}c -print0 | xargs -0 md5sum | sort | uniq -w32 --all-repeated=separate
    syssyphus · 2009-09-21 00:24:14 23
  • Using tape archive create a tar file in Stdout (-) and pipe that into a compound command to extract the tar file from Stdin at the destination. This similar to "Copy via tar pipe ...", but copies across file systems boundaries. I prefer to use cp -pr for copying within the same file system. Show Sample Output


    -2
    tar cpof - src |( cd des; tar xpof -)
    davidpotter42 · 2009-09-20 20:43:30 0
  • Replace D drive with mounted ISO virtual drive and Replace E with your USB drive letter.


    -3
    xcopy D:\*.* /s/e/f E:\
    eth0 · 2009-09-20 12:36:52 2
  • Change directory (cd) to the directory where all your encrypted files are placed, and then run the command - then you are asked to insert your secret gpg password - ubuntu 8.04


    1
    gpg --allow-multiple-messages --decrypt-files *
    bkn390 · 2009-09-20 11:50:41 0
  • worked on ubuntu 9.04 and cygwin with MS netstat Show Sample Output


    3
    netstat -an | awk '$1 ~ /[Tt][Cc][Pp]/ && $NF ~ /ESTABLISHED/{i++}END{print "Connected:\t", i}'
    twfcc · 2009-09-20 08:19:27 0
  • Searches backwards through your command-history for the typed text. Repeatedly hitting Ctrl-R will search progressively further. Return invokes the command. Show Sample Output


    14
    Ctrl-R <search-text>
    tarkasteve · 2009-09-20 05:07:31 1

  • 0
    xmms2 mlib search added \> $(echo $(date +%s) - 604800|bc)
    unixmonkey6280 · 2009-09-20 04:00:37 0
  • This just reads in a local file and sends it via email. Works with text or binary. *Requires* local mail server.


    2
    cat filename | mail -s "Email subject" user@example.com
    topher1kenobe · 2009-09-20 01:38:23 0
  • 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" Show Sample Output


    2
    xev -id `xwininfo | grep 'Window id' | awk '{print $4}'`
    ktoso · 2009-09-19 22:47:16 0
  • for one line per process: ss -p | cat for established sockets only: ss -p | grep STA for just process names: ss -p | cut -f2 -sd\" or ss -p | grep STA | cut -f2 -d\"


    51
    ss -p
    Escher · 2009-09-19 21:55:01 0

  • 5
    seq -s " " -w 3 20
    edo · 2009-09-19 21:26:57 2
  • This will log your internet download speed. You can run gnuplot -persist <(echo "plot 'bps' with lines") to get a graph of it.


    9
    echo $(date +%s) > start-time; URL=http://www.google.com; while true; do echo $(curl -L --w %{speed_download} -o/dev/null -s $URL) >> bps; sleep 10; done &
    matthewbauer · 2009-09-19 21:26:06 0
  • show only the name of the apps that are using internet Show Sample Output


    31
    lsof -P -i -n | cut -f 1 -d " "| uniq | tail -n +2
    edo · 2009-09-19 21:23:54 2

  • 87
    lsof -P -i -n
    OJM · 2009-09-19 18:28:48 1
  • I often need to know of my directory in the PATH, which one DOES NOT exist. This command answers that question * This command uses only bash's built-in commands * The parentheses spawn a new sub shell to prevent the modification of the IFS (input field separator) variable in the current shell


    9
    (IFS=:;for p in $PATH; do test -d $p || echo $p; done)
    haivu · 2009-09-19 17:51:06 1
  • ‹ First  < 398 399 400 401 402 >  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



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: