What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again.

Delete that bloated snippets file you've been using and share your personal repository with the world. 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.

Get involved!

You can sign-in using OpenID credentials, or register a traditional username and password.

First-time OpenID users will be automatically assigned a username which can be changed after signing in.

Universal configuration monitoring and system of record for IT.

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:



May 19, 2015 - A Look At The New Commandlinefu
I've put together a short writeup on what kind of newness you can expect from the next iteration of clfu. Check it out here.
March 2, 2015 - New Management
I'm Jon, I'll be maintaining and improving clfu. Thanks to David for building such a great resource!

Top Tags





Maintained by Jon H.

Site originally by David Winterbottom (user root).

Psst. Open beta.

Wow, didn't really expect you to read this far down. The latest iteration of the site is in open beta. It's a gentle open beta-- not in prime-time just yet. It's being hosted over at UpGuard (link) and you are more than welcome to give it a shot. Couple things:

  • » The open beta is running a copy of the database that will not carry over to the final version. Don't post anything you don't mind losing.
  • » If you wish to use your user account, you will probably need to reset your password.
Your feedback is appreciated via the form on the beta page. Thanks! -Jon & CLFU Team

Commands using cp from sorted by
Terminal - Commands using cp - 104 results
cp -r path/to/file/tree $(mkdir -p new/path/here; echo new/path/here)
2012-04-27 16:18:11
User: wirespeed
Functions: cp echo mkdir

You need to cp, mv, scp, ..., some files around from one place to another, and after having laboriously typed out the source path, you remember that the destination directory doesn't yet exist, and so the command will fail. So rather than killing the command line and starting over, just interpolate the results of creating the directory and echo its name. You could DRY this with a for; do; done, but that may be more trouble than it's worth.

find / -type f -name IMG_????.JPG -print0 |xargs -0 exiv2 -g Exif.Canon.ModelID '{}' |grep A520 |rev |cut --complement -d " " -f1-40 |rev |xargs -I {} cp --parents {} /where
2012-03-10 03:01:01
User: fladam
Functions: cp cut find grep rev xargs

You must spezify /where folder and / folder

If you have another camera you must experiment with Exif data (after -g and after grep) and mask of your photo files IMG_????.JPG

I have do it on Knoppix 6.7.0

You must have installed exiv2.

cp -auv /SorceDirectory/ /ParentDestination/
2012-03-04 13:04:03
User: joeseggiola
Functions: cp

Backup a whole directory copying only updated files.

lsof -n -P|grep FlashXX|awk '{ print "/proc/" $2 "/fd/" substr($4, 1, length($4)-1) }'|while read f;do newname=$(exiftool -FileModifyDate -FileType -t -d %Y%m%d%H%M%S $f|cut -f2|tr '\n' '.'|sed 's/\.$//');echo "$f -> $newname";cp $f ~/Vids/$newname;done
2012-02-25 01:49:45
User: mhs
Functions: awk cp cut echo grep read sed tr

Certain Flash video players (e.g. Youtube) write their video streams to disk in /tmp/ , but the files are unlinked. i.e. the player creates the file and then immediately deletes the filename (unlinking files in this way makes it hard to find them, and/or ensures their cleanup if the browser or plugin should crash etc.) But as long as the flash plugin's process runs, a file descriptor remains in its /proc/ hierarchy, from which we (and the player) still have access to the file. The method above worked nicely for me when I had 50 tabs open with Youtube videos and didn't want to have to re-download them all with some tool.

ldd file | grep "=> /" | awk '{print $3}' | xargs -I '{}' cp -v '{}' /destination
2012-02-11 17:50:10
User: rickard2
Functions: awk cp file grep ldd xargs

When working with jailed environments you need to copy all the shared libraries to your jail environment. This is done by running ldd on a binary which needs to run inside the jail. This command will use the output from ldd to automatically copy the shared libraries to a folder of your choice.

for FILE in `ls -1`; do if [ -L "$FILE" ]; then cp $(readlink "$FILE") ${FILE}_rf; rm -f $FILE; mv ${FILE}_rf "$FILE"; fi; done
cp -r * .??* /dest
2011-12-16 23:41:03
User: atoponce
Functions: cp
Tags: mv rm cp

You could do the following, however, brace expansion with {} is not defined in POSIX, and therefore not guaranteed to work in all shells. But, if it does, it's more convenient (although it's certainly not less typing):

cp -r {*,.??*} /dest

Sometimes there are times when I need to cp(1), mv(1) or rm(1) files recursively, but don't want to traverse the previous directory by following ../../../../ etc out of the current directory. This command prevents that. The secret sauce is ".??*". The file globbing ensures that it must start with a dot, and be followed by at least two characters. So, three characters must exist in the filename, which eliminates "." and "..".

cp -a /etc /destination
find <start directory> -iname "<all my files type>" -exec cp {} <target_dir> \;
cp /work/host/phone/ui/main.cpp !#$:s/host/target
2011-09-20 06:48:07
User: kev
Functions: cp
Tags: !!

expand to:

cp /work/host/phone/ui/main.cpp /work/target/phone/ui/main.cpp


The entire command line typed so far.

cp --sparse=always <SRC> <DST>
2011-09-07 08:02:50
User: h3xx
Functions: cp

This causes cp to detect and omit large blocks of nulls. Sparse files are useful for implying a lot of disk space without actually having to write it all out.


You can use it in a pipe too:

dd if=/dev/zero bs=1M count=5 |cp --sparse=always /dev/stdin SPARSE_FILE
cp -dpRx /* /mnt/target/
2011-08-22 14:22:01
Functions: cp

preserve all except context and xattr. useful when moving a running system to a new partition.

sedit() { cp "$*"{,.bk}; which $EDITOR > /dev/null && $EDITOR "$*" || vim "$*"; }
2011-08-16 18:28:22
User: kaedenn
Functions: cp vim which

Some people put spaces in filenames. Others have an $EDITOR environment variable set. This defaults to vim, but you can use whatever you wish: emacs, nano, ed, butterflies, etc.

cp httpd.conf{,.bk}
2011-08-15 16:43:53
User: ideivid
Functions: cp
Tags: backup cp

Remember to backup everything before changing it so you can restore all to normal.

cp /dev/cdrom file.iso
find ~ -name "*.ttf" -exec cp {} /usr/share/fonts/truetype \; & fc-cache -f
2011-05-25 20:18:33
User: scripteles
Functions: cp fc-cache find

1) Find true type fonts;

2) Copy them to /usr/share/fonts/truetype;

3) Reload font information.

for file in `find *| sort -n | sed 's% %?%g'`; do echo "${file//?/ }"; cp --parents "${file//?/ }" /destinity_folder/ ;done
v () { ( IFS=$'\n'; suf="_versions"; mkdir -p "$1$suf"; nr=`ls "$1$suf" | wc -l`; nr=`printf "%02d" $(($nr + 1))`; cp "$1" "$1$suf/v${nr}_$1" ) }
2011-04-22 07:33:51
User: dubnov
Functions: cp mkdir wc
Tags: bash copy

Bash function copies a file prefixed with a version number to a subdirectory

cp filename{,.`date +%Y%m%d`}
2011-04-02 06:41:26
Functions: cp
Tags: backup copy

This is a BASH feature.

The above command will create a backup of "filename" called "filename.DATE", where DATE is the actual day in %Y%m%d (year, month and day numbers together) format.

files -type f | xargs -n100 | while read l; do mkdir $((++f)); cp $l $f; done
2011-02-15 23:15:16
User: flatcap
Functions: cp mkdir read xargs

Take a folder full of files and split it into smaller folders containing a maximum number of files. In this case, 100 files per directory.

find creates the list of files

xargs breaks up the list into groups of 100

for each group, create a directory and copy in the files

Note: This command won't work if there is whitespace in the filenames (but then again, neither do the alternative commands :-)

find files/ -type f | while read line; do if [ $((i++%100)) -eq 0 ]; then mkdir $((++folder)); fi; cp $line $folder/; done
s=/etc/ssh/sshd_config;r=PermitRootLogin;cp $s{,.old}&& if grep $r $s;then sed "s/$r yes/$r no/" $s.old > $s; else echo $r no >> $s;fi
2011-01-30 23:41:59
User: kzh
Functions: cp echo grep sed
Tags: bash openssh

This will tighten up security for your box. The default value for PermitRootLogin sadly is 'yes'.

cp -i FILENAME{,.`date +%Y%m%d`}
buf() { cp -v $1 ${1/${1%%.*}/$f-$(date +"%Y%m%d_%H%M%S")};}