All about unix linux freebsd and FAQ for Packetlove.com Web hosting , Mail hosting , VoIP + IP PBX server > command , shell script ,tool , crontab
basic command for xargs by golfreeze
golfreeze:
=== grep only name of /etc/password and show in 1 line
cut -d: -f1 < /etc/passwd | sort | xargs
golfreeze:
=== echo all name in "/home" and show as /home/test/{}
cd /home/
ls | xargs -I {} echo "/home/test/{}"
golfreeze:
==show verbose "-t" and -n "max-args, --max-args=max-args per command line" and show echo filename
ls | cut -d. -f1 | xargs -t -n 1
golfreeze:
==มีโจทย์ว่าต้องการเปลี่ยน chown ของ folder โดยเพิ่มชื่อโดเมนเข้าไปด้วย แล้วให้เปลี่ยนทุกไฟล์ใน folder นั้นๆ
ls -lah | awk '{print $10}' | grep vditest01 | xargs -I {} chown -R {}@dpa.or.th:domain\ users@dpa.or.th {}
golfreeze:
=== ถ้าเรา grep output ชื่อสักอย่าง ได้ออกมาเป็น column ที่9 แล้วจะทำให้ ข้อมูลที่เรียงเป็น column นั้นออกมาเป็นแถวเดียวต่อกัน และเว้นช่องว่างด้วย ,_ สามารถทำได้ดังนี้คือ
ls -lah | awk '{print $9}' | grep [a-z] | xargs -t | sed 's/ /, /g'
:-[
นำร่อง
[0] ดัชนีข้อความ
[*] หน้าที่แล้ว
Go to full version