Hide

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.


If you have a new feature suggestion or find a bug, please get in touch via http://commandlinefu.uservoice.com/

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.

Hide

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:

Hide

News

2011-03-12 - Confoo 2011 presentation
Slides are available from the commandlinefu presentation at Confoo 2011: http://presentations.codeinthehole.com/confoo2011/
2011-01-04 - Moderation now required for new commands
To try and put and end to the spamming, new commands require moderation before they will appear on the site.
2010-12-27 - Apologies for not banning the trolls sooner
Have been away from the interwebs over Christmas. Will be more vigilant henceforth.
2010-09-24 - OAuth and pagination problems fixed
Apologies for the delay in getting Twitter's OAuth supported. Annoying pagination gremlin also fixed.
Hide

Tags

Hide

Functions

Commands using rm from sorted by
Terminal - Commands using rm - 257 results
rm *.txt <TAB> <TAB>
2010-11-04 13:58:15
User: boschi
Functions: rm
24

alternative for "echo rm *.txt". Just doubletab the command you are willing to use and it will show you the affected files.

ps -u $USER -lf | grep -vE "\-bash|sshd|ps|grep|PPID" > .tmpkill; if (( $(cat .tmpkill | wc -l) > 0 )); then echo "# KILL EM ALL"; cat .tmpkill; cat .tmpkill | awk '{print $4}' | xargs kill -9; else echo "# NOTHING TO KILL"; fi; cat .tmpkill; rm .tmpkill;
2010-11-04 04:16:50
User: zsugiart
Functions: awk cat echo grep kill ps rm wc xargs
0

Kills all process that belongs to the user that runs it - excluding bash, sshd (so putty/ssh session will be spared). The bit that says grep -vE "..." can be extended to include ps line patterns that you want to spare.

If no process can be found on the hitlist, it will print # NOTHING TO KILL. Otherwise, it will print # KILL EM ALL, with the cull list.

for i in $(file * | grep broken | cut -d : -f 1); do rm $i; done
echo rm *.txt
2010-10-27 07:26:26
User: alperyilmaz
Functions: echo rm
11

if you're using wildcards * or ? in your command, and if you're deleting, moving multiple files, it's always safe to see how those wildcards will expand. if you put "echo" in front of your command, the expanded form of your command will be printed. It's better safe than sorry.

