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

show all established tcp connections on os x

List all files in current dir and subdirs sorted by size
or $ tree -ifsF --noreport .|sort -n -k2|grep -v '/$' (rows presenting directory names become hidden)

Recover tmp flash videos (deleted immediately by the browser plugin)
Newer versions of the flashplayer browser plugin delete the tmp flash video immediately after opening a filehandle to prevent the user from "exporting" the video by simply copying the /tmp/FlashXYZ file. This command searches such deleted flash videos and creates symbolic links to the opened filehandle with the same name as the deleted file. This allows you to play your flash-videos (from e.g. youtube) with e.g. mplayer or copy the buffered video if you want to keep it.

Find where a kind of file is stored
In this case searches for where .desktop files are stored. The resulted is a sorted list of the top directories containing such files.

Split a large file, without wasting disk space
It's common to want to split up large files and the usual method is to use split(1). If you have a 10GiB file, you'll need 10GiB of free space. Then the OS has to read 10GiB and write 10GiB (usually on the same filesystem). This takes AGES. . The command uses a set of loop block devices to create fake chunks, but without making any changes to the file. This means the file splitting is nearly instantaneous. The example creates a 1GiB file, then splits it into 16 x 64MiB chunks (/dev/loop0 .. loop15). . Note: This isn't a drop-in replacement for using split. The results are block devices. tar and zip won't do what you expect when given block devices. . These commands will work: $ hexdump /dev/loop4 . $ gzip -9 < /dev/loop6 > part6.gz . $ cat /dev/loop10 > /media/usb/part10.bin

Random number generation within a range N, here N=10

Find the most recent snapshot for an AWS EBS volume
Uses the python-based AWS CLI (https://aws.amazon.com/cli/) and the JSON query tool, JQ (https://stedolan.github.io/jq/)

FAST Search and Replace for Strings in all Files in Directory
I needed a way to search all files in a web directory that contained a certain string, and replace that string with another string. In the example, I am searching for "askapache" and replacing that string with "htaccess". I wanted this to happen as a cron job, and it was important that this happened as fast as possible while at the same time not hogging the CPU since the machine is a server. So this script uses the nice command to run the sh shell with the command, which makes the whole thing run with priority 19, meaning it won't hog CPU processing. And the -P5 option to the xargs command means it will run 5 separate grep and sed processes simultaneously, so this is much much faster than running a single grep or sed. You may want to do -P0 which is unlimited if you aren't worried about too many processes or if you don't have to deal with process killers in the bg. Also, the -m1 command to grep means stop grepping this file for matches after the first match, which also saves time.

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

GRUB2: set Super Mario as startup tune


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: