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.
» 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:
* grep -i leaves only mp3 files (case insentitive)
* sort -R randomizes list (may use GNU 'shuf' instead).
* the sed command will add double quotes around each filename (needed if odd characters are present)
Compare the ls -Rl output of two directories in meld (you can also use diff -y instead of meld).
This let me find some a set of modifications that were made to a rather large tree of files, where the file-names themselves were not unique (actually: insanely redundant and useless. "1.dat 2.dat ..."). Pruning down to last-branch brough things back to the "project-name" scope, and it's then easy to see which branches of the tree have recently changed, or any other similar search.
Ideally, it should sort the directories by the mtime of the most recent *file* *inside* the directory, but that's probably outside the scope of a (sane...) command line.
Returns the most recently modified file in the current (or specified) directory. You can also get the oldest file, via:
ls -t1 $* | tail-1 ;
This command does a basic find with size. It also improves the printout given (more clearer then default)
Adjusting the ./ will alter the path.
Adjusting the "-size +100000k" will specify the size to search for.
This will quickly display files last changed in a directory, with the newest on top.
this requires the use of a throwaway file.
it outputs a shell function.
assuming the throwaway file is f.tmp
usage: >f.tmp;lso f.tmp > f.tmp; . f.tmp;rm f.tmp;lso -l ...
notes:
credit epons.org for the idea. however his version did not account for the sticky bit and other special cases.
many of the 4096 permutations of file permissions make no practical sense. but chmod will still create them.
one can achieve the same sort of octal output with stat(1), if that utility is available.
here's another version to account for systems with seq(1) instead of jot(1):
lso(){
case $# in
1)
{ case $(uname) in
FreeBSD)
jot -w '%04d' 7778 0000 7777 ;;
*)
seq -w 0000 7777 ;;
esac; } \
|sed '
/[89]/d
s,.*,printf '"'"'& '"'"';chmod & '"$1"';ls -l '"$1"'|sed s/-/./,' \
|sh \
|{
echo "lso(){";
echo "ls \$@ \\";
echo " |sed '";
sed '
s, ,@,2;
s,@.*,,;
s,\(.* \)\(.*\),s/\2/\1/,;
s, ,,';
echo \';
echo };
};
;;
*)
echo "usage: lso tmp-file";
;;
esac;
}
this won't print out types[1]. but its purpose is not to examine types. its focus is on mode and its purpose is to make mode easier to read (assuming one finds octal easier to read).
1. one could of course argue "everything is a file", but not always a "regular" one. e.g., a "directory" is really just a file comprising a list.
Use the -a flag to display all files, including hidden files. If you just want to display regular files, use a -1 (yes, that is the number one). Got this by RTFM and adding some sed magic.
[bbbco@bbbco-dt ~]$ ls -a | sed "s#^#${PWD}/#"
/home/bbbco/.
/home/bbbco/..
/home/bbbco/2011-09-01-00-33-02.073-VirtualBox-2934.log
/home/bbbco/2011-09-10-09-49-57.004-VirtualBox-2716.log
/home/bbbco/.adobe
/home/bbbco/.bash_history
/home/bbbco/.bash_logout
/home/bbbco/.bash_profile
/home/bbbco/.bashrc
...
[bbbco@bbbco-dt ~]$ ls -1 | sed "s#^#${PWD}/#"
/home/bbbco/2011-09-01-00-33-02.073-VirtualBox-2934.log
/home/bbbco/2011-09-10-09-49-57.004-VirtualBox-2716.log
/home/bbbco/cookies.txt
/home/bbbco/Desktop
/home/bbbco/Documents
/home/bbbco/Downloads
...
This will list the files in a directory, then zip each one with the original filename individually.
video1.wmv -> video1.zip
video2.wmv -> video2.zip
This was for zipping up large amounts of video files for upload on a Windows machine.
Like normal ls, but only lists directories.
Can be used with -l to get more details (ls -lad */)
Will use variable value (for variable $my_dir, in this case), an assign a default value if there is none.
You need to have figlet(for font) and cowsay installed then add it to your .bashrc file.You can see it every time after start a new session.
I simply find binary notation more straightforward to use than octal in this case.
Obviously it is overkill if you just 600 or 700 all of your files...
whereis (1) - locate the binary, source, and manual page files for a command
Not actually better, just expanded a bit. The "whereis" command has the following output:
whereis gcc
gcc: /usr/bin/gcc /usr/lib/gcc /usr/bin/X11/gcc /usr/share/man/man1/gcc.1.gz
therefore the 'ls' error on first line, which could be eliminated with a little extra work.
this is the much easier zsh equivalent ...