When I need to find a file it’s normally when I am in Vim and I’ll happly use Ctrl P. However, there are tasks outside of Vim that require my attention daily and I have found the following tips and tricks to listing and finding files very usefull.
Of course, everyone knows what ls
is, for those who don’t we’ll take a moment
to weep for their souls… ls
has more power to it than you may know. For
instance, if you use ls -t
it provides a list of files ordered by most
recently modified.
|
The real powerhouse of file finding is aptly named find
. If you do any kind
of command line work this is a command you should know how to harness the power
of. My favorite of these is the -name
option, which matches files like bash
would.
|
Want a ls version of that find? No problem dude
|
sort
is also a powerful ally for just about everything command, in this case
the sort -k 11
is sorting the 11th column, which is the default of ls, but
you could very easily sort by any other column.
Other noteble features of find
-mtime
– Find files edited before or after a certain time, for instance-mtime -2
would list all files edited in the last two days while-mtime +2
would list all files that haven’t been edited in the last two days-newer <file>
finds all files more recently modified than<file>
-exec
run a command against each file, for instancefind -name '*.rb' -exec flog {} \;
will runflog
for every ruby file
There are a ton more uses for find
but these are the ones I use on a daily
basis. I suggest trying them out and crack open the man pages to discover new
features you might find useful!