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.
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.
» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10
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:
This allows the output to be sorted from largest to smallest in human readable format.
This command will find the biggest files recursively under a certain directory, no matter if they are too many. If you try the regular commands ("find -type f -exec ls -laSr {} +" or "find -type f -print0 | xargs -0 ls -laSr") the sorting won't be correct because of command line arguments limit.
This command won't use command line arguments to sort the files and will display the sorted list correctly.
Ever need to output an entire directory and subdirectory contents to a file? This is a simple one liner but it does the trick every time. Omit -la and use only -R for just the names
I'm working in a group project currently and annoyed at the lack of output by my teammates. Wanting hard metrics of how awesome I am and how awesome they aren't, I wrote this command up.
It will print a full repository listing of all files, remove the directories which confuse blame, run svn blame on each individual file, and tally the resulting line counts. It seems quite slow, depending on your repository location, because blame must hit the server for each individual file. You can remove the -R on the first part to print out the tallies for just the current directory.
Output manpage as plaintext using cat as pager: man -P cat commandname
And redirect its stdout into a file: man -P cat commandname > textfile.txt
Example: man -P cat ls > man_ls.txt
Find when debian packages were installed on a system.
This command finds the 5 (-n5) most frequently updated logs in /var/log, and then does a multifile tail follow of those log files.
Alternately, you can do this to follow a specific list of log files:
sudo tail -n0 -f /var/log/{messages,secure,cron,cups/error_log}
Creates a PDF (over ps as intermediate format) out of any given manpage.
Other useful arguments for the -T switch are dvi, utf8 or latin1.
When a fs hangs and you've just one console, even # ls could be a dangerous command. Simply put a trailing "&" and play safe
order the files by modification (thanks stanishjohnd) time, one file per output line and filter first 10
Sort ls output of all files in current directory in ascending order
Just the 20 biggest ones:
ls -la | sort -k 5bn | tail -n 20
A variant for the current directory tree with subdirectories and pretty columns is:
find . -type f -print0 | xargs -0 ls -la | sort -k 5bn | column -t
And finding the subdirectories consuming the most space with displayed block size 1k:
du -sk ./* | sort -k 1bn | column -t
The URL can then be pasted with a middle click.
This is probably useful when trying to explain problems over instant messaging when you don't have some sort of shared desktop.
added alias in ~/.bashrc
alias lf='find ./* -ctime -1 | xargs ls -ltr --color'
To sort hidden files first, simply switch the two inner `ls` commands.
I have this aliased to `dira`
`dir` is aliased to the simpler version with no hidden files:
ls -l --color=always | less -R
This works on my ubuntu/debian machines.
I suspect other distros need some tweaking of sort and cut.
I am sure someone could provide a shorter/faster version.
Yeah, there are many ways to do that.
Doing with sed by using a for loop is my favourite, because these are two basic things in all *nix environments. Sed by default does not allow to save the output in the same files so we'll use mv to do that in batch along with the sed.