Here are some of the unix command line tools which we feel make our hands faster and lives easier. Let’s go through them in this post and make sure to leave a comment with your favourite!
In many situations we need to perform a command line operation but we might not know the right utility to run. The command (apropos) searches for the given keyword against its short description in the unix manual page and returns a list of commands that we may use to accomplish our need.
If you can not find the right utility, then Google is our friend 🙂
1
2
|
$ apropos "list dir" $ man -k "find files" |
It’s normal to make typographical errors when we type so fast. Consider a situation where we need to run a command with a long list of arguments and when executing it returns “command not found” and you noticed that you have made a “typo” on the executed command.
Now, we really do not want to retype the long list of arguments, instead use the following to simply just correct the typo command and execute
1
2
3
|
$ ^typo_cmd^correct_cmd $ dc /tmp $ ^ dc ^ cd |
The above will navigate to /tmp directory
Bang quite useful, when we want to play with the bash history commands . Bang helps by letting you execute commands in history easily when you need them
1
2
|
$ ~ /bin/lg-backup $ sudo !! |
In the last part of the above example we didn’t realize that the lg-backup command had to be run as “sudo”. Now, Instead of typing the whole command again with sudo, we can just use “sudo !!” which will re-run the last executed command in bash history as sudo, which saves us lot of time.
This incron configuration is almost like crontab setup, but the main difference is that “Incron” monitors a directory for specific changes and triggers future actions as specified
1
|
Syntax: $directory $file_change_mask $command_or_action |
1
2
|
/var/www/html/contents/ IN_CLOSE_WRITE,IN_CREATE,IN_DELETE /usr/bin/rsync –exclude ’*.tmp’ -a /home/ram/contents/ user@another_host: /home/ram/contents/ /tmp IN_ALL_EVENTS logger "/tmp action for #file" |
The above example shows triggering an “rsync” event whenever there is a change in “/var/www/html/contents” directory. In cases of immediate backup implementations this will be really helpful. Find more about incron here.
There are situations where we end up in creating/deleting the directories whose name start with a symbol. These directories can not be removed by just using “rm -rf or rmdir”. So we need to use the “double dash” (–) to perform deletion of such directories
1
|
$ rm -rf -- $symbol_dir |
There are situations where you may want to create a few directory that starts with a symbol. “You can just these create directories using double dash(–) and starting the directory name with a symbol”
1
|
$ mkdir -- $symbol_dir |
We can do lot with comma and braces to make our life easier when we are performing some operations, lets see few usages
To backup the httpd.conf to httpd.conf.bak
1
|
$ cp httpd.conf{,.bak} |
To revert the file from httpd.conf.bak to httpd.conf
1
|
$ mv http.conf{.bak,} |
To rename the file with prefixing ‘old’
1
|
$ cp exampleFile old-! #ˆ |
As we all know, vim is a powerful command line editor. We can also use vim to view files in read only mode if you want to stick to vim
1
|
$ vim -R filename |
We can also use the “view” tool which is nothing but read only vim
1
|
$ view filename |
Sometimes when we are working with various directories and looking at the logs and executing scripts we find alot of our time is spent navigating the directory structure. If you think your directory navigations resembles a stack structure then use push and pop utilities which will save you lots of time
Install xclip and create the below alias
1
2
|
$ alias pbcopy=’xclip -selection clipboard’ $ alias pbpaste=’xclip -selection clipboard -o’ |
We need to have the X window system running it to work. In Mac OS X, these pbcopy and pbpaste commands are readily available to you
To Copy:
1
|
$ ls | pbcopy |
To Paste:
1
|
$ pbpaste > lstxt.txt |
This means that it will not recopy all of the files every single time a backup is performed. Instead, only the files that have been newly created or modified since the last backup will be copied. Unchanged files are hard linked from prevbackup to the destination directory.
1
|
$ rsync -a –link-dest=prevbackup src dst |
Showing your processes in a tree structure is very useful for confirming the relationship between every process running on your system. Here is an option which is available by default on most of the Linux systems.
1
|
$ ps -aux –forest |
–forest is an argument to ps command, which displays ASCII art of process tree
There are many commands available like ‘pstree’, ‘htop’ to achieve the same thing.
If you want to see git commits in a repo as tree view to understand the commit history better, the below option will be super helpful. This is available with the git installation and you do not need any additional packages.
1
|
$ git log –graph –oneline |
Tee command is used to store and view (at the same time) the output of any other command.
(ie) At the same time it writes to the STDOUT, and to a file. It helps when you want to view the command output and at the time same time if you want to write it into a file or using pbcopy you can copy the output
1
|
$ crontab -l | tee crontab .backup.txt |
The tee command is named after plumbing terminology for a T-shaped pipe splitter. This Unix command splits the output of a command, sending it to a file and to the terminal output. Thanks Jon for sharing this.
Analysing disk usage with nurses interface, is fast and simple to use.
1
|
$ sudo apt-get install ncdu |
You all have seen the hacking scene on hollywood movies. Yes, there is a package which will let you create that for you.
1
2
3
|
$ sudo apt-add-repository ppa:hollywood /ppa $ sudo apt-get update $ sudo apt-get install hollywood |
1
|
$ hollywood |
20 Best iOS App Development Tutorials and Online Learning Resources
Top 15 Best Android Apps For C Programming | 2018 Exclusive
List of 15 Best iOS App Development Tools
The Best 15 Mobile Game Development Platforms & Tools in 2018
10 Amazing & Best SEO Tools You Must Try in 2018
20 Best MySQL GUI Tools
15 Best Free PHP Frameworks
Best Linux distros 2019: The finest open source operating systems around