Process using port
lsof -i:80
File operation
Insert new line: esc i enter
Delete letter: esc x
Delete Line: esc d
sudo vi file name
Editor: gedit filename
find . -name *.txt| grep -i keyword
ls -l
viewing elnf of files
vi fileName -->Shift g
http://www.tecmint.com/35-practical-examples-of-linux-find-command/switching to root user: sudo su
Removing file recursively: rm abc.* -r
space available:
(disk free)
df -m
df -g
df -h // human readable
df m/g (megabytes/gigabytes)
df -ah // all files
memory:
free -h
free -h -t
free -m / in MB
free -g / in GB
Process
Process
list out process running:ps -ef
Find Java process: ps –ef | grep java
Find tomcat process: ps- ef | grep cataline
Kill Process: kill -9 processid
Linking
Creating link of an existing file
ln -s filexisting filenew
changing owner group
chown user_name:group_name file_name.
File Download
GNU Wget is a free utility for non-interactive download of files from the Web. It supports HTTP, HTTPS, and FTP protocols, as well as retrieval through HTTP proxies.
download jdk
wget http://download.oracle.com/otn-pub/java/jdk/6u31-b04/jdk-6u31-linux-x64-rpm.bin
ftp archive requires the --passive-ftp flag on wget.
wget --passive-ftp http://www.ccrnp.ncifcrf.gov/~toms/ftp/ev.p
Installation
#rpm- rpm is packaging technique followed by few linux os.
#yum - an utility which updates and install packagesand their dependencies using internate.
yum package name.
yum >savefile output of a command in a file
Install Apache: yum install httpd
Install JDK: yum install jdk
./jdk-6u32-linux-x64-rpm.bin
version check:
which java
Creating Tar/Compressing and uncompressing tar files
#To combine multiple files and/or directories into a single file, use the following command:
tar -cvf file.tar inputfile1 inputfile2
#Replace inputfile1 and inputfile2 with the files and/or directories you want to combin
#To separate an archive created by tar into separate files, at the shell prompt, enter:
tar -xvf file.tar
#f option, tar assumes you really do want to create a tape archive instead of joining up a number of files. The v option tells tar to be verbose, which reports all files as they are added.
Compressing and uncompressing tar files
tar -cvzf file.tar.gz inputfile1 inputfile2
# z option tells tar to zip the archive as it is created. To unzip such a zipped tar file, enter:
tar -xvzf file.tar.gzTar everything in the current directory but
exclude two files
Creating link of an existing file
ln -s filexisting filenew
changing owner group
chown user_name:group_name file_name.
File Download
GNU Wget is a free utility for non-interactive download of files from the Web. It supports HTTP, HTTPS, and FTP protocols, as well as retrieval through HTTP proxies.
download jdk
wget http://download.oracle.com/otn-pub/java/jdk/6u31-b04/jdk-6u31-linux-x64-rpm.bin
ftp archive requires the --passive-ftp flag on wget.
wget --passive-ftp http://www.ccrnp.ncifcrf.gov/~toms/ftp/ev.p
Installation
#rpm- rpm is packaging technique followed by few linux os.
#yum - an utility which updates and install packagesand their dependencies using internate.
yum package name.
yum >savefile output of a command in a file
Install Apache: yum install httpd
Install JDK: yum install jdk
./jdk-6u32-linux-x64-rpm.bin
version check:
which java
Creating Tar/Compressing and uncompressing tar files
#To combine multiple files and/or directories into a single file, use the following command:
tar -cvf file.tar inputfile1 inputfile2
#Replace inputfile1 and inputfile2 with the files and/or directories you want to combin
#To separate an archive created by tar into separate files, at the shell prompt, enter:
tar -xvf file.tar
#f option, tar assumes you really do want to create a tape archive instead of joining up a number of files. The v option tells tar to be verbose, which reports all files as they are added.
Compressing and uncompressing tar files
tar -cvzf file.tar.gz inputfile1 inputfile2
# z option tells tar to zip the archive as it is created. To unzip such a zipped tar file, enter:
tar cvpf mytar.tar * --exclude=index.html --exclude=myimage.png
#To separate a tar archive that was compressed by gzip, enter:
gunzip -c file.tar.gz | tar -xvf -
#To separate a tar archive that was compressed by gzip, enter:
gunzip -c file.tar.gz | tar -xvf -
#Extract jar file
jar xf xyz.jar
Make a Tar file" : tar -czf folder_name.tar.gz folder_name
Compress a single file: gzip file_name.txt -> file_name.txt.gz
Searching
Searching some keyword in a file
grep -n keyword localhost_tomcat.log
-n shows line number
grep -n keyword localhost_tomcat.log
-n shows line number
egrep:
egrep stands for extended grep and it is more powerful than grep command in Unix and allows more regular exception like you can use "|" option to search for either Error or Exception by executing just one command.
egrep 'Error|Exception' logfile.txt
egrep stands for extended grep and it is more powerful than grep command in Unix and allows more regular exception like you can use "|" option to search for either Error or Exception by executing just one command.
egrep 'Error|Exception' logfile.txt
Show only n lines from the search result
shows only 400 lines from line -572458
grep -n keyword localhost_tomcat.log head -572458 catalina.out | tail 400
grep -r catalina.xml .
tail -100f localhost_latest.log
find . -name *file_name* -type f
find <directory_location> -name "*file_name*" | grep "key_word_from_output"
eg. directory_location: . , /, ../
find <directory_location> -name "*file_name*" | grep "key_word_from_output"
eg. directory_location: . , /, ../
Others:
history
echo $CATALINA_HOME
sudo -i :acquires the root user's environment.
history | grep process_name
starting apache server
sudo httpd -k start
Setting Environment variable:
export JAVA_HOME=/usr/lib/jvm/java-6-sun
Setting environment variable permanently
vi ~/.bash_profile
export ABC=XYZ
print all environment variable : printenv
print all environment variable : printenv
Switch to a different user
su -l <user_name>
Getting IP configuration
ipconfig//win
ifconfig// mac
nslookup google.com
network statistics
netstat -n
TCP packet dump
tcpdump -l -x
tcpdump allows us to save the packets that are captured, so that we
can use it for future analysis. The saved file can be viewed by
the same tcpdump command.
Reload environment variable
. /Users/<user_id>/.bash_profile
Sftp:
Reload environment variable
. /Users/<user_id>/.bash_profile
Sftp:
Download
sftp user@host_name:src_path/file_name
dlocal_dest_path
grep:
Show 5 more lines along with the keyword line
grep:
Show 5 more lines along with the keyword line
grep 'some_key_word' application.log -A5
5 lines before
grep 'some_key_word' application.log -B5
in between 5 lines
grep 'some_key_word' application.log -C5
error count
grep 'some_key_word' application.log | wc -l
Running Shell Script:
& -> Running script in background.
Stop running ctrl z
continue runnning in background: bg, foreground: fg
foreground : z
Disk usage:
du -h -d1
awk:
data extraction utility (Aho, Weinberger and Kernighan )
awk ' /'pattern'/ {print $2} '
ls -l | awk '{print $3}'
kill running program foo
kill -9 $(ps -ef | grep java | awk '{print $2}')
awk ’{ print $1 > "names.unsorted"
command = "sort -r > names.sorted"
print $1 | command }’ inputfile
https://linuxconfig.org/learning-linux-commands-awk
#Cron expression
crontab -e //edit
cromtab -i // info
No comments:
Post a Comment