Linux Basics !
What is difference between shell & kernal ?
The main difference between kernel and shell is that thekernel is the core of the operating system that controls all the tasks of the system while the shell is the interface that allows the users to communicate with the kernel. Unix is an operating system. It is the interface betweenthe user and the hardware.Reference
How to open file ?
open 'filename' or cat 'filename'
Cosmis-MacBook-Air:Desktop cosmi$ cat vidushi.txt
Cosmis-MacBook-Air:Desktop cosmi$ cat vidushi.txt
How to create empty file ?
touch 'filename'
How to check date ?
dateHow to check date ?
touch 'filename'
How to check in which directory you are ?
touch 'filename'
How to check in which directory you are ?
touch 'filename'How to check in which directory you are ?
touch 'filename'Possible ways to use 'less command' ?
How to remove folder with directories & folders inside ?
rm -rf ws
Reverse contents of file
cosmi$ rev
Takshila
alihskaT
mv
wsip-174-79-41-8:test cosmi$ ls
test1 v11 copy.txt v13.txt v2 copy.txt v4 copy.txt v6.txt v9 copy.txt
test2 v11.txt v14 copy.txt v2.txt v4.txt v7 copy.txt v9.txt
v1 copy.txt v12 copy.txt v14.txt v21.txt v5 copy.txt v7.txt
v10 copy.txt v12.txt v15 copy.txt v3 copy.txt v5.txt v8 copy.txt
v10.txt v13 copy.txt v15.txt v3.txt v6 copy.txt v8.txt
wsip-174-79-41-8:test cosmi$ mv v2.txt /Users/cosmi/test/test1/
less
less
ps -ef | less
Reference
wc
wc stands for word count. As the name implies, it is mainly used for counting purpose.
- It is used to find out number of lines, word count, byte and characters count in the files specified in the file arguments.
- By default it displays four-columnar output.
- First column shows number of lines present in a file specified, second column shows number of words present in the file, third column shows number of characters present in file and fourth column itself is the file name which are given as argument.
wsip-174-79-41-8:~ cosmi$ cd test
wsip-174-79-41-8:test cosmi$ wc v1.txt
39 560 3501 v1.txt
wsip-174-79-41-8:test cosmi$ wc v1.txt v2.txt
39 560 3501 v1.txt
0 0 0 v2.txt
39 560 3501 total
wsip-174-79-41-8:test cosmi$
Memory related commands
du
$du -a test
/*now using du to produce
sorted output */
$du -a test | sort -n
~ cosmi$ du |less -N
df
How to check in diskspace ?
df- diskspace .
Reference
https://www.geeksforgeeks.org/df-command-linux-examples/
File compression & extraction command
zip
wsip-174-79-41-8:~ cosmi$ zip test.zip test
adding: test/ (stored 0%)
unzip
tar
How to search in files ?
How to check in environment ?
Linux : printenv
$du -a test /*now using du to produce sorted output */ $du -a test | sort -n
Commands to shutdown or force reboot
reboot -f |
reboot |
shutdown |
shutdown |
shutdown -h now |
shutdown |
shutdown |
* * * * * command to execute │ │ │ │ │ │ │ │ │ └─── day of week (0 - 6) (0 to 6 are Sunday to Saturday, or use names; 7 is Sunday, the same as 0) │ │ │ └──────── month (1 - 12) │ │ └───────────── day of month (1 - 31) │ └────────────────── hour (0 - 23) └─────────────────────── min (0 - 59)
Cosmis-MacBook-Air:Desktop cosmi$ crontab
1 * * * * * * date
* * * * * * echo "Takshila"
min hour date month dow
Cosmis-MacBook-Air:Desktop cosmi$ test $(time)
real 0m0.000s
user 0m0.000s
sys 0m0.000s
Cosmis-MacBook-Air:Desktop cosmi$ test $(date)
-bash: test: too many arguments
Cosmis-MacBook-Air:Desktop cosmi$
TEXTEDITOR
NANO
VI
CRON TAB
OPENS UP EDITOR
Cosmis-MacBook-Air:Desktop cosmi$ crontab -e
Getting permission to edit other s
Cosmis-MacBook-Air:Desktop cosmi$ su crontab -u cosmi
Password:
su: Sorry
Cosmis-MacBook-Air:Desktop cosmi$
Last login: Sun Apr 1 21:49:31 on ttys000
Cosmis-MacBook-Air:~ cosmi$ cd Desktop
java-version
chmod- Changing file mode
-bash: wakeup.sh: command not found
Cosmis-MacBook-Air:Desktop cosmi$ chmod +x wakeup.sh
Cosmis-MacBook-Air:Desktop cosmi$ bash wakeup.sh
mac os x
Cosmis-MacBook-Air:Desktop cosmi$
export- Setting environmental variables
export JAVA_HOME =/Library/Java/Home
export M2 =$M2_HOME/bin
export MAVEN_OPTS = -Xmx256m-Xmx512
export PATH = $M2:$PATH
Cosmis-MacBook-Air:Desktop cosmi$ ls
Atom alias
BOOKS -2018
CLOSURE
Postman alias
clear
pwd- show the files
Cosmis-MacBook-Air:Desktop cosmi$ pwd
/Users/cosmi/Desktop
Cosmis-MacBook-Air:Desktop cosmi$
list- show the list of files
Cosmis-MacBook-Air:Desktop cosmi$ ls -lrt
total 21208
-rw-r--r--@ 1 cosmi staff 948 May 3 2017 Eclipse
-rw-r--r--@ 1 cosmi staff 800 May 6 2017 pgAdmin 4
-rw-r--r--@ 1 cosmi staff 788 Jun 9 2017 STS
-rw-r--r--@ 1 cosmi staff 944 Jul 15 2017 Postman alias
-rw-r--r--@ 1 cosmi staff 928 Aug 5 2017 Atom alias
drwxr-xr-x@ 3 cosmi staff 102 Aug 10 2017 Skype.app
drwxr-xr-x@ 13 cosmi staff 442 Oct 25 11:31 Umlet
-rw-r--r--@ 1 cosmi staff 171 Oct 30 12:36 ~$FINANCE.xlsx
drwxr-xr-x@ 46 cosmi staff 1564 Dec 15 19:00 CODING EXAMPLES
-rw-r--r--@ 1 cosmi staff 210141 Jan 11 15:30 CV.pdf
drwxr-xr-x 6 cosmi staff 204 Jan 24 11:34 spring-main
drwxr-xr-x 40 cosmi staff 1360 Feb 26 16:07 CLOSURE
drwxr-xr-x 10 cosmi staff 340 Mar 1 16:14 H1-B
touch [-A [-][[hh]mm]SS] [-acfhm] [-r file] [-t [[CC]YY]MMDDhhmm[.SS]] file ...
Cosmis-MacBook-Air:Desktop cosmi$ touch -r wakeup.sh
usage:
touch [-A [-][[hh]mm]SS] [-acfhm] [-r file] [-t [[CC]YY]MMDDhhmm[.SS]] file ...
touch- Create new file
Cosmis-MacBook-Air:Desktop cosmi$ touch vidushi.txt
Cosmis-MacBook-Air:Desktop cosmi$ touch -t YYMMDDHHMM.SS tecmint
Cosmis-MacBook-Air:Desktop cosmi$
cat-Read the contents of new file
Cosmis-MacBook-Air:Desktop cosmi$ cat vidushi.txt
HI Takshila !
I hope you get up see a brighter day !
you Deserve it baby
Regards
Vidushi
cp - To copy one or more files to another location.
Cosmis-MacBook-Air:Desktop cosmi$
head - to read first n lines} used with logs
Cosmis-MacBook-Air:~ cosmi$ cd Desktop
Cosmis-MacBook-Air:Desktop cosmi$ head vidushi.txt
Cosmis-MacBook-Air:Desktop cosmi$ head -15 vidushi.txt
Cosmis-MacBook-Air:Desktop cosmi$ head -5 vidushi.txt
Cosmis-MacBook-Air:Desktop cosmi$ head -n 4 *.txt
hihiiiiiiiiiiii
aaaaaaaaaaaa
tail - to read first n lines used with logs
bkbjkhjh
Cosmis-MacBook-Air:Desktop cosmi$ tail -100 vidushi.txt
su- changing user .
Cosmis-MacBook-Air:Desktop cosmi$ Iam@peace
-bash: Iam@peace: command not found
Cosmis-MacBook-Air:Desktop cosmi$ su postgres
Password:
su: Sorry
Cosmis-MacBook-Air:Desktop cosmi$
df- diskspace .
Cosmis-MacBook-Air:Desktop cosmi$ df
Filesystem 512-blocks Used Available Capacity iused ifree %iused Mounted on
/dev/disk1 487882752 172922432 314448320 36% 2176290 4292790989 0% /
devfs 358 358 0 100% 620 0 100% /dev
map -hosts 0 0 0 100% 0 0 100% /net
map auto_home 0 0 0 100% 0 0 100% /home
/Applications/sts-bundle/STS.app 487882752 173156032 314214720 36% 2176485 4292790794 0% /private/var/folders/p9/t2pt77xd77z4k4qlsq2pqy6c0000gn/T/AppTranslocation/12746F0F-436A-413B-9342-7CFB7B3A25D8
du- disk usage.
Cosmis-MacBook-Air:Desktop cosmi$ du
env- environment.
Cosmis-MacBook-Air:Desktop cosmi$ env
TERM_PROGRAM=Apple_Terminal
SHELL=/bin/bash
TERM=xterm-256color
TMPDIR=/var/folders/p9/t2pt77xd77z4k4qlsq2pqy6c0000gn/T/
Apple_PubSub_Socket_Render=/private/tmp/com.apple.launchd.85T4B3WwtO/Render
TERM_PROGRAM_VERSION=388.1.1
OLDPWD=/Users/cosmi
TERM_SESSION_ID=4B5D5D77-84D3-4ECB-92A3-B75D577DE595
USER=cosmi
SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.AK4CN05Wkm/Listeners
__CF_USER_TEXT_ENCODING=0x1F5:0x0:0x0
PATH=/Library/Frameworks/Python.framework/Versions/3.6/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
PWD=/Users/cosmi/Desktop
LANG=en_US.UTF-8
XPC_FLAGS=0x0
XPC_SERVICE_NAME=0
SHLVL=1
HOME=/Users/cosmi
LOGNAME=cosmi
_=/usr/bin/env
Cosmis-MacBook-Air:Desktop cosmi$ printenv
TERM_PROGRAM=Apple_Terminal
SHELL=/bin/bash
TERM=xterm-256color
TMPDIR=/var/folders/p9/t2pt77xd77z4k4qlsq2pqy6c0000gn/T/
Apple_PubSub_Socket_Render=/private/tmp/com.apple.launchd.85T4B3WwtO/Render
TERM_PROGRAM_VERSION=388.1.1
OLDPWD=/Users/cosmi
TERM_SESSION_ID=4B5D5D77-84D3-4ECB-92A3-B75D577DE595
USER=cosmi
SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.AK4CN05Wkm/Listeners
__CF_USER_TEXT_ENCODING=0x1F5:0x0:0x0
PATH=/Library/Frameworks/Python.framework/Versions/3.6/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
PWD=/Users/cosmi/Desktop
LANG=en_US.UTF-8
XPC_FLAGS=0x0
XPC_SERVICE_NAME=0
SHLVL=1
HOME=/Users/cosmi
LOGNAME=cosmi
_=/usr/bin/printenv
Cosmis-MacBook-Air:Desktop cosmi$
Cosmis-MacBook-Air:Desktop cosmi$ who
cosmi console Apr 1 21:25
cosmi ttys000 Apr 1 22:53
Cosmis-MacBook-Air:Desktop cosmi$ whoami
cosmi
Cosmis-MacBook-Air:Desktop cosmi$
Cosmis-MacBook-Air:Desktop cosmi$ find vidushi.txt
vidushi.txt
Cosmis-MacBook-Air:Desktop cosmi$ find vidushi.txt
find: vidushi.txt: No such file or directory
Cosmis-MacBook-Air:Desktop cosmi$ find vidushi.txt
vidushi.txt
Cosmis-MacBook-Air:Desktop cosmi$
less- filename | to read contents of file.
Cosmis-MacBook-Air:~ cosmi$ less vidushi.txt
vidushi.txt: No such file or directory
Cosmis-MacBook-Air:~ cosmi$ cd Desktop/
Cosmis-MacBook-Air:Desktop cosmi$ less vidushi.txt
kill process no
Cosmis-MacBook-Air:~ cosmi$ ps -ef|grep java
501 1403 1391 0 9:56AM ttys000 0:00.00 grep java
Cosmis-MacBook-Air:~ cosmi$ kill 1391
Cosmis-MacBook-Air:~ cosmi$
------------------------------------------------------------------------------------------------
GREP i
Cosmis-MacBook-Air:Desktop cosmi$ ps -ef|grep java
501 1641 1629 0 11:38AM ttys005 0:00.00 grep java
Cosmis-MacBook-Air:Desktop cosmi$ ps -ef|grep $(which java)
501 1644 1629 0 11:39AM ttys005 0:00.00 grep /usr/bin/java
Cosmis-MacBook-Air:Desktop cosmi$
grep
does just text match, it doesn't have idea of process name or filename etc.
that is, if you have a python script called
likejava.py
, it will be in result too.
Back to your question, your
*.java
is not good, because grep works with regex, not glob patterns.
You could try:
ps -ef|grep $(which java)
this will list java processes, but only for your default java installation. If you have more than one Java installed, e.g. your Jboss with java7, tomcat with java6, and eclipse with java5, this will fail.
There is another tool called
pgrep
. You could give it a try, e.g.pgrep -l java
you could do
man pgrep
to get more info:pgrep, pkill - look up or signal processes based on name and other attributes
EDIT add a small ps..|grep trick
just saw your output in the question:
You have
grep *.java
in output, it is a good example. grep *.java
is not java process but it has text "java". so it is there.
You could avoid it by
ps...|grep [j]ava
works for bash.
Cosmis-MacBook-Air:Desktop cosmi$ ps -ef|grep java
501 1641 1629 0 11:38AM ttys005 0:00.00 grep java
Cosmis-MacBook-Air:Desktop cosmi$
------------------------------------------------------------------------------------------------
free : free memory
------------------------------------------------------------------------------------------------
ps
ps | ps-t | ps-xsless : prints snap shot of current process |
The ps (i.e., process status) command is used to provide information about the currently running |
Cosmis-MacBook-Air:Desktop cosmi$ ps aux
USER PID %CPU %MEM VSZ RSS TT STAT STARTED TIME COMMAND
cosmi 1483 15.4 6.3 4046388 264948 ?? S 11:14AM 2:33.31 /Applications/Google Chrome.app/Contents/Versions/65.0.3325.181/Goog
cosmi 271 13.9 5.8 3999528 244628 ?? S 9:25PM 28:17.33 /Applications/Google Chrome.app/Contents/MacOS/Google Chrome -psn_0_
cosmi 453 3.4 1.1 3406548 47100 ?? S 9:25PM 0:23.94
Cosmis-MacBook-Air:Desktop cosmi$ ps -p 1483
PID TTY TIME CMD
1483 ?? 2:46.05 /Applications/Google Chrome.app/Contents/Versions/65.0.3325.181/Google Chrome Helper.app/Contents/MacOS/Google Chrome Help
Cosmis-MacBook-Air:Desktop cosmi$ ps -p 271
PID TTY TIME CMD
271 ?? 28:33.33 /Applications/Google Chrome.app/Contents/MacOS/Google Chrome -psn_0_28679
Cosmis-MacBook-Air:Desktop cosmi$
TOP - GIVES DETAILS OF
Processes: 265 total, 2 running, 263 sleeping, 1336 threads 11:31:29
Load Avg: 1.81, 1.88, 1.94 CPU usage: 12.44% user, 7.65% sys, 79.90% idle SharedLibs: 88M resident, 30M data, 7716K linkedit.
MemRegions: 52995 total, 805M resident, 38M private, 260M shared. PhysMem: 4072M used (1273M wired), 23M unused.
VM: 726G vsize, 633M framework vsize, 262014(0) swapins, 427719(0) swapouts. Networks: packets: 429346/530M in, 148614/20M out.
Disks: 402514/8529M read, 115953/4538M written.
PID COMMAND %CPU TIME #TH #WQ #PORT MEM PURG CMPRS PGRP PPID STATE BOOSTS %CPU_ME %CPU_OTHRS UID FAULTS COW
1567 top 3.6 00:00.62 1/1 0 20 2668K+ 0B 0B 1567 1541 running *0[1] 0.00000 0.00000 0 3843+ 105
1564 Google Chrom 0.0 00:00.36 15 1 134 12M 0B 11M 271 271 sleeping *0[1] 0.00000 0.00000 501 18605 1603
1559 mdworker 0.0 00:00.20 4 1 48 11M 0B 1132K 1559 1 sleeping *0[1]
top usage: top
[-a | -d | -e | -c ]
[-F | -f]
[-h]
[-i ]
[-l ]
[-ncols ]
[-o ] [-O ]
[-R | -r]
[-S]
[-s ]
[-n ]
[-stats ]
[-pid ]
[-user ]
[-U ]
[-u]
- sudo ("superuser do", or "switch user do") allows a user with proper permissions to execute a command as another user, such as the superuser.
- sudo allows a permitted user to execute a command as another user, according to specifications in the /etc/sudoers file.
ps | ps-t | ps-xsless : prints snap shot of current process |
su |
sudo |
chmod -777 |
java -XX:+PrintFlagsFinal -version | grep -iE 'HeapSize|PermSize|ThreadStackSize' |
java -XX:+PrintFlagsFinal -version | grep -iE 'HeapSize|PermSize|ThreadStackSize' |
pgrep -f desired_program_name |
in progress |
-
java -XX:+PrintFlagsFinal -version | grep -iE 'HeapSize|PermSize|ThreadStackSize'
pgrep -f desired_program_nameReferences
References
exit |
whatis |
clear |
man |
less |
pwd |
ls |
cd |
bash |
cat |
type |
alias |
whoami |
whereis |
date |
touch |
file |
which |
echo |
nano |
ln |
mkdir |
cp |
mv |
rm |
wc |
head |
tail |
apropos |
find |
sort |
uniq |
cut |
diff |
comm |
sdiff |
paste |
join |
grep |
sed |
calender |
cal |
sleep |
crontab |
ps |
printenv/env |
export |
set |
unset |
stat |
df |
du |
free |
pg |
more |
emacs |
vim |
history |
kill |
bg |
chsh |
uname |
jobs |
dpkg |
apt-get |
apt-cache |
aptitude |
gzip |
gunzip |
bzip2 |
xz |
zip |
tar |
rsync |
chmod R -777 |
chown |
id |
su |
sudo |
passwrd |
adduser |
ping |
traceroute |
ftp |
wget |
ssh |
source |
time |
read |
xargs |
tee |
printf |
test |
if |
function |
while |
case |
for |
until |
fold |
top |
vi filname |
ps aux |
java -XX:+PrintFlagsFinal -version | grep -iE 'HeapSize|PermSize|ThreadStackSize' |
java -XX:+PrintFlagsFinal -version | grep -iE 'Xms|Xmx' |
dzdo su
open /tmp
ls -la /tmp
rm /tmp
sudo rm /tmp
sudo rmdir /tmp
sudo unlink /tmp
unlink: /tmp: Operation not permitted
touch /tmp/test
ls -al /tmp
ls -al /tmp/
ls -la /var/log
ls -la /var/sfsite
cd /dist/
ls -l
rm sfsit
rmdir -f sfsite
rm -f sfsite
rm -f sfsite
cd sfsite/
takshila:sfsite takshila.vidushi$ ls -la
takshila:sfsite takshila.vidushi$ cd ..
mv sfsite/ sfsiteold
ln -s ~/og
ln -s ~/og
ln -s ~/og/
ln -s ~/og-deployment/dist/
ls -la
pwd
/dist
ln -s ~/og-deployment/dist/sfsite/
ls -la sfsite
lrwxr-xr-x 1 takshila.vidushi admin 50 Jun 5 16:21 sfsite -> /Users/takshila.vidushi/og-deployment/dist/sfsite/
ls -la sfsite/
ls -la /dist/
ls -la /dist/sfsite/
ls -latr /var/log/sfsite/
less /var/log/sfsite/groutingadmin.2019-06-05.log
less /var/log/sfsite/gateway.2019-06-05.log
2019-06-05 16:26:14,698 HttpTransportServlet INFO [ localhost-startStop-1]: Initialized CamelHttpTransportServlet[name=CamelServlet, contextPath=/gateway]
|
pgrep -f desired_program_name |
No comments:
Post a Comment