find ~ -name "*.pyc" -exec rm {} \;
rm -f !(survivior.txt)
ram() { for i in /tmp /altroot;do mount -t tmpfs tmpfs $i;done&& for i in /var /root /etc $HOME; do find -d $i |cpio -pdmv /tmp&& mount -t tmpfs tmpfs $i&& mv -v /tmp$i/* $i&& rm -vrf /tmp$i ; done ;} usage: (in rc sequence) ram
2010-08-31 08:25:55
User: argv
Functions: cpio find mount mv rm
4

if you use disk-based swap then it can defeat the purpose of this function.

wget http://forums.dropbox.com && wget $(cat index.html|grep "Latest Forum Build"|cut -d"\"" -f2) && wget $(cat topic.php*|grep "Linux x86:"|cut -d"\"" -f2|sort -r|head -n1) && rm -rf ~/.dropbox* && rm index.html *.php* && tar zxvf dropbox-*.tar.gz -C ~/
cat b1.avi b2.avi b3.avi b4.avi b5.avi b6.avi b7.avi > output.avi; mencoder -forceidx -oac copy -ovc copy output.avi -o output_final.avi; rm output.avi
find $HOME -name '*.sol' -exec rm {} \;
2010-08-27 06:38:16
User: Tungmar
Functions: find rm
2

Maybe you want first check which files will be deleted:

find $HOME -name '*.sol' -exec echo rm {} \;
rm ^'name with spaces'
2010-08-21 02:24:17
User: dbbolton
Functions: rm
Tags: rm zsh glob
1

This is for zsh with extended globbing.

rm -f **/Thumbs.db
2010-08-18 07:09:19
User: Seebi
Functions: rm
Tags: thumbnails rm zsh
4

An alternative which uses the advanced zsh globbing (pattern matching)

rm -fr `find . -name Thumbs.db`
find ./ -name Thumbs.db -exec rm -rf '{}' +
tar tfz filename.tgz |xargs rm -Rf
find -type f -size +0 -mtime +1 -print0|xargs -0r rm -f
today=`date +%d`; ls -ltr | rm -f `nawk -v _today=$today '{ if($5 != 0 && $7 < _today) { print $9 } }'`
2010-07-29 13:47:19
User: alex__
Functions: ls rm
0

Delete all files that its size it's different than 0 and older than actuall day.

for i in {a..z};do sudo rm /usr/share/doc/$i*/*;done
2010-07-23 01:52:25
User: LinuxMan
Functions: rm sudo
-12

Never read the documentation? No, then why have that ~ 20 MB sit there and take up space? This command preserves directory structure wile removing all of those unnecessary help and documentation files. Works on Ubuntu, Debian, and most related systems. Gives a lot of directory errors, I'll fix those later.

rm $( ls | egrep -v 'abc|\s' )
2010-07-18 10:59:15
User: dbbolton
Functions: egrep ls rm
Tags: grep rm
-1

Really, you deserve whatever happens if you have a whitespace character in a file name, but this has a small safety net. The truly paranoid will use '-i'.

shopt -s globstar ; rm -f **/cscope.out
find ~ -maxdepth 20 -type f -size -16M -print > t; for ((i=$(wc -l < t); i>0; i--)) do a=$(sed -n ${i}p < t); mv "$a" /dev/shm/d; mv /dev/shm/d "$a"; echo $i; done; echo DONE; rm t
2010-07-07 04:29:22
User: LinuxMan
Functions: echo find mv rm sed wc
2

Thanks to flatcap for optimizing this command.

This command takes advantage of the ext4 filesystem's resistance to fragmentation.

By using this command, files that were previously fragmented will be copied / deleted / pasted essentially giving the filesystem another chance at saving the file contiguously. ( unlike FAT / NTFS, the *nix filesystem always try to save a file without fragmenting it )

My command only effects the home directory and only those files with your R/W (read / write ) permissions.

There are two issues with this command:

1. it really won't help, it works, but linux doesn't suffer much (if any ) fragmentation and even fragmented files have fast I/O

2. it doesn't discriminate between fragmented and non-fragmented files, so a large ~/ directory with no fragments will take almost as long as an equally sized fragmented ~/ directory

The benefits i managed to work into the command:

1. it only defragments files under 16mb, because a large file with fragments isn't as noticeable as a small file that's fragmented, and copy/ delete/ paste of large files would take too long

2. it gives a nice countdown in the terminal so you know how far how much progress is being made and just like other defragmenters you can stop at any time ( use ctrl+c )

3. fast! i can defrag my ~/ directory in 11 seconds thanks to the ramdrive powering the command's temporary storage

bottom line:

1. its only an experiment, safe ( i've used it several times for testing ), but probably not very effective ( unless you somehow have a fragmentation problem on linux ). might be a placebo for recent windows converts looking for a defrag utility on linux and won't accept no for an answer

2. it's my first commandlinefu command

goburncd() { d=/tmp/goburncd_$RANDOM; mkdir $d && for i in *.[Mm][Pp]3; do lame --decode "$i" "$d/${i%%.*}.wav"; done; sudo cdrecord -pad $d/* && rm -r $d; eject }
2010-07-06 21:58:10
User: meathive
Functions: cdrecord eject mkdir rm sudo
1

My variation on an audio burning command from commandlinefu - this one doesn't crap out if you want to burn a CD in a directory whose permissions don't allow it, and instead rips everything to /tmp. If you mount your music partition like I do using Samba, you probably don't have write permission inside that file system in order to create the temporary directory other audio burning commands here use. Not a bad idea to add cdrom to your groups, and /bin/eject with visudo.

find . -name .svn -exec rm \-rf {} \;
bsro3 () { P=`pwd`; S=$1; R=$2; ls *.odt > /dev/null 2>&1; if [[ $? -ne 0 ]]; then exit 1; fi; for i in *.odt; do mkdir ${P}/T; cd ${P}/T; unzip -qq "$P"/"$i"; sed -i "s/$S/$R/" ${P}/T/content.xml; zip -qq -r "$P"/"$i" *; cd ${P}; rm -rf ${P}/T; done; }
2010-06-30 04:43:54
User: danpos
Functions: cd exit ls mkdir rm sed
2

This function does a batch edition of all OOO3 Writer files in current directory. It uses sed to search a FOO pattern into body text of each file, then replace it to foo pattern (only the first match) . I did it because I've some hundreds of OOO3 Writer files where I did need to edit one word in each ones and open up each file in OOO3 gui wasn't an option. Usage: bsro3 FOO foo

find ~/.thunderbird/*.default/ -name *.msf -exec rm -f {} \;