All commands (14,187)

  • Extremely useful to maintain backups if you're using Dropbox. This mirrors the entire directory structure and places symlinks in each to the original file. Instead of copying over the data again to the ~/Dropbox folder creating a symbolic link tree is much more sensible in terms of space usage. This has to be supplemented by another script that removes dead symlinks in the Dropbox folder which point to files that have been moved/removed. find -L ./ -type l -delete And then removing empty directories find ./ -type d -exec rmdir 2>/dev/null {} \; **Actually after some finding I found lndir which creates symbolic trees but it wasn't in the Arch repos so.. ;)


    0
    find /home/user/doc/ -type d -printf "mkdir -vp '/home/user/Dropbox%p'\n" -o -type f -printf "ln -vs '%p' '/home/user/Dropbox%p'\n" | sh
    jnash · 2009-03-29 09:25:12 23
  • Nice interface for an info page.


    1
    yelp info:foo
    renich · 2009-03-29 07:14:48 7
  • A great way of viewing some man page while using gnome.


    3
    yelp man:foo
    renich · 2009-03-29 07:13:44 8
  • This requires that your sudo not prompt for a password, as sftp cannot allocate the terminal necessary to ask.


    0
    sftp -s "sudo /usr/lib/sftp-server" user@host
    mrtheplague · 2009-03-29 07:02:58 6
  • Might be more useful if you were able to print it in Days HH:MM:SS format as: perl -e '@p=gmtime(234234);printf("%d Days %02d:%02d:%02ds\n",@p[7,2,1,0]);' But I'm not exactly sure how to replace the 234234 with the output of the countdown time. (Having some problems with nested quoting/command substitution). Help would be appreciated :)


    0
    watch --no-title -d -n 1 'echo `date -d "next Thursday" +%s` "-" `date +%s` | bc -l'
    jnash · 2009-03-29 06:53:09 9

  • 3
    dscacheutil -flushcache
    oarmas · 2009-03-29 06:17:32 5
  • Several times, I find myself hitting my up arrow, and changing the search term. Unfortunately, I find myself wasting too much time typing: grep kernel /var/log/messages Redirecting STDIN allows me to put the search term at the end so I less cursor movement to change what I'm searching for: < /var/log/messages grep kernel If you're using the emacs keyboard binding, then after you press your up arrow, press CTRL+w to erase the word. If this has already been submitted, I couldn't find it with the search utility.


    15
    < /path/to/file.txt grep foo
    atoponce · 2009-03-29 02:43:40 16
  • On Fedora clean the boot directory; erase older kernel


    1
    rpm -q kernel-2* | grep -v $(uname -r) | xargs yum erase -y
    Nick · 2009-03-28 21:41:15 11
  • Here is a command line to run on your server if you think your server is under attack. It prints our a list of open connections to your server and sorts them by amount. BSD Version: netstat -na |awk '{print $5}' |cut -d "." -f1,2,3,4 |sort |uniq -c |sort -nr Show Sample Output


    14
    netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n
    tiagofischer · 2009-03-28 21:02:26 73
  • This command is useful when you want to install the same packages on another fresh OS install for example. To do that, use: sudo dpkg --set-selections < LIST_FILE Show Sample Output


    11
    dpkg --get-selections > LIST_FILE
    o6291408 · 2009-03-28 17:45:29 12
  • Update a Mandriva Linux system with any pending updates. This command needs to be run with root privilege. Using the "--force" option answers "yes" to any interactive prompts thus allowing the updates to be left unattended to completion. NB if there is an update for glibc and/or a new kernel then the system would need to be rebooted for these to take effect. A prerequisite for running "urpmi --auto-update" is to have correctly defined urpmi media sources (which can be done by visiting http://easyurpmi.zarb.org/). If there are no new updates the the message "Packages are up to date" is shown. Show Sample Output


    0
    urpmi --auto-update --force # apply all pending updates (Mandriva Linux)
    mpb · 2009-03-28 14:59:26 8
  • I find this terribly useful for grepping through a file, looking for just a block of text. There's "grep -A # pattern file.txt" to see a specific number of lines following your pattern, but what if you want to see the whole block? Say, the output of "dmidecode" (as root): dmidecode | awk '/Battery/,/^$/' Will show me everything following the battery block up to the next block of text. Again, I find this extremely useful when I want to see whole blocks of text based on a pattern, and I don't care to see the rest of the data in output. This could be used against the '/etc/securetty/user' file on Unix to find the block of a specific user. It could be used against VirtualHosts or Directories on Apache to find specific definitions. The scenarios go on for any text formatted in a block fashion. Very handy.


    94
    awk '/start_pattern/,/stop_pattern/' file.txt
    atoponce · 2009-03-28 14:28:59 26
  • Packages: gmailfs fuse-utils libfuse2 gvfs-fuse Config files: /etc/gmailfs/gmailfs.conf; ~/.gmailfs.conf (make a copy from the another one) Unmount: fusermount -u /mount/path/ /etc/fstab (Optional): none /mount/path/ gmailfs noauto,user[,username=USERNAME,password=PASSWORD,fsname=VOLUME] 0 0 NOTES: - The options between [] are optional since they already setuped on the config files. - The '-p' flag shows a prompt for the password entry. - It's necessary to add the user to the 'fuse' group. You can do that with: sudo chgrp fuse /dev/fuse and sudo usermod -a -G fuse USER - The volume name is not needed but highly recommended to avoid file corruption. Also choose a non-trivial name. - Google doesn't approve the use of Gmail account other than e-mail purposes. So, I recommend the creation of a new account for this.


    5
    mount.gmailfs none /mount/path/ [-o username=USERNAME[,password=PASSWORD][,fsname=VOLUME]] [-p]
    o6291408 · 2009-03-28 13:00:47 5
  • Perform a dns zone transfer (if is allowed on target dns server) and print result.


    0
    host -la domain.com
    servermanaged · 2009-03-28 12:15:16 5
  • See: "man pwgen" for full details. Some Linux distros may not have pwgen included in the base distribution so you maye have to install it (eg in Mandriva Linux: "urpmi pwgen"). Show Sample Output


    6
    pwgen
    mpb · 2009-03-28 11:43:21 5
  • To install a theme use: sudo firefox -install-global-theme /path/to/theme You can get the .xpi or .jar file from the versions history on the add-on/theme page. NOTE: may not work in your system (Debian-based is an example).


    17
    sudo firefox -install-global-extension /path/to/add-on
    o6291408 · 2009-03-28 11:11:12 9
  • Not so useful. Just a cool feature.


    7
    mplayer -vo aa <video file>
    o6291408 · 2009-03-28 10:01:56 9
  • The download content part. NOTE: the '-c' seems to not work very well and the download stuck at 99% sometimes. Just finish wget with no problem. Also, the download may restart after complete. You can also cancel. I don't know if it is a wget or Rapidshare glitch since I don't have problems with Megaupload, for example. UPDATE: as pointed by roebek the restart glitch can be solved by the "-t 1" option. Thanks a lot.


    6
    wget -c -t 1 --load-cookies ~/.cookies/rapidshare <URL>
    o6291408 · 2009-03-28 09:13:35 5
  • In order to do that, first you need to save a cookie file with your account info. These commands do it (maybe you need to create the '.cookies' dir before). Also, you need to check the "Direct downloads" option on the Premium Zone >> Settings tab. You need to do this once (as long you maintain the file or your Rapidshare Premium account).


    4
    wget --save-cookies ~/.cookies/rapidshare --post-data "login=USERNAME&password=PASSWORD" -O - https://ssl.rapidshare.com/cgi-bin/premiumzone.cgi > /dev/null
    o6291408 · 2009-03-28 09:12:02 7
  • A great password generation tool. http://www.adel.nursat.kz/apg/ Show Sample Output


    3
    apg -a 0 -n 10
    renich · 2009-03-28 08:52:59 8
  • Within vi allow to empty a text file in one shot


    3
    :1,$d
    acirulli · 2009-03-28 02:28:19 12
  • The vi key sequence !}command will send the file contents from the cursor to the next blank line as STDOUT to the command specified and replace that sequence of file lines with the output of the command. For example: sorting a block of data - !}sort The sequence !{command will do the same but "upwards" (from the current position towards the start of the file. Show Sample Output


    12
    !}sort
    mpb · 2009-03-28 00:18:39 11

  • -13
    chmod +x FILES
    colinpj · 2009-03-27 23:28:40 5

  • -4
    sudo chmod -R g=u-w,g+X *
    mudiarto · 2009-03-27 23:27:12 5
  • head by default displays first ten lines of its output. Use 'head -nXX' to display the XX largest files


    -4
    ls -Sl * | head
    colinpj · 2009-03-27 23:20:32 7
  • ‹ First  < 509 510 511 512 513 >  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

Functions to display, save and restore $IFS
You can display, save and restore the value of $IFS using conventional Bash commands, but these functions, which you can add to your ~/.bashrc file make it really easy. To display $IFS use the function ifs shown above. In the sample output, you can see that it displays the characters and their hexadecimal equivalent. This function saves it in a variable called $saveIFS: $ sifs () { saveIFS=$IFS; } Use this function to restore it $ rifs () { IFS=$saveIFS; } Add this line in your ~/.bashrc file to save a readonly copy of $IFS: $ declare -r roIFS=$IFS Use this function to restore that one to $IFS $ rrifs () { IFS=$roIFS; }

Take a screenshot of the window the user clicks on and name the file the same as the window title
In general, this is actually not better than the "scrot -d4" command I'm listing it as an alternative to, so please don't vote it down for that. I'm adding this command because xwd (X window dumper) comes with X11, so it is already installed on your machine, whereas scrot probably is not. I've found xwd handy on boxen that I don't want to (or am not allowed to) install packages on. NOTE: The dd junk for renaming the file is completely optional. I just did that for fun and because it's interesting that xwd embeds the window title in its metadata. I probably should have just parsed the output from file(1) instead of cutting it out with dd(1), but this was more fun and less error prone. NOTE2: Many programs don't know what to do with an xwd format image file. You can convert it to something normal using NetPBM's xwdtopnm(1) or ImageMagick's convert(1). For example, this would work: "xwd | convert fd:0 foo.jpg". Of course, if you have ImageMagick already installed, you'd probably use import(1) instead of xwd. NOTE3: Xwd files can be viewed using the X Window UnDumper: "xwud <foo.xwd". ImageMagick and The GIMP can also read .xwd files. Strangely, eog(1) cannot. NOTE4: The sleep is not strictly necessary, I put it in there so that one has time to raise the window above any others before clicking on it.

follow the content of all files in a directory
The `-q' arg forces tail to not output the name of the current file

Get full from half remembered commands
Show all commands having the part known by you. Eg: $apropos pdf | less

sort a JSON blob
For situations where you keep JSON in a VCS and you want your diffs to be sane, such as within a Chef configuration repo.

Change prompt to MS-DOS one (joke)

pass the output of some command to a new email in the default email client
This depends on 'stripansi' and 'urlencode' commands, which exist on my system as these aliases: $ alias stripansi='perl -ple "s/\033\[(?:\d*(?:;\d+)*)*m//g;"' $ alias urlencode='perl -MURI::Escape -ne "\$/=\"\"; print uri_escape \$_"' The `open` command handles URLs on a Mac. Substitute the equivalent for your system (perhaps gnome-open). I don't use system `mail`, so I have this aliased as `mail` and use it this way: $ git show head | mail

github push-ing behind draconian proxies!
If you are behind a restrictive proxy/firewall that blocks port 22 connections but allows SSL on 443 (like most do) then you can still push changes to your github repository. Your .ssh/config file should contain: Host * ForwardX11 no TCPKeepAlive yes ProtocolKeepAlives 30 ProxyCommand /usr/local/bin/proxytunnel -v -p -d %h:443 Host User git Hostname ssh.github.com ChallengeResponseAuthentication yes IdentityFile ~/.ssh/id_rsa IdentitiesOnly yes Basically proxytunnel "tunnels" your ssh connection through port 443. You could also use corkscrew or some other tunneling program that is available in your distro's repository. PS: I generally use "github.com" as the SSH-HOST so that urls of the kind git@github.com:USER/REPO.git work transparently :) You

add a gpg key to aptitute package manager in a ubuntu system
when we add a new package to a aptitude (the debian package manager) we need to add the gpg, otherwise it will show warning / error for missing key

Prepare a commandlinefu command.
This command will format your alias or function to a single line, trimming duplicate white space and newlines and inserting delimiter semi-colons, so it continues to work on a single 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: