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 prints file access rights in octal - useful when "stat" is unavailable.
Show running time. eta, progressbar
new way to replace text file with dd,faster than head,sed,awk if you do this with big file
This is an alternative to #9131. ffmpeg didn't work on my .au files, though it did on the .wav ones. Also useful if you don't have ffmpeg but do have sox. Handily, sox already reports in seconds (decimal).
Cleaner, but probably less portable. Works with bash4 and should also work on bash3.
IIRC, $(()) and (()) are bashisms, not POSIX.
Will automatically take the size of the file but longer, usefull only if in an function.
This is useful if you'd like to see the output of a script while you edit it. Each time you save the file the command is executed. I thought for sure something like this already exists - and it probably does. I'm on an older system and tend to be missing some useful things.
Examples:
ontouchdo yourscript 'clear; yourscript somefiletoparse'
Edit yourscript in a separate window and see new results each time you save.
ontouchdo crufty.html 'clear; xmllint --noout crufty.html 2>&1 | head'
Keep editing krufty.html until the xmllint window is empty.
Note: Mac/bsd users should use stat -f%m. If you don't have stat, you can use perl -e '$f=shift; @s=stat($f); print "$s[9]\n";' $1
This script compares the modification date of /var/lib/dpkg/info/${package}.list and all the files mentioned there.
It could be wrong on noatime partitions.
Here is non-oneliner:
#!/bin/sh
package=$1;
list=/var/lib/dpkg/info/${package}.list;
inst=$(stat "$list" -c %X);
cat $list |
(
while read file; do
if [ -f "$file" ]; then
acc=$(stat "$file" -c %X);
if [ $inst -lt $acc ]; then
echo used $file
exit 0
fi;
fi;
done
exit 1
)
The find command isn't the important bit, here: it's just what feeds the rest of the pipe (this one looks for all PDFs less than 7 days old, in an archive directory, whose structure is defined by a wildcard pattern: modify this find, to suit your real needs).
I consider the next bit the useful part. xargs stats out the byte-size of each file, and this is passed to awk, which adds them all together, and prints the grand total. I use printf, in order to override awk's tendency to swtich to exponential output above a certain threshold, and, specifically "%0.0f\n", because it was all I can find to force things back to digital on Redhat systems.
This is then passed to an optional sed, which formats them in a US/UK number format, to make large numbers easier to read. Change the comma in the sed, for your preferred separator character (e.g. sed -r ':L;s=\b([0-9]+)([0-9]{3})\b=\1 \2=g;t L' for most European countries).
(This sed is credited to user name 'archtoad6', on the Linuxquestions forum.)
This is useful for monitoring changes in the storage use within large and growing archives of files, and appears to execute much more quickly than some options I have seen (use of a 'for SIZE in find-command -exec du' style approach, instead, for instance). I just ran it on a not particularly spectacular server, where a directory tree with over three thousand subdirectories, containing around 4000 files, of about 4 Gigs, total, responded in under a second.
Problem arises when ebuild gets removed from portage and you end up with old and unmaintained package that you cannot find standard way. This oneliner will give you list of those packages.
This command remove a file from your filesystem like the normal rm command
but instead of deleting only the inode information this also delete the data that was stored on blocks
/!\ warning this may be long for large files
This renames a pattern matched bunch of files by their last modified time.
rename by timestamp
rename by time created
rename by time modified
Works with files containing spaces and for very large directories.
Use color escape sequences and sed to colorize the output of svn stat -u.
Colors: http://www.faqs.org/docs/abs/HTML/colorizing.html
svn stat characters: http://svnbook.red-bean.com/en/1.4/svn-book.html#svn.ref.svn.c.status
GNU Extensions for Escapes in Regular Expressions: http://www.gnu.org/software/sed/manual/html_node/Escapes.html
Since the original command (#1873) didn't work on FreeBSD whose stat lacks the "-c" switch, I wrote an alternative that does. This command shows also the fourth digit of octal format permissions which yields the sticky bit information.