Tuesday, October 6, 2020

linux commands for system admin

linux commands for system admin

1) Access via pem file

ssh -i ubuntu.pem ubuntu@192.168.20.201


2) Zip with exclude some file

zip -r httpdocs.zip httpdocs --exclude *.svn* --exclude *.git*


3) Apply permission along subfolder exclude files

find permission-test/ -type d -exec chmod 700 {} \;

4) Apply permission along files exclude folder

find ! -type d -exec chmod 700 {} \;

find . -name \*test.txt -type f -exec rm -f {} \;                  -----> Delete all the matching file's with the same name

find /home -type f -name "*.tar.gz" -exec du -sh {} \;

find . -type f -name "*.zip" -size +1G -exec du -sh {} \;

find . -name "*.tar.gz" -type f -mmin +15 -delete                  -----> Delete files older than 15 min

find /var/log/apache2/ -name "*.gz" -mtime +5 -delete              -----> Delete files older than 5 days

find . -exec grep -Rnw 'India' {} \;                      ------>  Find a Specific Word in a File

5) Drag file from server

 scp ubuntu@ip/home/ubuntu/pagal  /home/adminstrator


6) Drop & Drag file in server

rsync -avzh --progress (file-name)  ssh ubuntu@ip:/home/ubuntu          ----> Drop file in server

rsync -avzh --progress root@127.0.0.1:/root/html.tar.gz  .           ----> Drag file from server


7) Change xtaract location

tar -xvf new.tar -C /home/administrator/Desktop/


8) Mysql dump

mysqdump -u root -p database_name > database.sql           -------> For Single DB

mysqldump -u root -p --all-databases > alldb.sql                     ------> For All DB

9) mysql dump restore

 mysql -u root -p database_name < database.sql


10) Enable and disable any service in ubuntu

sudo update-rc.d atd disable


11) For directoy

find /home/USERNAME/public_html -type d -exec chmod 755 {} \;


12) For files

find /home/USERNAME/public_html -type f -exec chmod 644 {} \;


13) check connectivity source to destination

traceroute 31.170.123.130 


14) resolve ip to name and name to ip

nslookup domain_name or ip_address


15) delete 10 days older data

0 9 * * * /usr/bin/find /home/ubuntu/database_backup -name "*.gz" -type f -mtime +10 -exec rm -f {} \;


  • If telnet showing connected that mean port opened/enabled
  • If telnet showing Trying that mean port closed/disabled

$ telnet   ip-address   port-number


nmap -p 22  100.100.7.32                                      ------------> same work as telnet

nmap -sT 100.100.7.32                                              ------------> Check how many port open 


17) Automatically open selected link in browser 

gnome-open https://tech2towards.blogspot.com


18) ss command is a tool that is used for displaying network socket related information

$  ss


19) show running time open ports

sudo netstat -tulpn

 

20) Check all the process id via mentioned port no of postgres

sudo ss -lptn 'sport = :5432'


21) Show hosting deatils

whois IP_address/Domain_name


22) How to find perticular folder path

find $HOME -type d -name ".git"


23) download file form server "file should be under Document root of webserver"

wget https://tech2towards.com/mysqldump.sql


24) Check All service status

sudo service --status-all


25) Replace the words from abc to XYZ in file via terminal

sed -i -e 's/abc/XYZ/g' test.txt


26) change string with specific line number

sed -i '5s/Best/Next/' demo-file.txt

sudo sed -i '812s/max_file_uploads = 20/max_file_uploads = 200/' php.ini

sed -i '/host/s/^#//g' input.txt                                  -----------> To Uncomment 

sed -i '/2001/s/^/#/g' input.txt                                  -----------> To Comment Out

27) delete user password

password --delete user_name_1


28) grep one and more string with \| symbol

grep 'max_file\|memory_limit' php.ini


29) To delete all files with the exception of filename1 and filename2:

rm -rf -v !("filename1"|"filename2")


30) Get the mac addrss list

arp

Get the mac addrss list with system name like hp

arp-scan -l   


31) Check installed package in ubuntu

apt list --installed


32)  Calculate loadavarage

grep 'cpu ' /proc/stat | awk '{usage=100-($5*100)/($2+$3+$4+$5+$6+$7+$8)} END {print usage}'


33) Termial Trash Location

~/.local/share/Trash/files 


34) View PHP version and extionson 

php --ini


35) Delete user password

password --delete user_name

36) View site without cache (if existing code loading)

