I found myself using quite often two particular functions:
- searching for a file which name contains a keyword, and
- figuring out what files I recently modified in the current directory.
ls -l | grep -i some_keyword
ls -lt | head
Right, but since I use them quite often and being rather lazy I wouldn't want to type these every time... So here come aliases.
You can define an alias for a command you often type and use it instead. So I decided to define two aliases: lsg and lst for searching for a file name containing a keyword and displaying the recently modified files respectively.
So if you type at your command prompt:
alias lsg='ls -l | grep -i'
alias lst='ls -lt | head'
From now one you can use lsg and lst freely.
If you want to make the change permanent you could add the above lines to your ~/.bashrc file, so the aliases would be accessible any time you log in.
Oh one more thing... how to use it.
If I want to find out what files I modified recently in the current directory I just type:
$ lst
and it gives me a list of recntly modified files. If I'm looking for a file which name contains a keyword "book" I issue:
$ lsg book
And I get a list of files which names contain "book" (case insensitive). It's quite useful - at least for me.
PS. Dont forget about: cd -
It will bring you up to the directory you were previously in.
No comments:
Post a Comment