Linux with its versatile command line is my go-to OS for software development. Here are 3 command line tools I commonly use for development and which I recommend you to try out!
1. grep
The #1 command line tool I use during development is grep
. Basically it’s a simple tool which searches for patterns in files. But when do you need that?
Well, let’s say you need to find every occurrence of the variable meow
in your code base. Unfortunately the variable exists in many different classes and some functions which are not related to each other, so IDE refactoring could prove bothersome. Simply execute grep -rn meow
!
The -r
flag will cause grep
to search in all sub-directories recursively, and the -n
flag will print the lines, in addition to the file names. That’s everything you need!
~/linux_commands grep -rn meow
example_tree/dir_1/subdir_2/great_file.md:3:meow
example_tree/dir_2/another_great_file.md:2:meow
example_tree/dir_2/another_great_file.md:23:meow
2. tree
Did you ever need to look up a file and had no idea where it could be? Or did you want to know how a directory and its sub-directories are structured, but didn’t have any overview? This is where tree
comes in.
By running tree
you get a nicely looking directory tree, containing the current directory and all the sub-directories.
~/linux_commands tree
.
└── example_tree
├── dir_1
│ ├── subdir_1
│ └── subdir_2
│ └── great_file.md
└── dir_2
└── another_great_file.md
5 directories, 2 files
Handy, isn’t it? But there’s more to it! If you look up the man page you see that, as an example, you can append the -l
flag to follow symbolic links or append the -f
flag to print the relative file path, which is useful if you need the relative path in your code base. Additionally, if you execute tree
for a large directory with numerous sub-directories you may limit the depth of the sub-directory traversal to e.g. 2 levels via the tree -L 2
.
3. rsync
Last on our list is rsync
. Its main ability is to copy files, which doesn’t sound extraordinary. However, it proves useful when you want to limit what you copy, or you want to copy from/to remote directories.
Let’s say you have some files on your remote server, located at me@myserver.com:/home/me
. You want to copy a large file of several GB to your local file system, so a progress bar would be nice too. Additionally, there are sub-directories and symbolic links, so you want to follow those too. Then you may use
rsync -rL --info=progress2 me@myserver.com:/home/me/big_directory .
to copy the whole remote big_directory
to your local file system. Neat!
There are way more options to rsync
than I could list here, so just look at its man page with man rsync
.
Bonus command: fortune | cowsay
Are you having a bad day at work? Did your co-developers make a mess of your thought-through and beloved class? Or is the new pack of coffee you bought just not what you hoped for?
Improve your mood via cowsay
! 🙂
~/linux_commands fortune | cowsay
______________________________________
/ You will have domestic happiness and \
\ faithful friends. /
--------------------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
If you’re more the GUI type then there’s also xcowsay
for you out there.