All commands (14,187)

  • Copy a file to a range of other files. Show Sample Output


    9
    for i in {1..5}; do cp test{,$i};done
    azeey · 2009-05-06 21:44:03 6

  • 4
    lsof -i | grep -i estab
    P17 · 2009-05-06 17:45:55 15
  • I have a bash alias for this command line and find it useful for searching C code for error messages. The -H tells grep to print the filename. you can omit the -i to match the case exactly or keep the -i for case-insensitive matching. This find command find all .c and .h files Show Sample Output


    33
    find . -name "*.[ch]" -exec grep -i -H "search pharse" {} \;
    bunedoggle · 2009-05-06 15:22:49 26
  • Aureport is a tool for displaying auditd system log. -x options cause to display launched executable on system. Aureport work with auditd so auditd must be installed an running on a system. Tested on CentOS / Debian Show Sample Output


    1
    aureport -x
    servermanaged · 2009-05-06 11:42:12 4
  • Please take notice that if you are going to use an JPG file for shadow effect, let change -background none to -background white! Because -background none make a transparent effect while JPG doesn't support transparent! And when viewing, you will get a bacl box! So we will use an white background under! We can use other color as well!


    7
    convert {$file_in} \( +clone -background black -shadow 60x5+10+10 \) +swap -background none -layers merge +repage {$file_out}
    kureikain · 2009-05-06 10:19:39 13
  • rotate: the rotate angle width, $height: width and height to scale to birghtness: change brighness


    4
    convert -rotate $rotate -scale $Widthx$Height -modulate $brightness -contrast $contrast -colorize $red%,$green%,$blue% $filter file_in.png file_out.png
    kureikain · 2009-05-06 10:14:22 4
  • The colors are defined as variables. e.g. RED="\[\033[01;31m\]" BLUE="\[\033[01;34m\]" Show Sample Output


    -3
    PS1="$BLUE[$CYAN\u$BLUE@$CYAN\h$WHITE-bash \v:$GREEN\w$BLUE]$WHITE \$ "
    P17 · 2009-05-06 08:01:06 6

  • 5
    ip route show dev ppp0 | awk '{ print $7 }'
    williamruckman · 2009-05-06 02:07:57 7
  • Runs an instance of screen with name of "name_me" and command of "echo "hi"" To reconnect to screen instance later use: screen -r name_me


    3
    screen -dmS "name_me" echo "hi"
    williamruckman · 2009-05-06 02:04:15 4
  • While I love gpg and truecrypt there's some times when you just want to edit a file and not worry about keys or having to deal needing extra software on hand. Thus, you can use vim's encrypted file format. For more info on vim's encrypted files visit: http://www.vim.org/htmldoc/editing.html#encryption Show Sample Output


    88
    vim -x <FILENAME>
    denzuko · 2009-05-05 23:24:17 28
  • This prints a summary of your referers from your logs as long as they occurred a certain number of times (in this case 500). The grep command excludes the terms, I add this in to remove results Im not interested in. Show Sample Output


    1
    awk -F\" '{print $4}' *.log | grep -v "eviljaymz\|\-" | sort | uniq -c | awk -F\ '{ if($1>500) print $1,$2;}' | sort -n
    jaymzcd · 2009-05-05 22:21:04 4
  • I use this (well I normally just drop the F=*.log bit and put that straight into the awk command) to count how many times I get referred from another site. I know its rough, its to give me an idea where any posts I make are ending up. The reason I do the Q="query" bit is because I often want to check another domain quickly and its quick to use CTRL+A to jump to the start and then CTRL+F to move forward the 3 steps to change the grep query. (I find this easier than moving backwards because if you group a lot of domains with the pipe your command line can get quite messy so its normally easier to have it all at the front so you just have to edit it & hit enter). For people new to the shell it does the following. The Q and F equals bits just make names we can refer to. The awk -F\" '{print $4}' $F reads the file specified by $F and splits it up using double-quotes. It prints out the fourth column for egrep to work on. The 4th column in the log is the referer domain. egrep then matches our query against this list from awk. Finally wc -l gives us the total number of lines (i.e. matches). Show Sample Output


    0
    Q="reddit|digg"; F=*.log; awk -F\" '{print $4}' $F | egrep $Q | wc -l
    jaymzcd · 2009-05-05 21:51:16 6
  • there is no explicit find command in DOS you can create a batch file with this one and find all jpegs on the C drive ... note: if creating a batch file "find.bat" the syntax changes to: for %%f in (c) do dir %%f:\%1 /s /p you can then use find *.jpg Show Sample Output


    -5
    for %f in (c) do dir %f:\*.jpg /s /p
    copremesis · 2009-05-05 18:28:18 11
  • It's like `prstat -t` under Solaris Show Sample Output


    1
    ps -eo user,pcpu,pmem | tail -n +2 | awk '{num[$1]++; cpu[$1] += $2; mem[$1] += $3} END{printf("NPROC\tUSER\tCPU\tMEM\n"); for (user in cpu) printf("%d\t%s\t%.2f%\t%.2f%\n",num[user], user, cpu[user], mem[user]) }'
    feraudet · 2009-05-05 16:54:25 4
  • Reads in the ~/.Xdefaults lexicographically sorted with, instead of replacing, the current contents of the specified properties.


    0
    alias xdef_load='xrdb -merge ~/.Xdefaults'
    P17 · 2009-05-05 16:34:06 8

  • -9
    alias b='cd -'
    P17 · 2009-05-05 16:21:22 6
  • Since bash 4.0, you can use ** to recursively expand to all files in the current directory. This behaviour is disabled by default, this command enables it (you'd best put it in your .profile). See the sample output for clarification. In my opinion this is much better than creating hacks with find and xargs when you want to pass files to an application. Show Sample Output


    11
    shopt -s globstar
    Alanceil · 2009-05-05 16:02:44 8
  • You can use this on your session login.


    6
    VBoxManage startvm "name"
    o6291408 · 2009-05-05 13:23:26 6
  • Simple but useful command, I use this for purge an hard disk entry in Virtualbox registry file (is in ~user/.Virtualbox) that persist if I erase a Virtual Machine, so I need to delete it manually.


    -3
    sed -i '/Centos/d' VirtualBox.xml
    servermanaged · 2009-05-05 13:03:55 6
  • This is the alias command that I discussed in my prior release which you can add to your ~/.bashrc. This command asks for the station name and then connects to somafm, Great for those who have linux home entertainment boxes and ssh enabled on them, just for the CLI fiends out there ( I know I'm one of them ;) You can find future releases of this and many more scripts at the teachings of master denzuko - denzuko.co.cc.


    -2
    alias somafm='read -p "Which station? "; mplayer --reallyquiet -vo none -ao sdl http://somafm.com/startstream=${REPLY}.pls'
    denzuko · 2009-05-05 12:13:46 3
  • This is a working version, though probably clumsy, of the script submitted by felix001. This works on ubuntu and CygWin. This would be great as a bash function, defined in .bashrc. Additionally it would work as a script put in the path. Show Sample Output


    0
    lynx -dump randomfunfacts.com | grep -A 3 U | sed 1D
    xizdaqrian · 2009-05-05 07:52:10 12
  • This command might not be useful for most of us, I just wanted to share it to show power of command line. Download simple text version of novel David Copperfield from Poject Gutenberg and then generate a single column of words after which occurences of each word is counted by sort | uniq -c combination. This command removes numbers and single characters from count. I'm sure you can write a shorter version. Show Sample Output


    -4
    wget -q -O- http://www.gutenberg.org/dirs/etext96/cprfd10.txt | sed '1,419d' | tr "\n" " " | tr " " "\n" | perl -lpe 's/\W//g;$_=lc($_)' | grep "^[a-z]" | awk 'length > 1' | sort | uniq -c | awk '{print $2"\t"$1}'
    alperyilmaz · 2009-05-04 16:00:39 11
  • This command is useful if you accidentally untar or unzip an archive in a directory and you want to automatically remove the files. Just untar the files again in a subdirectory and then run the above command e.g. for file in ~/Desktop/temp/*; do rm ~/Desktop/`basename $file`; done


    11
    for file in <directory A>/*; do rm <directory B>/`basename $file`; done
    jamiebullock · 2009-05-04 12:44:50 14
  • Retrieve the current stock price from Yahoo Finance. The output is simply the latest price (which could be delayed). If you want to look up stock for a different company, replace csco with your symbol. Show Sample Output


    11
    curl -s 'http://download.finance.yahoo.com/d/quotes.csv?s=csco&f=l1'
    haivu · 2009-05-04 08:13:59 28
  • The nl command lists the contents of a file where is each line is prefixed by a line number. For more information about this command, check out its man page. I tested under Mac OS X and Xubuntu 9.04


    -2
    nl filename | more
    haivu · 2009-05-04 07:35:16 11
  • ‹ First  < 497 498 499 500 501 >  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

Multi-thread any command
For instance: $ find . -type f -name '*.wav' -print0 |xargs -0 -P 3 -n 1 flac -V8 will encode all .wav files into FLAC in parallel. Explanation of xargs flags: -P [max-procs]: Max number of invocations to run at once. Set to 0 to run all at once [potentially dangerous re: excessive RAM usage]. -n [max-args]: Max number of arguments from the list to send to each invocation. -0: Stdin is a null-terminated list. I use xargs to build parallel-processing frameworks into my scripts like the one here: http://pastebin.com/1GvcifYa

lazy SQL QUERYING
alias for psql command line; works similar for Oracles sqlplus commandline interface. if you do not provide stdin you will end up in the db shell.

Create a video that is supported by youtube
Takes an mpeg video and coverts it to a youtube compatible flv file. The -r 25 sets the frame rate for PAL, for NTSC use 29.97

Show a git log with offsets relative to HEAD
Print a git log (in reverse order) giving a reference relative to HEAD. HEAD (the current revision) can also be referred to as HEAD~0 The previous revision is HEAD~1 then HEAD~2 etc. . Add line numbers to the git output, starting at zero: $ ... | nl -v0 | ... . Insert the string 'HEAD~' before the number using sed: $ ... | sed 's/^ \+/&HEAD~/' . Thanks to bartonski for the idea :-)

Display a list of all PHP classes that are called statically
Searches all .php files for a static instantiation of a class and displays the class names along with their frequencies.

Dump dvd from a different machine onto this one.
You can use this to directly dump from machine A (with dvd drive) to machine B (without dvd drive) . I used this to copy dvd using my friend's machine to my netbook. Above command is to be issued on machine B. Advantages : 1) No wasting time dumping first to machine A and then copying to Machine B. 2) You dont need to use space on Machine A. In fact, this will work even when Machine A doesnt have enough hdd space to dump the DVD. Use -C ssh option on slow networks (enables compression). you can replace "dd if=/dev/dvd" with any ripping command as long as it spews the iso to stdout.

Get a metascore from metacritic.com
This will fetch a metascore from metacritic.com. It requires a url from metacritic without the http://www.metacritic.com/ Example: $ metascore games/platforms/wii/supermariogalaxy - $ metascore tv/shows/marriageref - $ metascore video/titles/newmoon Would be cool to use this in some sort of a graph.

Get the dir listing of an executable without knowing its location

show the real times iso of epochs for a given column
When you have one of those (log)files that only has epoch for time (since no one will ever look at them as a date) this is a way to get the human readable date/time and do further inspection. Mostly perl-fu :-/

My PS1
My PS1


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: