Tuesday, September 10, 2019

Linux commands for day to day use

file search
1. print top lines
head sample.log
head -n 20 /path/to/logfile.log

2. print bottom lines
   tail  sample.log
   
terminal commands
control A - begining of the line
control E - end of the line
control right arrow
control left arrow
control U start line delete
control K start from custor delete 


file system

cd 
when folder name has space
cd Exercise Files error
cd Exercise\ Files

ls -R inside directory
ls --color=always


rm -sample?.txt

vs

cat sample.txt | cat -n | tail -n4

grep "hello" sample.txt - simple search
grep -in "hello" sample.txt - with line numbers /ignore case with line numbres
grep -vi "hello" sample.txt - with line numbers /ignore matching case and print remaining
grep -n "hello" sample.txt - with line numbers
grep -E "[hijk]" sample.txt - search for letters and shows the results
grep -E "/w{6,}" sample.txt - count words and shows the results


log analysis with awk command
awk '/error/ {print}' /var/log/syslog
awk '{print $2}' sample.txt
awk '{print $2 "\t" $1}' sample.txt | sort -n  more filter on tablular data 

sed s/Orange/Red/ sample_data  to edit& replace text
s for substitute
g for global replace

sort sample.txt
sort -k2 -n sample.txt sort the data
sort -u sample.txt - remove dublicates only unique print
rev tac tr



tar -xvf log.tar.gz 


log analysis
less filename
cat filename | grep "string" | awk '{print $9}' |sort -u > users.txt

free -h
cat /proc/cpuinfo - c

df -h memory information 





copy the text from ssh editor to local 

cntrl+insert for copy
shift +insert for paste

grep commands for daily use

 grep -B 3 -A 2 'Invalid user' /var/log/auth.log
https://www.loggly.com/ultimate-guide/troubleshooting-with-linux-logs/

scp command to transfer files

1. search text in vi editor

  1. Press ESC key.
  2. Type /vivek.
  3. Hit n to search forwards for the next occurrence of word named “vivek”. You can press N to search backwards.

Find Files linux commad


find / -name "*conf" 
find /home/exampleuser/ -name "*conf" 

2. How to unpack (ungzip, unarchive) a tar.gz file

For many systems, REBOL is distributed as a tar gz file. This is a common archive format. Here's how to unpack it...

For tar.gz

To unpack a tar.gz file, you can use the tar command from the shell. Here's an example:
tar -xzf rebol.tar.gz
The result will be a new directory containing the files.
(Also, on many systems, when you download the tar.gz from a web browser, an unpacker will open, and you can just use that.)

For just .gz (.gzip)

In some cases the file is just a gzip format, not tar. Then you can use:
gunzip rebol.gz
In order to execute it, you will need to add execute permissions to the file:
chmod +x rebol


for more refer below videos on detailed commands


Vi Editor

 vi editor move in the editor : h right j up k  down l left move top shift +g gg down line of the file :8 go to line 8 /string - search n ke...