Showing posts with label shell. Show all posts
Showing posts with label shell. Show all posts

Sunday, July 12, 2020

How to loop through each line in a file with BASH

cat some-list | while read line
do
  echo $line
done > result

Tuesday, March 12, 2019

How To Record Terminal And Replay It

$ script -t 2>~/upgrade-stretchstep.time -a ~/upgrade-stretchstep.script
$ exit
$ scriptreplay ~/upgrade-stretch.time ~/upgrade-stretch.script

References:

Thursday, November 29, 2018

Friday, October 19, 2012

unix command "find" search string under svn working copy

% find . \( ! -regex '.*\.svn.*' \) -exec grep -n "รายการ PaySure" {} \; -print| less

Monday, July 16, 2012

mosh - mobile shell with roaming and intelligent local echo

mosh  (mobile  shell)  is  a remote terminal application that supports intermittent
       connectivity, allows roaming, and provides speculative local echo and line  editing
       of user keystrokes.

       Compared  with ssh, mosh is more robust — its connections stay up across sleeps and
       changes in the client's IP address — and more responsive, because the  protocol  is
       tolerant  of packet loss and the client can echo most keystrokes immediately, with‐
       out waiting for a network round-trip.

how to use grep to filter directories with large data

$ du -sh | grep -e "^[0-9.]*\(G\|M\)"

Saturday, April 30, 2011

ชื่อไฟล์ที่ขึ้นต้นด้วย ขีด (-) มีปัญหากับ shell ใน unix / linux

ในหลายเพลา เรามักจะพบว่า ไฟล์ที่เราได้รับมาจากผู้อื่นนั้นมีการใช้ dash (ขีด, -) นำหน้าชื่อไฟล์ เช่น:

-abc.torrent

    การที่ชื่อไฟล์ขึ้นต้นด้วย - นั้นจะสร้างปัญหาให้กับ shell ที่เราใช้อยู่ สืบเนื่องจาก shell จะไปเข้าใจว่า "-" ขีดเส้นนั้นเป็น command line option (ซึ่งมักขึ้นต้นด้วย ขีด นั่นเอง)

    วิธีแก้ปัญหานี้คือ ให้ใส่ ขีดสองตัวติดกัน (--) ต่อท้ายคำสั่งที่เราเรียกใช้นั่นเอง แล้วหลังจากนั้นจึงเป็นชื่อไฟล์ที่เป็นปัญหา ตัวอย่างเช่น:

    $ mv -- -abc.torrent abc.torrent

    จึงขอประกาศให้ทราบโดยทั่วกัน

    อ้างอิง: