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

list block level layout

awk date convert
Convert readable date/time with `date` command

Alias TAIL for automatic smart output
Run the alias command, then issue $ps aux | tail and resize your terminal window (putty/console/hyperterm/xterm/etc) then issue the same command and you'll understand. $ ${LINES:-`tput lines 2>/dev/null||echo -n 12`} Insructs the shell that if LINES is not set or null to use the output from `tput lines` ( ncurses based terminal access ) to get the number of lines in your terminal. But furthermore, in case that doesn't work either, it will default to using the default of 80. The default for TAIL is to output the last 10 lines, this alias changes the default to output the last x lines instead, where x is the number of lines currently displayed on your terminal - 7. The -7 is there so that the top line displayed is the command you ran that used TAIL, ie the prompt. Depending on whether your PS1 and/or PROMPT_COMMAND output more than 1 line (mine is 3) you will want to increase from -2. So with my prompt being the following, I need -7, or - 5 if I only want to display the commandline at the top. ( http://www.askapache.com/linux/bash-power-prompt.html ) 275MB/748MB [7995:7993 - 0:186] 06:26:49 Thu Apr 08 [askapache@n1-backbone5:/dev/pts/0 +1] ~ $ In most shells the LINES variable is created automatically at login and updated when the terminal is resized (28 linux, 23/20 others for SIGWINCH) to contain the number of vertical lines that can fit in your terminal window. Because the alias doesn't hard-code the current LINES but relys on the $LINES variable, this is a dynamic alias that will always work on a tty device.

generate a unique and secure password for every website that you login to
usage: sitepass MaStErPaSsWoRd example.com description: An admittedly excessive amount of hashing, but this will give you a pretty secure password, It also eliminates repeated characters and deletes itself from your command history. tr '!-~' 'P-~!-O' # this bit is rot47, kinda like rot13 but more nerdy rev # this avoids the first few bytes of gzip payload, and the magic bytes.

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

View all images
So you are in directory with loads of pictures laying around and you need to quickly scan through them all

Renaming a file without overwiting an existing file name
Sometimes in a hurry you may move or copy a file using an already existent file name. If you aliased the cp and mv command with the -i option you are prompted for a confirmation before overwriting but if your aliases aren't there you will loose the target file! The -b option will force the mv command to check if the destination file already exists and if it is already there a backup copy with an ending ~ is created.

Extract the MBR ID of a device
Useful when you want to know the mbrid of a device - for the purpose of making it bootable. Certain hybridiso distros, for eg the OpenSUSE live ISO uses the mbrid to find the live media. Use this command to find out the mbrid of your USB drive and then edit the /grub/mbrid file to match it.

Convert CSV to JSON
Replace 'csv_file.csv' with your filename.

Find files that were modified by a given command
Traces the system calls of a program. See http://linuxhelp.blogspot.com/2006/05/strace-very-powerful-troubleshooting.html for more information.


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: