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:
make usable on OSX with filenames containing spaces. note: will still break if filenames contain newlines... possible, but who does that?!
This command will ask for remote sudo password before executing a remote command.
A way to display directory structure
This will show you the permissions on the directory you are currently in
Sometime you need to monitor file or direcory change in dimension or other attributes. This command output file (called myfile in the example) attributes in the top of the screen, updating each 1 second.
You should change update time, command ( e.g., ls -all ) or target ( myfile, mydir, etc...).
zsh globbing and glob qualifier:
'**/*' = recursive
om = ouput by modification (last access)
[1,20] = twenty files.
The '-t' switch is provided to ls so that the files are ordered with the most recent at the top. For a more 'find' like output the following can be used.
print -rl **/*(om[1,20])
zsh: list of files sorted by size, greater than 100mb, head the top 5. '**/*' is recursive, and the glob qualifiers provide '.' = regular file, 'L' size, which is followed by 'm' = 'megabyte', and finally '+100' = a value of 100
Find top 5 big files
I find it useful, when cleaning up deleting unwanted files to make more space, to list in size order so I can delete the largest first.
Note that using "q" shows files with non-printing characters in name.
In this sample output (above), I found two copies of the same iso file both of which are immediate "delete candidates" for me.
Long listing alternative
I find it very handy to be able to quickly see the most recently modified/created files in a directory.
Note that the "q" option will reveal any files with non-printable characters in their filename.
list only directories in reverse order
On the Mac, the 'ls' function can sort based on month/day/time, but seems to lack ability to filter on the Year field (#9 among the long listed fields). The sorted list continuously increases the 'START' year for the most recently accessed set of files. The final month printed will be the highest month that appeared in that START year. The command does its magic on the current directory, and suitably discards all entries that are themselves directories. If you expect files dating prior to 2002, change the START year accordingly.
Executing pfiles will return a list of all descriptors utilized by the process
We are interested in the S_IFREG entries since they are pointing usually to files
In the line, there is the inode number of the file which we use in order to find the filename.
The only bad thing is that in order not to search from / you have to suspect where could possibly be the file.
Improvements more than welcome.
lsof was not available in my case
Lists everithing using -l "long listing format" wich includes the space used by the folder. Displays it in -h "human readable form" (i.e. 2.2G, 32K), and -R recurses subfolders.
grep -e using a regex, show lines containing the word "total" or a ":" at the end of the line (those with the name of the folder) only.
ls -1 shows one file per line (update: -1 was not really needed)
wc -l counts the lines received from the previous command