All commands (14,187)


  • -4
    tar -C <source_dir> -cf . | tar -C <dest_dir> -xf
    Tekhne · 2009-07-08 22:19:04 6

  • -4
    :!>test.txt
    amaymon · 2009-08-19 13:45:23 4
  • It will return the absolute location of the called a script. If is in $PATH, it will search it using which. You can combine this function with this other one: http://www.commandlinefu.com/commands/view/9252/readlink-equivalent-using-shell-commands-and-following-all-links, to get a way to know where is the real location of a called script: # Returns the realpath of a called command. whereis_realpath() { local SCRIPT_PATH=$(whereis $1); myreadlink ${SCRIPT_PATH} | sed "s|^\([^/].*\)\$|$(dirname ${SCRIPT_PATH})/\1|"; } Show Sample Output


    -4
    get_absolute_path() { echo $1 | sed "s|^\([^/].*/.*\)|$(pwd)/\1|;s|^\([^/]*\)$|$(which -- $1)|;s|^$|$1|"; }
    keymon · 2011-09-13 11:06:55 6

  • -4
    ip a
    huazhihao · 2012-09-20 01:44:58 5

  • -4
    perl -e 'print crypt("PASSWORD",int(rand(128))).$/;'
    cicatriz · 2010-09-30 12:58:39 3
  • 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
  • It extracts X number of lines from file1 and dumps them to file2.Using grep with the empty string '' extracts the complete lines (i.e. no filtering takes place) and the -m flag indicates how many lines to extract out from the given file. Then using the redirect > operator we send the extracted lines to a new file.


    -4
    grep '' -m X file1 > file2
    sardanapalos · 2009-03-22 04:34:43 17
  • See smbstatus Output within a 5 second interval (for monitoring smb access)


    -4
    while (( $i != 0 )) { smbstatus; sleep 5; clear }
    unixmonkey4084 · 2009-06-03 13:26:30 9
  • After a command is run in bash, !$ is set to the last (space-delimited) argument of the command. Great for running several commands against the same file in a row.


    -4
    svn status app/models/foo.rb; svn commit -m "Changed file" !$
    ggoodale · 2009-03-22 23:14:06 5

  • -4
    sh default values
    rootgeek · 2010-03-26 02:36:57 4
  • # define user pid to kill PID=httpd ; # kill all pids ps aux | grep $PID | grep -v grep | awk '{print $2}' | xargs kill -9 Show Sample Output


    -4
    PID=httpd ; ps aux | grep $PID | grep -v grep | awk '{print $2}' | xargs kill -9
    esaenz · 2012-02-21 23:27:47 6
  • I use these command to validate twitter accounts, we can use a "for a in $(cat list.txt)" to validate a complete list of twitter accounts.


    -4
    if lynx --dump http://twitter.com/xmuda | grep -q "Sorry, that page does"; then echo "Dont Exist"; else echo "Exist"; fi
    xmuda · 2013-03-23 16:12:24 4
  • The sample output, is the command with a ?, to show you all the stuff you can look at. Show Sample Output


    -4
    dm ?
    rootgeek · 2010-03-26 02:42:21 3

  • -4
    Place a filename at the beginning of the line to make it easier to edit the search at the end of the command.
    iveney · 2009-02-07 12:03:19 12

  • -4
    alias w3m='w3m -cookie'
    freestyler · 2009-07-09 09:01:55 4
  • This command marks it as "dirty" NTFS partition, forcing Windows to do the scandisk during boot. It is convenient if you work hard to NTFS partitions under Linux


    -4
    ntfsfix /dev/hda1
    0disse0 · 2011-07-02 17:49:48 3
  • changes the PS1 to something better than default. [username.hostname.last-2-digits-of-ip] (current directory) Show Sample Output


    -4
    newhostname=$(hostname | awk -F. '{print $1 "." $2}'); ipaddress=$(nslookup `hostname` | grep -i address | awk -F" " '{print $2}' | awk -F. '{print $3 "." $4}' | grep -v 64.142);PS1="[`id -un`.$newhostname.$ipaddress]"' (${PWD}): '; export PS1
    simardd · 2009-02-16 20:11:53 8
  • I have come across multiple situations where I could only get to a server from a very restrictive bounce point which would not allow file transfers. I was able to uuencode a file, copy the output to a text file over putty, and then uudecode the file to transfer it. This works with any kind of file. Show Sample Output


    -4
    uuencode -m <filename> <filename>
    leprasmurf · 2009-12-22 15:28:59 3

  • -4
    grep --exclude-dir=.svn --exclude=*~ -i "TODO" -rl .
    saibbot · 2011-04-06 20:25:41 5
  • deletes first 55 lines; change the 55 to whatever number


    -4
    sed '1,55d'
    grep · 2009-02-16 20:36:25 8
  • On Linux and Mac systems (I have not tested with other Unix systems), the ping command will keep on pinging until the user interrupts it with Ctrl+C. On Windows system, ping will execute for a number of times then quit. The -c flag on Linux and Mac will make this happen


    -4
    ping -c 10 hostname
    haivu · 2009-03-04 06:14:52 6
  • This is based on the Windows Version of VirtualBox. From the /? ... VBoxManage clonehd | [--format VDI|VMDK|VHD|RAW|] [--variant Standard,Fixed,Split2G,Stream,ESX] [--type normal|writethrough|immutable|shareable] [--remember] [--existing] From the online help.. http://www.virtualbox.org/manual/ch08.html#id2676537 VBoxManage clonehd This command duplicates a registered virtual hard disk image to a new image file with a new unique identifier (UUID). The new image can be transferred to another host system or imported into VirtualBox again using the Virtual Media Manager; see the section called ?The Virtual Media Manager? and the section called ?Cloning disk images?. The syntax is as follows: VBoxManage clonehd | [--format VDI|VMDK|VHD|RAW|] [--variant Standard,Fixed,Split2G,Stream,ESX] [--type normal|writethrough|immutable] [--remember] where the parameters mean: format Allow to choose a file format for the output file different from the file format of the input file. variant Allow to choose a file format variant for the output file. It is a comma-separated list of variant flags. Not all combinations are supported, and specifying inconsistent flags will result in an error message. type Only honored if --remember is also specified. Defines what kind of hard disk type this image should be. remember Keep the destination image registered after it was successfully written. Show Sample Output


    -4
    vboxmanage clonehd --format VMDK <source image|uuid> <destination image>
    dreffed · 2010-10-04 16:42:12 3

  • -4
    find . -name \*.pyc -delete
    zluyuer · 2016-09-07 01:49:59 17
  • Easy way to find out what Debian version your machine is running Show Sample Output


    -4
    cat /etc/debian_version
    caiosba · 2009-08-05 14:47:05 5
  • netstat has two lines of headers: Active Internet connections (w/o servers) Proto Recv-Q Send-Q Local Address Foreign Address State Added a filter in the awk command to remove them


    -4
    netstat -ntu | awk ' $5 ~ /^[0-9]/ {print $5}' | cut -d: -f1 | sort | uniq -c | sort -n
    letterj · 2011-07-04 20:23:21 8
  • ‹ First  < 539 540 541 542 543 >  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

