Unix Commands

Unix  is a multitasking, multi-user computer operating system.
            
           
A Unix shell is a command-line interpreter or shell that provides a traditional user interface for the Unix operating system and for Unix-like systems. Users direct the operation of the computer by entering commands as text for a command line interpreter to execute or by creating text scripts of one or more such commands.
The most influential Unix shells have been the Bourne shell and the C shell. The Bourne shell, sh, was written by Stephen Bourne at AT&T as the original Unix command line interpreter; it introduced the basic features common to all the Unix shells, including piping, here documents, command substitution, variables, control structures for condition-testing and looping and filename wildcarding.
The C shell, csh, was written by Bill Joy while a graduate student at University of California, Berkeley. The language, including the control structures and the expression grammar, was modeled on C. The C shell also introduced a large number of features for interactive work, including the history and editing mechanisms, aliases, directory stacks, tilde notation, cdpath, job control and path hashing.

  
touch
Used to set same date & time for all files under folder
Ps –ef | grep java
Shows which java processes are running on the machine
Pgrep  java | xargs pwdx
Shows which java processes are running on the machine and which directory they started from
Kill -9  <processId>
To kill the processes by id.
$ telnet x.x.x.x  port

$ telnet eh-mbp-p-db05 1521
Attempt to connect to a service running on a IP address and port.  Very useful for checking if the firewall is open between the server running the command and the end point.  NOTE you must be sure that the end service is running.
The example shows proving that we can connect to a database listenner running on db05.

# netstat –an

# netstat –an |grep 2100

# netstat –an |egrep “210[0-9]”

netstat -a -n -o
Must be logged in as root.
Check the port connections open by processes on this machine. 
Check if any process has port 2100 open on this machine.
Check if any process has a port open in the range 2100-2109.
$ less <filename>
Very useful to view large log files on a unix system.
nohup.out
Used to append the console logs to file
chown user:usergroup filenme
used to change the user for file / folder
sudo su - newuser
to change the user


List all process for current user
ps -u user -f
Delete all files and folders in current location
rm -fr *
Download file
wget http://ipaddress:8080/content.zip
Grant execute permission
chmod a+x startup.sh
Grant permission to a specific user
setfacl -m u:c693054:rwx tools/
setfacl -m u:cookies:rwx  tools/
Copy complete directory including sub-dir
cp -rf present/directory /desire/directory
Unzip
tar -zxvf apache-tomcat-7.0.27.tar.gz -C tcdemo
tar -zxvf apache-tomcat-7.0.27.tar.gz -C tc1

unzip  content.zip
Tail
tail -f catalina.log
Kill process
kill -9 processid
environment variables
echo $PATH
export PATH=$PATH:/usr/local/bin
List file sizes
du -smh *
Free space
df -h
Free memory
free -m
vmstat
Process
top
Find
 sudo find / -name searchpattern
Reload .profile
. .profile
Find pattern in files under
grep -R 'pattern' *
SCP file copy via ssh
scp SystemOut.log user@ipaddess:SysOut.log
vi ~/.profile

env -> will show the all environment values set up for current user.


Importing the security certificates on Unix machines -
  • echo | openssl s_client -connect xxx.xxx.xxx.xxx:10000 -tls1 2>&1 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > client.pem
  • openssl x509 -outform der -in client.pem -out client.crt
  • keytool -import -keystore cacerts -file client.crt -alias <serverIpaddress>
  • Password - changeit