Linux : Cammand Linux ค้นหาไฟล์หรือ Directory


200910 Jun

Find

ค้นหา directory หรือ ชื่อไฟล์ใน directory ที่ต้องการค้น ทำไมช่างลำบากยากเข็นกับ command ตัวของกระผมเองยังจำไม่ได้หมดเลยทำไว้เป็นชุดคำสั่งไว้สำหรับกันลืมแล้วก้อเอาแบ่งปันความรู้ให้กับท่านอื่นๆ ที่ใช้ Linux command "." หมายถึง current directory ในการกรณีไม่ใส่ path ในการค้นหา

find . -name "[file name or directory name]" -print
Ex: find  /home/kritr/sitename/  -name "*templates.*.*" -print
Ex: find . -name "*xapian*.*" -print
// look up in current directory and subdirectory to find out where is filename or directory contain the word "xapian" in.

Find wording

find  /export/web/code/ -exec grep -l "<div id=\"newuser\">"  {} \;
// ค้นหาในคำ <div id="newuser"> ทุกไฟล์ใน  /export/web/code/
find . -exec grep -l "postcode" {} \;  
// find "postcode" wording in every file, in current directory.
 
find /home/username/HEAD/production/cust/templates  -exec grep -l "postcode" {} \;  
 //find "postcode" wording in every file, in specific directory

Find and Replace wording

It seems like find wording command, but we use "sed" command instead.
find [directory] -name [specify name] -exec sed -i "s/[find string]/[replace with]/g" {} \;
 // syntax
 find . -name "data.rec" -exec sed -i "s/containsproducts/categorylist/g" {} \;
 // find file name is "data.rec" in current directory and replace string "containsproducts" with "categorylist"

Find and Sort by last modified

It's useful when we would like to check the latest update. Go to directory you would like to check, the run command follow instruction below:  
find . -type f -mtime -[day] -ls | sort -k8,9r
// syntax find = look at present date to previous date [day] and sort with column 8 and 9

find . -type f -mtime -1 -ls | sort -k8,9r
// check yesterday to today and sort by month and day

find . -type f -mtime -3 -exec ls --full-time  {} \; | sort -k6,7

Find and Get the size of all directories in the current directory

find . -maxdepth 1 -type d -print | xargs du -sk | sort -rn
// maxdepth 1 = only category under current directory
// -type d = only directory
// xargs = pass list of directory to du command

Find, then copy to one directory

find [path-looking] -name "[keyword]" -exec cp [--parents] -r {} [destination]\;
 path-looking: directory or folder that we would like to look for (e.g. production/generic/wireframe/USdummycontent)
 keyword: wording to specific to find (e.g. data.rec, ae, wz*.*)
  --parents: append source path to DIRECTORY
  -r: copy directories recursively
  destination: directory or folder you would like to copy to

 Example:
find production/generic/site/language/  -name "fr" -exec cp --parents -r {} only_th/ \;
 (copy all fr folders to only_th folder)

Find, then copy to the same directory

find [path] -name "[keyword]" | awk '{print "cp -r "$1" "$1";"}' | sed "s/[keyword]\;/[newkeyword]/g" | sh

Ex:find . -name "en" | awk '{print "cp -r "$1" "$1";"}' | sed "s/en\;/ae/g" | sh

หมวดหมู่สินค้า

ขายหูฟัง Sennheiser CX500, Sennheiser CX300 , Sennheiser MM50, Monster Beats , Bose in ear
รับ Preorder หูฟังจากต่างประเทศ

Earphone
(20)

รวม หูฟังทุกรุ่นต่าง ๆ ใน Shop

Sennheiser
(7)

ขาย หูฟัง Sennheiser CX500,ขาย หูฟัง Sennheiser CX300, ขาย หูฟัง Sennheiser MM50

AKG
(3)

หูฟัง AKG ใน Shop

Creative
(1)

หูฟัง Creative ใน shop

DIY
(4)

DVD และ VCD การสอนต่างๆและเรียนรู้ต่างๆด้วยด้วยตัวเอง

Bose
(1)

รวมหูฟังยี่ห้อ Bose

Bluetooth stereo
(5)

รวมหูฟัง อุปกรณ์ บูลทูธ ต่าง ๆ
และ หูฟังบูลทูธสเตอริโอสำหรับฟังเพลง

Finger Style Guitar
(7)

รวม DVD แนวเพลง Finger Style Guitar ต่างๆ

fingerstyle
(3)

DVD และ VCD เพลงแนว Finger Style Guitar

Tommy Emmanuel
(3)

รวมงานเพลง Tommy Emmanuel
แนว Finger Style Guitar

pair bluetooth
(1)

วิธีการ Pair อุปกรณ์ Bluetooth ต่าง ๆ

SMF
(2)

บทความและความรู้ด้านการพัฒนาเว็บไซต์

css
(11)

บทความเกี่ยวกับ CSS, เทคนิคต่าง ๆในการใช้ CSS เรียนรู้การแก้ไขต่าง ๆ

css hack
(4)

บทความเกี่ยวกับ CSS, เทคนิคในการปัญหา cross browser ในการแสดงผลของ browser ที่แตกต่าง ๆ กัน

drupal
(12)

บทความเกี่ยว Drupal แนะนำการใช้งาน Drupal และเทคนิคต่างๆในการใช้งาน

javascript
(13)

บทความเกี่ยว Javascript แนะนำการใช้งานวิธีแก้ไขต่างๆ

JSON
(1)
php
(4)
SEO
(3)
Web Tools
(3)

แนะนำเครื่องมือสำหรับพัฒนาเวบไซต์

Who's online

There are currently 1 user and 3 guests online.

Online users

ขายหูฟัง Sennheiser CX500, Sennheiser CX300 , Sennheiser MM50, Monster Beats , Bose in ear
รับ Preorder หูฟังจากต่างประเทศ

หน้าแรก Shop
(41)

หน้าแรกของ Shop