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/
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.
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.
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:
Remove all arquives except the list.
Can't have space between the commas.
Bash method to remove all files but "abc".
It would be 'rm *~abc' in Zsh.
-depth argument will cause find to do a "depth first" tree search, this will eliminate the "No such file or directory" error messages
expands through shell and not find
but may hits the limit of max argument size for rm
(thus: for f in **/*.htm;do rm $f;done
but then I prefer the find command ;)
This is for zsh with extended globbing.
An alternative which uses the advanced zsh globbing (pattern matching)
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'.
Please be careful while executing the following command as you don?t want
to delete the files by mistake. The best practice is to execute the same
command with ls ?l to make sure you know which files will get deleted when
you execute the command with rm.
This will search all directories and ignore the CVS ones. Then it will search all files in the resulting directories and act on them.
This is a slight variation of an existing submission, but uses regular expression to look for files instead. This makes it vastly more versatile, and one can easily verify the files to be kept by running ls | egrep "[REGULAR EXPRESSION]"
Remove all empty directories below the current directory. If directories become empty as the results of this, remove those too.
it will remove everything except the file names matching you can use also use wildcards
Remove everything except that file with shell tricks inside a subshell to avoid changes in the environment.
This is an useful command for when your OS is reporting less free RAM than it actually has. In case terminated processes did not free their variables correctly, the previously allocated RAM might make a bit sluggis over time.
This command then creates a huge file made out of zeroes and then removes it, thus freeing the amount of memory occupied by the file in the RAM.
In this example, the sequence will free up to 1GB(1M * 1K) of unused RAM. This will not free memory which is genuinely being used by active processes.
Remove everything in current directory except files starting with "ca".
avoid rm to be recursive until you complete the command: put the -rf at the end!
Deletes empty directories and prints an error if directory is not empty.
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
Sometimes Firefox crashes or is bad finished and the message the process is still running appear while it's not. This also works when you sharing account from a NIS server and try to open the browser on multiple computers.
Can be used for other commands as well, replace rm with ls.
It is easy to make this shorter but if the filenames involved have spaces, you will need to do use find's "-print0" option in conjunction with xargs's "-0" option. Otherwise the shell that xargs uses to execute the "rm" command line will treat the space as a token separator, thereby treating the name as two (or more) names.