Useful Unix Commands and Tips - Part 7

This is the final part of the series. Let us see some miscellaneous commands and tips. Hope this series helped you.

1) The utilities zcat, zgrep, zless, and zdiff, among others, serve the same purpose as cat, grep, less, and diff, respectively, but operate on compressed files. For example, if you want to search inside jar/zip file, you can use zgrep.

2) apropos command can be used to find the appropriate command if we forget command name. 
apropos search # gives all related commands with search string.
3) watch command allows to watch the output of a program change over time, which can be especially convenient when looking for changes to file sizes that reflect debugging output, download or file creation state, memory or disk usage, and so on.
4) History: If you want to remove a sensitive command from your history, you can simply edit your $HISTFILE history file and remove it. There is a trick you can use if you want to fly under the radar and never have a command recorded in history in the first place. Simply prefix your command by a space. For more tips refer here.
5) What is the difference between the sourcing and executing of a file?
Executing a file does not make any changes in the current shell, if intended, whereas the sourced file makes the changes in the current shell itself. Usually, the alias and profile files are the ones which are sourced since they contain stuffs like setting of environment variables , aliases definition, etc.
6) nohup: To background an already running program you can do Ctrl-Z followed by bg. Back grounded processes are still children processes of your terminal and will die if you close the terminal (this will send yet another signal, SIGHUP). To prevent that from happening you can run the program with nohup (a wrapper to ignore SIGHUP).
6) Difference between bashrc and bash_profile:
.bashrc : A file that runs in each new shell that is spawned
.bash_profile : A file that runs only in a “login shell” (and not all shells eg. it won’t run if you invoke a shell script that creates a subshell)
7) Redirecting multiple lines to a command’s input:
You might find yourself in a situation where you want to pass multiple lines of input to a command, and the < operator fails you in that case, as it only deals with files. Luckily, your shell provides you with the heredoc (here document) << operator to accomplish this. For more info, here.
A heredoc redirection has the following syntax:
command <<DELIMITER
a multi-line
string
DELIMITER
8) 1To find list of weblogic server names running in a node:
ps -ef | grep java | awk -F'Dweblogic.Name=' ' { print $2 } ' | awk  -F' ' ' { print $1 } ' | sed '/^s*$/d' | sort
9) To hit a webservice/url from command-line continuously with delay:
for ((i=0; i<10000; i++)) ; do     wget -r -N https://abc.com 2>&1 | tee >> 1.txt;     sleep 20s; done 

References:

Comments

Popular posts from this blog

HOW WE REDUCED SOA OSB PROVISIONING FROM 4 DAYS TO 4 HOURS

NOT ABLE TO START RABBITMQ CLUSTER: CANNOT DECLARE A QUEUE ‘~S’ ON NODE ‘~S’: ~255P

SOA SUITE 12.2.1.4 INSTALLATION: GOT EXCEPTION WHEN AUTO CONFIGURING THE SCHEMA COMPONENT(S) WITH DATA OBTAINED FROM SHADOW TABLE