http://tech2towards.tech/?nocache

37) Check installed packages in ubuntu

dpkg -l | grep mysql

38) Delete user account with home directory

sudo deluser --remove-home itadministrator

39) Calculate load avarage by Command.

cat /proc/loadavg | cut -c 1-4 | echo "scale=2; ($(</dev/stdin)/`nproc`)*100" | bc -l

40) Calculate load avarage by calculating.

load_avarage/no_of_cpu*100 (3.56/4*100) = 89%

41) Glances is a monitoring tool as similar as TOP

glances

42) Dig is similar to nslookup, but dig has advance feature

dig tech2towards.tech

dig tech2towards.tech ANY

43) Open website without domain name in shared hosting server

http://server_ip/~cpaneluser

Basically, the website can be checked using the temporary URL (http://server_ip/~cpanelusername/) on cPanel before switching DNS. But for security reason, many hosting providers don’t allow to access the website via server IP address or temporary URL.

Due to this, mod_userdir is disabled and you don’t have permission to enable it on your shared hosting. However, there has another option to test your website before pointing domain name or update DNS records with the new server.

44) Apply same permission of older directory to New directory

sudo chmod --reference Older_directory  New_directory

45) Apply same permission of older directory to New directory

sudo chown --reference Older_directory  New_directory

46) Generate password via this command

apg -n 1 -MCLN -m 16 -s

47) Check installed software

dpkg -l *python2.7*

48) User for set default permission for all file/directory

umask


49) Root user also not delete this file (+ for apply and - for remove)

chattr +i file.txt

check chattr applied or not

lsattr    file.txt

50) (-i use for casesenitive) (-r use for recursive)

grep -i -r  "server_name" /etc/nginx/sites-available/

51) View all deatils

/usr/sbin/mysqld --help --verbose

52) kill service by PID

kill -9 PID

53) Kill service by Process name

killall firefox

54) Testing load on CPU and RAM

stress --cpu 8 --io 4 --vm 4 --vm-bytes 512M --timeout 10s

55) Extract .gz file in linux

gzip -d  linux.gz

56) Compress through zip extention

zip -r linux.zip linux

Extract file through unzip

unzip linux.zip

57) Create multiple directory with absolute

mkdir -p a/b/c/d/e/f

create multiple directory in same path

mkdir -p a/b/c/d/e/f/{subhash,sachin}

58) view all content under "Folder" directory with recursive

ls -R Folder

59) replace word in vim editor

:%s/map/gap

60) Forcefully restart/shutdown window (write cmd in RUN)


shutdown -r -f -t 00
shutdown -s -f -t 00

61) View detailed info about installed package.

dpkg --status apache2 

62) See last reboot log details

last reboot 

63) Show process details in advance

iotop , iostat , atop

64) SHow history with date and time

echo 'HISTTIMEFORMAT="%F %T "' >> ~/.bashrc

65) Replace the word from file

sed 's/unix/linux/g' demofile.txt

66) Show All Hidden Files

du -sh .[^.]* 

67) Find Out which process is eating much CPU & RAM

ps -eo pmem,pcpu,pid,user,args | sort -k 1 -r | head -10 

68) Make it short terminal host

export PS1="\u$" 

69) Install Multiple Services In Single Command

sudo sh -c 'apt update && apt install vim'

70) who and w (This command shows the information about the users currently on the machine and their processes.)

 who   and    w 


Kill Remotey Connected User Terminal Access Only (after w cmd)

sudo pkill -9 -t pts/5 

71) It Will Kill All Process Which Are Running By User

pkill -u user_name

72) If You Get 1 For hard disks & 0 for a SSD.

cat /sys/block/sda/queue/rotational

73) trash-list , trash-restore

sudo apt-get install trash-cli

74) Find a Specific Word in a File

$ grep -Rnw '/home/ubuntu/Desktop' -e 'India'

Reduce Unnecessary timing to find exact word

$ grep --exclude=*.csv -Rnw '/home/ubuntu/Desktop' -e 'India'

75) Excute Commands Without Login SSH Terminal

ssh root@10.10.3.4 'uptime'
ssh root@10.10.3.4 'ls /var/www/html/'

76) Make a User an Administrator in Ubuntu via cli

sudo adduser user_name sudo 

77) Locate command is an reliable & better alternative of find cmd.

locate -b demo-file.txt


78 ) ......To Be Continue





No comments:

Post a Comment

testing