put current directory in LAN quickly

sed /pat/!d without using sed (no RE; limited to shell patterns aka globbing)
POSIX requires this "string truncating" functionality. might as well use it, at least for very small tasks where invoking sed and using RE is overkill.

find and delete empty dirs, start in current working dir

Get AWS temporary credentials ready to export based on a MFA virtual appliance
You might want to secure your AWS operations requiring to use a MFA token. But then to use API or tools, you need to pass credentials generated with a MFA token. This commands asks you for the MFA code and retrieves these credentials using AWS Cli. To print the exports, you can use: `awk '{ print "export AWS_ACCESS_KEY_ID=\"" $1 "\"\n" "export AWS_SECRET_ACCESS_KEY=\"" $2 "\"\n" "export AWS_SESSION_TOKEN=\"" $3 "\"" }'` You must adapt the command line to include: * $MFA_IDis ARN of the virtual MFA or serial number of the physical one * TTL for the credentials

check the filesystem and use a progress bar
if you happen to start with out the -C switch then you a killall -USR1 e2fsck

Auto Get Missing Launchpad Keys
You can choose these mirror servers to get gpg keys, if the official one ever goes offline keyserver.ubuntu.com pool.sks-keyservers.net subkeys.pgp.net pgp.mit.edu keys.nayr.net keys.gnupg.net wwwkeys.en.pgp.net #(replace with your country code fr, en, de,etc)

Start dd and show progress every X seconds

find and replace tabs for spaces within files recursively

strip non-constant number of directories from tar archive while decompressing
If you want to decompress the files from an archive to current directory by stripping all directory paths, use --transform option to strip path information. Unfortunately, --strip-components option is good if the target files have same and constant depth of folders. The idea was taken from http://www.unix.com/solaris/145941-how-extract-files-tar-file-without-creating-directories.html

Convert seconds into minutes and seconds
This is a very simple way to input a large number of seconds and get a more useful value in minutes and seconds.


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: