User Tools

Site Tools


linux:shellcommands

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
linux:shellcommands [2015/07/28 09:35] – [Job and process commands] adminlinux:shellcommands [2018/05/05 13:00] – [sed] admin
Line 20: Line 20:
 ==== date ==== ==== date ====
   * set date<code bash>   * set date<code bash>
-date +%Y%m%d -s "20120226"   
-date +%T -s "11:12:00"   
 date +%Y%m%d -s "20120120"   date +%Y%m%d -s "20120120"  
 date +%T -s "16:00:00" date +%T -s "16:00:00"
-date +%Y%m%d -s "20120130" 
-date +%T -s "13:43:00" 
   </code>   </code>
   * display date<code bash>   * display date<code bash>
Line 33: Line 29:
   * convert unixtime<code bash>   * convert unixtime<code bash>
   date -d @1098181096   date -d @1098181096
-</code>  +</code> 
 +  * sync time:<code bash> 
 +ntpdate  pool.ntp.org 
 +</code>
 ===== file and directory commands ===== ===== file and directory commands =====
 ==== dirname ==== ==== dirname ====
Line 44: Line 43:
 ls -1 ls -1
 </code> </code>
-==== find ==== +==== find files in directory==== 
-  find . -name dev+<code bash> 
 +find . -name filename 
 +</code>
 ==== ln ==== ==== ln ====
   ln [OPTION]... TARGET [LINK_NAME]   ln [OPTION]... TARGET [LINK_NAME]
Line 56: Line 57:
   df -ah   df -ah
   df -h   df -h
 +==== lock/unlock file and directory ====
 +<code bash>
 +cd /home/admin/conf
 +lsattr -a
 +-------------e- ./web
 +----i--------e- ./.
 +-------------e- ./..
 +-------------e- ./dns
 +-------------e- ./mail
 +</code> => directory /home/admin has attribute **i** => can't remove or create new files in this directory with root
 +And remove this attribute<code bash>
 +chattr -i /home/admin/conf/
 +</code>
 ===== Shell Security ===== ===== Shell Security =====
 ==== chmod ==== ==== chmod ====
Line 123: Line 137:
 apache    5553  0.5 11.2 301832 56404 ?        S    16:20   0:02 /usr/sbin/httpd apache    5553  0.5 11.2 301832 56404 ?        S    16:20   0:02 /usr/sbin/httpd
 </code> </code>
-==== check memory information ====+==== Check memory information ====
 Memory space is divided into memory **used by processes, disk cache, free memory and memory used by kernel** Memory space is divided into memory **used by processes, disk cache, free memory and memory used by kernel**
 Some basic parameters in memory information: Some basic parameters in memory information:
Line 265: Line 279:
 00007f1b27b18000    3268    1664       0 r-x--  libphp5.so 00007f1b27b18000    3268    1664       0 r-x--  libphp5.so
 00007f1b31f4a000  123012  122464  122464 rw---    [ anon ] 00007f1b31f4a000  123012  122464  122464 rw---    [ anon ]
 +</code>
 +==== Get all threads of process ====
 +  * Get all threads in linux<code bash>
 +ps -efL
 +</code>
 +  * Get all threads of MySQL(base on config **thread_cache_size**):<code bash>
 +ps -efL | grep mysql
 </code> </code>
 ===== List Open Files for Process ===== ===== List Open Files for Process =====
Line 331: Line 352:
 => get content none sign "#" => get content none sign "#"
 ==== sed ==== ==== sed ====
-sed is program used for editing data +Basic syntax:<code bash> 
- +sed -i 's/original/new/g' file.txt 
-  * Example search and replace string<code bash>+</code> 
 +Explain options: 
 +  * -i = --in-place (i.e. save back to the original file) 
 +The command string: 
 +  * s = the substitute command 
 +  * original = regular expression describing the word to replace (or just the word itself) 
 +  * new = the text to replace it with 
 +  * g = global (i.e. replace all and not just the first occurrence) 
 +Below are some basic examples for searching and replaccing string<code bash>
 cat intro cat intro
 +</code>output:<code>
 The Unix operating system. Unix system The Unix operating system. Unix system
- +</code> 
-sed 's/Unix/UNIX/' intro  =>  Substitute Unix with UNIX +  * Substitute Unix with UNIX: <code bash> 
-The UNIX operating system. Unix system +sed 's/Unix/UNIX/g' intro  
- +</code>  => output:<code> 
-sed --in-place 's/Unix/UNIX/' intro  =>  Substitute Unix with UNIX in file intro +The UNIX operating system. Unix system</code> 
- +  * Substitute Unix with UNIX in file intro: <code bash> 
-sed 's/Unix/UNIX/g' intro   =>  Substitute Unix with UNIX+sed --in-place 's/Unix/UNIX/g' intro 
 +</code> 
 +  Substitute Unix with UNIX<code bash> 
 +sed 's/Unix/UNIX/g' intro
 </code> </code>
   * example with -n option<code bash>   * example with -n option<code bash>
-sed -n '1,2p' intro        +sed -n '1,2p' intro</code>=> Just print the first 2 lines 
-=> Just print the first 2 lines +  * Just print lines containing UNIX: <code bash>
 sed -n '/UNIX/p' intro sed -n '/UNIX/p' intro
-=Just print lines containing UNIX+</code>
   * example Deleting Lines<code bash>   * example Deleting Lines<code bash>
 sed '1,2d' intro sed '1,2d' intro
-=> Delete lines 1 and 2 +</code>=> Delete lines 1 and 2 
 +  * Delete all lines containing UNIX:<code bash>
 sed '/UNIX/d' intro sed '/UNIX/d' intro
-=> Delete all lines containing UNIX+</code> 
 +  * Delete all characters before string<code bash> 
 +sed 's/.*No Warranty/No Warranty/g'
 </code> </code>
 ==== awk ==== ==== awk ====
Line 522: Line 556:
 ( rsync  is  a  program that behaves in much the same way that rcp does, but has many more options and uses the rsync       remote-update protocol to greatly speed up file transfers when the destination file is being updated. ( rsync  is  a  program that behaves in much the same way that rcp does, but has many more options and uses the rsync       remote-update protocol to greatly speed up file transfers when the destination file is being updated.
 The rsync remote-update protocol allows rsync to transfer just the differences between two sets of files across the network connection, using an efficient checksum-search algorithm described in the technical report that accompanies  this package.) The rsync remote-update protocol allows rsync to transfer just the differences between two sets of files across the network connection, using an efficient checksum-search algorithm described in the technical report that accompanies  this package.)
-<code bash> +  * rsync in local<code bash> 
-rsync -avz   --exclude=".svn" "/home/anhvc/web/9thien.com/" /web/9thien.com/</code>+rsync -avz   --exclude=".svn" "/home/anhvc/web/9thien.com/" /web/9thien.com/ 
 +</code> 
 +  * rsync to remote host<code bash> 
 +rsync -avz --exclude=".svn"  -e "ssh -p2222" "/home/anhvc/web" 123.30.245.164:~
 </code> </code>
 ==== rsync on windows ==== ==== rsync on windows ====
Line 559: Line 596:
   00000520 T Java_HelloWorldJNI_sayHelloWorld__   00000520 T Java_HelloWorldJNI_sayHelloWorld__
   00000534 T Java_HelloWorldJNI_sayHelloWorld(int0_t)   00000534 T Java_HelloWorldJNI_sayHelloWorld(int0_t)
-==== svn ==== +
-Create script to checkout on linux: +
-<code bash> +
-#!/bin/bash +
-SVN_USER="dev" +
-SVN_PASS="Zfq2222244123dfdsufXH" +
-SVN_REPO="http://10.30.22.55/svn_Source" +
-SVN_SOURCE="/home/svn_source/MolySource" +
-WEB_SOURCE="/home/MolySource" +
-svn checkout $SVN_REPO --username $SVN_USER --password $SVN_PASS $SVN_SOURCE/ +
-rsync -auvz --exclude=".svn" $SVN_SOURCE/ $WEB_SOURCE/ +
-svn checkout http://222.255.122.147/repos/mole --user mole --password cpRHvPv4 /root/patchs/mole +
-</code>+
 ===== Cygwin ===== ===== Cygwin =====
 ==== Install Cygwin ==== ==== Install Cygwin ====
linux/shellcommands.txt · Last modified: 2022/10/29 16:15 by 127.0.0.1