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:
You can convert any UNIX man page to .txt
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.
Ok so it's rellay useless line and I sorry for that, furthermore that's nothing optimized at all...
At the beginning I didn't managed by using netstat -p to print out which process was handling that open port 4444, I realize at the end I was not root and security restrictions applied ;p
It's nevertheless a (good ?) way to see how ps(tree) works, as it acts exactly the same way by reading in /proc
So for a specific port, this line returns the calling command line of every thread that handle the associated socket
A powerfull way to rename file using sed groups.
& stand for the matched expression.
\1 referes to the first group between parenthesis. \2 to the second.
This command list and sort files by size and in reverse order, the reverse order is very helpful when you have a very long list and wish to have the biggest files at the bottom so you don't have scrool up.
The file size info is in human readable output, so ex. 1K..234M...3G
Tested with Linux (Red Hat Enterprise Edition)
64 elements max on 16 rows, 4 cols.
GNU Barcode will adapt automagically the width and the eight of your elements to fill the page.
Standard output format is PostScript.
Suppose that you had change in a directory like /home/user/mycode/code, and now you need to list it, instead of type entire path again, use ls !$ to recall path and list. Useful with many commands, this is only an example. (In this case, same result can be achivied with ls .)
Shows all linked file and destinations. The 'ls -l' command lists the files in long (1 file per line) format, and the grep command displays only those lines that starts with an l (lower case L) -- a linked file.
Updated: Remove reference to hard links because this command does not apply to hard link as others kindly pointed out.
List files above a given size threshold.
head by default displays first ten lines of its output. Use 'head -nXX' to display the XX largest files
Finds all files of a certain name and reports all line with the string. Very simple.
Coming back to a project directory after sometime elsewhere?
Need to know what the most recently modified files are?
This little function "t" is one of my most frequent commands.
I have a tcsh alias for it also:
alias t 'ls -ltch \!* | head -20'
Allows for quick mass renaming, assuming the user has some familiarity with regular expressions. Basically, it replaces the original_file_name in the output of ls with
"mv -v original_file_name new_file_name"
and passes the output to sh.
An alias i made for myself to play music in a faster way.
Works great when you have Guake / Tilda installed (Console that drops down like in the game QUAKE)
I put this in my bash_alias file (I'm on ubuntu, the bash_alias file does autostart with the right config) but it works putting it in bashrc too. Or anything that autostarts when the console is opened.
Needs Mplayer and music files to work. With out music theres nothing to play!
Oh, and also, without modification, this alias will try to play stuff from your ~/Music folder! (case sensitive). Make sure that folder exists and has music OR edit this alias to fit your needs.
If you want to operate on a set of items in Bash, and at least one of them contains spaces, the `for` loop isn't going to work the way you might expect. For example, if the current dir has two files, named "file" and "file 2", this would loop 3 times (once each for "file", "file", and "2"):
for ITEM in `ls`; do echo "$ITEM"; done
Instead, use a while loop with `read`:
ls | while read ITEM; do echo "$ITEM"; done
I often deal with long file names and the 'ls -l' command leaves very little room for file names. An alternative is to use the -h -o and -g flags (or together, -hog).
* The -h flag produces human-readable file size (e.g. 91K instead of 92728)
* The -o suppresses the owner column
* The -g suppresses the group column
Since I use to alias ll='ls -l', I now do alias ll='ls -hog'