BLOG

Linux Sheet

23 Aug 2013, Posted by BoB in All Posts, Computer Talk, Website Talk

Just some commands that I found useful since using Linux:

http://mysql-apache-php.com/
Above is a good link to get a web server up and running.

/etc/init.d/apache2 start  –  start apache services

/etc/init.d/apache2 stop  –  stop apache services

/etc/init.d/apache2 restart  –  restart apache services

apt-get install <package>  –  install packages

apt-get upgrade  –  upgrade all packages

apt-get remove <package>  –  remove installed package

apt-get –purge remove <package>  –  remove package and config files

read = 4, write = 2, execute = 1 – permission values

chmod 644 <file/directory>  –  change permissions

chown -R <user> <directory>  –  change ownership for entire directory

chgrp -R <user> <directory>  –  change group for entire directory

chown <user> <file>  –  change ownership for file

chgrp <user> <file>  –  change group for file

chown -R <user>:<group> <directory> – change owner and group recursively

a2ensite <virtual site name>  –  enable website

a2dissite <virtual site name>  –  disable website

a2enmod <module>  –  enable module

a2dismod <module>  –  disable module

passwd root  –  change root password

dpkg –get-selections > installed-software  –  create file with a list of installed packages

dpkg –set-selections < installed-software – reinstall packages from the file list

wget http://www.webmin.com/download/deb/webmin-current.deb  –  get latest “webmin” panel

dpkg -i  –  install the deb package

Setting Time:
date -s “1 JAN 2012 12:00:00 GMT”

Setting Timezone:
find / -name localtime
–then–
remove found files
–then–
ln -s /usr/share/zoneinfo/[TIMEZONE] /etc/localtime
–or–
ln -s /usr/share/zoneinfo/US/[TIMEZONE] /etc/localtime

ps aux | less – list running processes

kill [PROCESS ID] – kill process

cat /proc/meminfo – check ram

Check Disks:
fdisk -l

Check Partitions:
df -i
df -l
df -h

Gzip:
gzip -9 [FILE]
gzip -d [FILE]

Decompress a tar (Tape ARchive):
tar xvfz filename.tar.gz
tar xvf filename.tar

Compress Folder:
tar -cvzpf “/PATH/TO/FILE.tar.gz” “/PATH/TO/FOLDER”
*NOTE* will show full path to folder once decompressed on windows

/etc/init.d/[NAME OF SERVICE] [start|stop|status|restart] – restart service(s)

vi /usr/local/apache/conf/modsec2/whitelist.conf – modSecurity file

service httpd restart – restart apache

/etc/init.d/apf restart – restart firewall

service iptables restart – restart iptables

Software Firewall Files:
vi /etc/apf/allow_hosts.rules
vi /etc/apf/deny_hosts.rules

Check TCP/UDP Traffic:
tcpdump.old -i eth0 [tcp/udp] port [PORT# i.e. 53]
tcpdump -i eth0 [tcp/udp] port [PORT# i.e. 53]
tcpdump -i eth0 [tcp/udp] port [PORT# i.e. 53]
tcpdump -i eth0 [tcp/udp] port [PORT# i.e. 53]

Check Port Connectivity (netcat):
using TCP
nc -zvv mit.edu 80
using UDP
nc -zuvv mit.edu 80

Sniff Network Traffic:
netstat -an
find specific string
netstat -an | grep [search string]

Shutdown:
needs root => init 0
any user => shutdown -h now

free -m – check memory cache

sync; echo 3 > /proc/sys/vm/drop_caches – clear memory cache

Create Aliases:
vi /USER/DIRECTORY/.bashrc
–add to file–
alias [ALIAS NAME]=’[COMMAND TO EXECUTE]’

rename [current ext].txt [desired ext].txt.old [target files]*.txt – rename multiple files

ln -s [TARGET DIRECTORY OR FILE] ./[SHORTCUT] – create symbolic link(s)

Add current user to group:
gpasswd -a $USER $GROUP
Remove current user from group:
gpasswd -d $USER $GROUP

Service Boot Behavior:
1. Find out the name of service’s script:
ll /etc/init.d/
2. Add it to chkconfig
sudo /sbin/chkconfig –add [service]
3. Make sure it is in the chkconfig
sudo /sbin/chkconfig –list [service]
4. Set it to autostart
sudo /sbin/chkconfig [service] on
5. To stop a service from auto starting on boot
sudo /sbin/chkconfig [service] off

https://drupal.org/node/1066928generate SSH key

Multiple value grep:
$ cat file | grep ‘error\|warning\|fail’
Reverse grep (exclude term(s)):
$ cat file | grep -i -v ‘error\|warning\|fail’

chmod gu-s [directory] – remove S permissions

find /full/path -type f -exec grep -l “word” {} \+ – recursively search files for a string

find /full/path -mtime -7 – recursively search for files a week old

find /full/path -mmin -60 – recursively search for files one hour old

Insert Line Break After Text In A File:
find *.txt | xargs sed -i ‘s/text/&\n/g’
sed -i ‘s/html code<\/html>/&\n/g’ file.html

One Line For Loops:
Run Command 5 Times
for i in {1..5}; do COMMAND-HERE; done
for((i=1;i<=10;i+=2)); do echo "Welcome $i times"; done Work On Files
for i in *; do echo $i; done
for i in /etc/*.conf; do cp $i /backup; done

Vi/Vim Show Line Numbers
:set number
:set nu
Vi/Vim Hide Line Numbers
:set nu!

Open File At Particular Location
vi +[line number] [target file]
vi +/[search text] [target file]

Add File To Existing ZIP File
move file
zip -m “/full/path/to/file.zip” “file.txt”
copy file
zip -g “/full/path/to/file.zip” “file.txt”

  • Regina Paddilla

    Hello there! Do you know where I can read more sites about this?

    Reply
  • Khach san Ho CHi Minh

    Whats up very nice website!! Man .. Beautiful .. Wonderful .. I’ll bookmark your blog and take the feeds also?I’m glad to seek out a lot of helpful information right here in the submit, we need work out extra strategies in this regard, thank you for sharing. . . . . .

    Reply

Post a comment