Tuesday, December 23, 2008

Link, Alias and Environment

Alias
[root]# alias
[root]# alias ls='ls -l'
[root]# unalias ls

[root]# alias le='ls -ltr'
[root]# alias ping='ping -c4'

Links
[root]# ln -s /usr/jakarta-ant-1.6 /usr/local/ant
[root]# ln -s `pwd` newlink

Set/Unset
[root]# set RGS_HOME=/usr/local/rgs
[root]# export RGS_HOME
[root]# unset -v RGS_HOME

Environment
[root]# env
[root]# dmesg --> view the booting process log
[root]# which

CPU information
[root]# uname -r
[root]# cat /proc/cpuinfo
[root]# grep 'physical id' /proc/cpuinfo | sort | uniq | wc -l --> check number of CPUs
[root]# grep ^processor /proc/cpuinfo | wc -l --> check how many virtual processors

Memory information
[root]# cat /proc/meminfo

Manipulating text files

Word count
 [root]# wc readme.txt
 [root]# wc -l readme.txt  --> number of lines
 [root]# wc -w readme.txt  --> number of words

Command substitution
 [root]# rm `cat garbage-files.list.txt` 

Combining commands
 [root]# cp file1 file2; rm file3 
 [root]# grep Austin cities.txt && vi cities.txt
                                      ---------- 
                                           |_ executes vi if grep succeeds
 
 [root]# grep Florida states.txt || grep Missisipi states.txt
 [root]# grep -E '^abc$ ^def$'
 [root]# grep -F -x 'abc def'
 [root]# find joomla/ -type f -print0 | xargs -0 grep "font" 

 [root]# dmesg | grep ^Blue*
 [root]# ifconfig -a | more
 [root]# grep -c '^processor' /proc/cpuinfo
 [root]# grep -i 'orange' /proc/cpuinfo  ---------------------> ignore case
 [root]# grep -B 0 -A 1 --color '^bind' /etc/redis.conf ------> show lines before and after

Grep only uncommented line of configuration
 [root@thermalite ~]# cat /var/lib/pgsql/data/postgresql.conf | awk '{$1=$1;print}' | grep -v "^#" | awk 'NF'
 

TBD


Navigation, find and searches

Show current directory
 [root]# pwd
 
Change directory
 [root]# cd ..
 [root]# cd ../../temp
 [root]# cd ~

List files in directory
 [root]# ls -a ---> list including hidden
 [root]# ls -F ---> list by file type
 [root]# ls -l ---> list long list
 [root]# ls -t ---> list by time-changed
 [root]# ls -u ---> list by time-accessed
 [root]# ls f080[1-6].jpg --> list using globbing

Find file
 [root]# find / -name httpd.conf
 [root]# locate httpd.conf
 [root]# find . -name "httpd.conf" -print

You can also install a UI based program called "mc" or Midnight Commander, to use GUI based file management
[root]# apt-get install mc
[root]# dnf install mc

Copy, move, rename, view and delete files and disk info

Copying files
[root]# cp source.txt destination.txt
[root]# cp me126* /home/me12
[root]# cp -f source.txt destination.txt --> overwrites if existing
[root]# cp -i source.txt destination.txt --> inform before overwriting
[root]# cp -u source.txt destination.txt --> updates if newer file
[root]# cp -r DIR1/ DIR2/ --> recursive copy, including sub-directories

Copying file securely from local to remote server using Linux scp
Username: alexm
Source......(Server A): 10.152.2.11 /home/alexm/export/file.txt
Destination (Server B): 10.152.2.10 /home/alexm/import/
[root]# scp /home/alexm/export/files.txt alexm@10.152.2.11:/home/alexm/import --> local to remote
[root]# scp -R /home/alexm/export alexm@10.152.2.11:/home/alexm/import --> local directory to remote
[root]# scp -R alexm@10.152.2.11:/home/alexm/import /home/alexm/export --> remote to local
[root]# scp alexm@192.168.0.104:file1.txt alexm@192.168.0.105:mydir ----> remote to remote

Copying file securely from local to and from remote server using Putty's pscp.exe
c:\>util\pscp.exe alexm@192.168.0.104:/etc/hosts c:\temp\example-hosts.txt --> remote to local
c:\>util\pscp.exe c:\documents\foo.txt alexm@example.com:/tmp/foo ----------> local to remote
c:\>util\pscp.exe c:\documents\*.doc alexm@example.com:docfiles ------> multiple files to remote
c:\>util\pscp.exe alexm@example.com:source/*.c c:\source ---------> multiple files from remote

Moving/Renaming files
[root]# mv source.txt destination.txt
[root]# mv -R source destination ----------> copy folder recursively
[root]# mv -f source.txt destination.txt --> force overwrites
[root]# mv -i source.txt destination.txt --> inform before overwriting
[root]# mv me126* /home/me12  --> move

rsync files
[root]# UPDATE LATER !!!

Deleting files
[root]# rm -Rf temp/ --> delete directory
[root]# rm -i mytext.txt
[root]# rm -d /usr/home/temp --> delete directory
[root]# rm -r /usr/home/temp --> delete directory recursive

Make/Delete directory
[root]# mkdir -p /home/azm/temp
[root]# mkdir -m 755 /home/azm/temp
[root]# rmdir -p /home/azm/temp

Touch files
[root]# touch blank.txt

View files
[root]# cat readme.txt
[root]# head readme.txt 
[root]# head -n15 readme.txt  --> view first 15 lines
[root]# tail readme.txt  
[root]# tail -n22 readme.txt  --> view last 22 lines 
[root]# less -10 readme.txt  --> view last 10 lines 
[root]# more readme.txt
[root]# cat address | awk `{print $1, $2}'
[root]# vi +/myword test.txt  --> go to line having "myword"
[root]# vi +3 test.txt    --> go to line 3

[root]# lsof -i -f | grep 80 --> list open files

Disk usage
[root]# du        --> disk usage
[root]# df -TH    --> free disk space
[root]# fdisk -l  --> list all partitions
[root]# lvs       --> list volume space
[root]# lvm --> goto lvm command prompt

You can also install a UI based program called "mc" or Midnight Commander, to use GUI based file management
[root]# apt-get install mc
[root]# dnf install mc

Thursday, December 18, 2008

Linux Pilipinas








Welcome to the Linux and Java Blog Home Page, a substantial collection of how-to and help documents to help you get more out of Java and Linux. Check out our Recommended Reading, search using keywords, or just browse through the categories below´´!
alex m.


Users, Groups, Privileges & Ownership


Create group/user
[root]# groupadd webuser
[root]# useradd -g me126904 webuser

Change permission
[root]# chmod a+x myscript.sh
[root]# chmod g-rwx yourscript.sh
[root]# chmod u+rwx g-rx o-rxw yourscript.sh

Change ownership
[root]# chown -R me126904.webuser phpweb/

Change group
[root]# chgrp -hR users /phpweb

Delete user
[root]# userdel -r me126904

Check current user
[root]# who

Gunzip, Tarballs, RPM, yum and apt-get

Unzip and extract contents of tar/gz/bz2
 [root]# gunzip -dc vsftpd-1.1.2.tar.gz | tar xvf -
 [root]# tar jxvf cvs-1.11.tar.bz2
 [root]# tar xvfz jakarta-tomcat-4.1.tar.gz
 [root]# tar -xf archive-10.3.tar
 [root]# gtar xvfz file.tgz
 [root]# bzip2 -d patch-12.3.bz2
 
How to extract multi-part zip files in Linux
[root]# cat zipfiles.* > zipfiles-full.zip
[root]# zip -F zipfiles-full.zip
[root]# unzip zipfiles-full.zip

Create tarballs
 [root]# tar cfzv cvs-1.11.tar.gz /cvs-home
 [root]# tar cfz back-up.11.tar.gz /tmp /etc

List contents of tarballs
 [root]# tar -tzf cvs-1.11.tar.gz

RPM Commands
 [root]# rpm -qa -------------------> list all rpm install
 [root]# rpm -qa | grep 'mysql' ----> list all rpm related to 'mysql'

 [root]# rpm -q mysql   ----------> query a package version
 [root]# rpm -qi mysql    --------> query information about a package
 [root]# rpm -qf /etc/passwd  ----> query information about a package
 [root]# rpm -qlp ypops-0.7.4-0.FC3.i386.rpm ----> list contents of rpm
 [root]# rpm -ql mysql  ----------> list all files of a package

 [root]# rpm -i mysql.rpm -------------> install a package
 [root]# rpm -ivh mysql.rpm  ----------> install a package with verify and hash
 [root]# rpm -ivh --force mysql.rpm ---> force install a package with verify and hash

 [root]# rpm -Uvh mysql.rpm  -----> update a package with verify and hash
 [root]# rpm -e mysql  -------------> remove a package
 [root]# rpm -e --nodeps mysql -----> remove a package ignoring dependencies

 [root]# rpm -qi mysql  ----------> query information about a package
 [root]# rpm -qi mysql  ----------> query information about a package

 [root]# rpm -K VMware-Player-2.5.1-126130.x86_64.rpm ------> verify checksum

yum Commands
 [root]# yum install java------------------> install java including its dependencies
 [root]# yum upgrade java------------------> upgrade java including its dependencies
 [root]# yum update java-------------------> update java including its dependencies
 [root]# yum clean --> cleans and replaces corrupted repository database file

apt-get Commands
 [root]# apg-get install java------------------> install java including its dependencies
 [root]# apt-get upgrade java------------------> upgrade java including its dependencies
 [root]# apt-get clean --> cleans and replaces corrupted repository database file

dnf Commands
 [root]# dnf install java-11-openjdk-devel -y -----> install package including its dependencies
 [root]# dnf update -y ----------------------------> update package including its dependencies
 [root]# dnf remove java-11-openjdk-devel -y ------> cleans and replaces corrupted repository database file