Advance Innovation Centre
  • AIC Knowledge @ EEC for All
  • 😎Logical Thinking
    • Karel Robot
    • Code to Flowchart
    • Play with Docker
    • CNX Software
  • MCU & Interfacing with Infineon PSOC™
    • Basic MCU Interfacing
      • Introduction to CY8CKIT-062S2-43012 Pioneer Kit
      • Development Environment Preparation
      • PSoC™ 6S2 Peripherals Interfacing (GPIO)
        • Hello World and LED Blinking
        • GPIO Principles
        • PSoC™ 6S2 GPIO-HAL LED Blink Lab
        • PSoC™ 6S2 GPIO-PDL LED Blink Lab
        • Button "Bounce" Principles
          • Push/Pull Button to Turn ON/OFF LED via HAL
          • Push/Pull Button to Turn ON/OFF LED via PDL
          • GPIO Button Interrupt via HAL
          • GPIO Button Interrupt via PDL
        • GPIO variables & functions
      • PSoC™ 6S2 Peripherals Interfacing (ADC, PWM)
        • PSoC™ 6S2 SAR ADC
          • ADC Principles
          • PSoC™ 6S2 with ADC Labs
            • Reading potentiometer sensor value via an ADC HAL
            • Reading potentiometer sensor value via an ADC PDL
        • PSoC™ 6S2 PWM & TCPWM
          • PWM Principles
          • PSoC™ 6S2 for PMW Function Labs
            • LED Brightness using PWM via HAL
            • LED Brightness using PWM via PDL
    • Sensor Interfacing and HMI
      • OLED Display
        • OLED Display Principles
        • Calling BDH’s OLED functions
        • Display ADC via Potentiometer on OLED
      • BDH Shell
        • Shell Principles
        • LED Blinking and CAPSENSE via BDH Shell
        • Adding "History" command
        • Adding "Reboot" command
        • CAPSENSE Button and Slider
          • CAPSENSE Button and Slider with Capsense Tuner
          • CAPSENSE Button and Slider using FreeRTOS
    • Serial Communication & Visualization
      • UART, I2C, SPI Communication via Infineon PSoC™6
      • BMX160 Sensor Communication via Infineon PSoC™6
        • Reading ADC via HAL with Potentiometer and Displaying GUI on Serial Studio
        • Reading XENSIV-DPS-3XX Pressure Sensor and Displaying GUI on Serial Studio
        • Motion Sensors GUI Integration via Serial Studio
    • IoT Connectivity & Data Analytics via Node-Red
      • Node-Red Installation
      • Setting MQTTS to MQTT Broker
      • Sending PSoC6’s sensor to MQTT (node-red)
    • Edge AI on PSoC™
      • Machine Learning on PSoC™6 via Edge-Impulse
    • Infineon PSoC™ Troubleshooting
  • IoT Development with Infineon PSOC™ & BDH Platform
    • PSoC™ IoT Development Kit
      • Introduction to CY8CKIT-062S2-43012 Pioneer Kit
      • Development Environment Preparation
        • Hello World and LED Blinking
    • IoT Connectivity
      • Node-Red Installation
      • Controlling PSoC™ LED using MQTT
      • Setting MQTTS to MQTT Broker
      • Sending PSoC6’s sensor to MQTT (node-red)
    • BDH IoT Connectivity
    • WireLinX™ IoT PLC
    • BDH X-Brain Data Analytics
      • PSoC6 Data Collection to CSV log file
    • Data Visualization
      • สร้าง Dashboard ด้วย Looker Studio
  • 🖥️Operation Systems
    • Prerequisites
      • Guideline from Ubuntu
        • Ubuntu and VSCode on WSL2
      • ติดตั้ง WSL 2
      • Run Ubuntu on VirtualBox7
    • Zero to Linux Hero
      • Computer OS Architecture
      • Anatomy of Linux System
        • UNIX/Linux History
        • UNIX/Linux Evolution
        • GNU Project
        • Linux OS Architecture
        • Command Line Interface (CLI)
          • Basic Commands
          • 😎Level up your Linux Shell
          • File & Dir. Commands
          • Searching Commands
          • 😎ChatGPT-based Terminal
          • SysAdmin Commands
          • Network Commands
          • Hacker Commands
        • Busybox
        • Shell Script
          • Awk Script
          • Bash Shell Script
            • Bash Snippets
            • Bash Useful Examples
      • Anatomy of Linux Kernel
        • Linux Kernel Principles
        • Linux Environment for Developer
      • Anatomy of Embedded Linux
        • Embedded Linux
        • Host & Target
        • Cross Toolchains
        • Bootloader
        • Building Embedded Linux
    • Linux OS Dev. Engineer
      • Process Management
        • Process Basic
        • Process State
        • Basic Process Mgmt. Commands
        • Advance Process Mgmt. Commands
        • Process API Programming
      • IPC
        • IPC Anatomy
        • Signal Programming
        • Pipe Programming
        • FIFO Programming
        • Msg. Queue Programming
          • System V
        • Share Memory Programming
          • System V
        • Socket Programming
      • POSIX Threads
        • Multi-tasking Basic
        • POSIX Thread Anatomy
        • Threading Programming
      • Applied IPC
        • Remote Commander
        • Multi-Remote Commanders
      • Process Synchronization
        • Mutex Programming
        • Semaphore Programming
      • Applied IPC with Semaphore
  • ⌚Embedded Systems Development
    • Introduction to ESD
      • Why's ESD?
      • What it use for?
      • How it works?
    • Enbedded System Development via PSoC6
      • Basic MCU Interfacing
        • Introduction to CY8CKIT-062S2-43012 Pioneer Kit
        • Development Environment Preparation
        • PSoC™ 6S2 Peripherals Interfacing (GPIO)
          • Hello World and LED Blinking
          • GPIO Principles
          • PSoC™ 6S2 GPIO-HAL LED Blink Lab
          • PSoC™ 6S2 GPIO-PDL LED Blink Lab
          • Button "Bounce" Principles
            • Push/Pull Button to Turn ON/OFF LED via HAL
            • Push/Pull Button to Turn ON/OFF LED via PDL
            • GPIO Button Interrupt via HAL
            • GPIO Button Interrupt via PDL
          • GPIO variables & functions
        • PSoC™ 6S2 Peripherals Interfacing (ADC, PWM)
          • PSoC™ 6S2 SAR ADC
            • ADC Principles
            • PSoC™ 6S2 with ADC Labs
              • Reading potentiometer sensor value via an ADC HAL
              • Reading potentiometer sensor value via an ADC PDL
          • PSoC™ 6S2 PWM & TCPWM
            • PWM Principles
            • PSoC™ 6S2 for PMW Function Labs
              • LED Brightness using PWM via HAL
              • LED Brightness using PWM via PDL
      • Sensor Interfacing and HMI
        • OLED Display
          • OLED Display Principles
          • Calling BDH’s OLED functions
          • Display ADC via Potentiometer on OLED
        • BDH Shell
          • Shell Principles
          • LED Blinking and CAPSENSE via BDH Shell
          • Adding "History" command
          • Adding "Reboot" command
          • CAPSENSE Button and Slider
            • CAPSENSE Button and Slider with Capsense Tuner
            • CAPSENSE Button and Slider using FreeRTOS
      • Serial Communication & Visualization
        • UART, I2C, SPI Communication via Infineon PSoC™6
        • BMX160 Sensor Communication via Infineon PSoC™6
          • Reading ADC via HAL with Potentiometer and Displaying GUI on Serial Studio
          • Reading XENSIV-DPS-3XX Pressure Sensor and Displaying GUI on Serial Studio
          • Motion Sensors GUI Integration via Serial Studio
    • Edge Computing and IoT Connectivity
    • Cloud-Based Data Analytics and Digital Twin
    • Edge Vision AI
    • Resources
      • Basic Hardware and Firmware
        • Environment Preparation
          • การติดตั้งโปรแกรม Arduino IDE
            • ตัวอย่างการเริ่มต้นใช้งาน Arduino IDE
          • การติดตั้งโปรแกรมสำหรับใช้งานเครื่องมือวัด NI MyDAQ
            • ตัวอย่างการตั้งค่าใช้ Digital Multimeter -NI ELVISmx
            • ตัวอย่างการตั้งค่าใช้ Oscilloscope-NI ELVISmx
          • ติดตั้งโปรแกรม KingstVIS
        • Basic measurement
          • Basic Digital and Analog I/O
            • LAB: Basic Digital Input/Output
            • LAB: Basic Analog Input/Output
          • Waveform
            • LAB: Oscilloscope
            • LAB: Oscilloscope and Function Generator
            • LAB: Pulse Width Modulation (PWM)
              • Homework
        • Interfacing and Communication
          • LAB: UART, RS485, RS232 Protocol
          • LAB: I2C Protocol
            • HOMEWORK
          • LAB: SPI Protocol
      • IoT Connectivity
        • Example: IoT with MQTT on Node-red
        • Data logger
        • LAB: Data Visualization
  • 🛠️C/C++ for Embedded Programming
    • Development Environment Preparation
      • ติดตั้ง WSL 2
      • ติดตั้ง Ubuntu environment
      • ติดตั้งโปรแกรม Visual Studio Code
      • การเชื่อมต่อ Virtual studio code เข้ากับ WSL
      • ติดตั้ง docker on WSL
    • Principle C/C++ Programming
      • Get started with C++
      • Makefile
        • Makefile Examples
      • Compiling and running
        • How to create a program that you can enter inputs.
          • Lab 1 Exercise
      • Arguments
        • Command line arguments in C and C++
      • signed and unsigned data types
      • Variable and Operator
      • If and If else
      • Loop, Infinite loop, and flag
        • Loop and Flag exercise
      • Array
        • Get to know with arrays
        • Implement example
      • Vector
    • Object Oriented Programming (OOP) in C++
      • Class and Object
      • Encapsulation and Abstraction
      • Polymorphism and Inheritance
    • C/C++ Preprocessing
      • Macro
        • Quiz Macro
      • File Inclusion
      • Conditional Compilation
      • Pragma directive
        • Quiz Pragma
    • String in C++
      • Concatenation
      • Split
    • Type conversions for C/C++
      • Conversion using Cast operator
    • Error handling
    • Data logger
      • การสร้างไฟล์และเขียนไฟล์
      • การอ่านไฟล์
      • การเก็บข้อมูลกับTime stamp
    • High performance programing
      • Multi-task and Multi-thread
        • Multi-threading example
      • Mutex
      • Queue
      • OpenCV
    • C/C++ Techniques
      • Makefile in action
      • Object Oriented Programming (OOP) in C++
        • Class and Object
        • Encapsulation and Abstraction
        • Polymorphism and Inheritance
      • C/C++ Preprocessing
        • Macro
          • Quiz Macro
        • File Inclusion
        • Conditional Compilation
        • Pragma directive
          • Quiz Pragma
      • Binary, Octal and Hexadecimal Numbers
      • Array and properties of an array
        • Get to know with arrays
        • Implement example
      • What's next?
  • 🤖Artificial Intelligence (AI)
    • VAMStack Design House, BUU
    • Data Analytics
      • Data cleansing
      • Data analytics
      • Data analytic exercise
    • Machine Learning
      • Neural Network Layers
      • Machine learning type
      • Dataset
      • Using Edge Impulse for AI Model
    • Basic Image Processing
      • Computer Vision using Python Language
        • Installation
        • Computer Vision Basics
          • Pixel and Color
          • Draw image
          • Basic Image processing
          • Morphology Transformations
          • Gaussian blur
          • Simple Thresholding
          • Contour
          • Canny edge detection
        • Case Study
          • Coin counting
          • Color detection & tracking
        • VAM_CV SDK
  • ⚙️FPGA Design and Development
    • Verilog HDL via Vivado IDE
      • LAB1: Setting Environment and Create Project
        • Create Vivado Project
      • LAB2: Hardware Description Language Work Flow
        • Simulation code
      • LAB3: Design HDL Project
        • Top Level Design
        • Top-level Simulation
      • LAB4: Asynchronous VS Synchronous Circuit
        • Simulation Synchronous counter
    • C/C++ Programming on Ultra96v2 FPGA Board
      • Application C/C++ on Ultra96v2 Part 1
        • Design Overview
        • Step 1 - Burn the image to SD card
        • Step 2 - Bring up Ultra96v2
        • Step 3 - Installing the Vitis-AI runtime packages
      • Application C/C++ on Ultra96v2 Part 2
        • STEP 1 : Setting auto boot Wifi
        • STEP 2 : How to working on Embedded
        • STEP 3 : How to run the test code
  • 🤖Robotics
    • Dobot Magician
      • Instruction of Dobot
      • Software Download
      • Basically of Program
        • Teaching and Playback
        • Write and Draw
        • LaserEngraving
        • 3D Printer
    • Robotino
      • Software Download
        • Robotino View
        • Robotino SIM
      • Charging
      • Connecting
      • Follow Line example
        • Basic block in Follow Line
    • RaspBlock
      • Get Started with Raspblock
  • 🚩Special Topics
    • Node-Red
      • Set up Raspberry Pi
      • Install node red in Raspberry Pi
      • Get started with Node Red
        • Open node-red
        • Turn off node red
        • Install Dashboard on Node-red
        • Use node red to show message
        • Using Ultrasonic sensor with node-red
    • IoT Cloud
      • Overview
        • How do they work?
          • Basic Knowlege
      • Installations
        • Install Docker
        • Install Mosquitto Broker
        • Install InfluxDB
        • Install Telegraf
        • Install Grafana
      • Get Sensor Value and Send to MQTT
        • Connect ESP3266 to sensor
        • Connect ESP3266 to MQTT
      • Integration
    • Senses IoT
      • SENSES IoT Platform
      • LAB8: MCU send data to IoT platform
    • CrowPi Dev Kit
      • Raspberry Pi with CrowPi
      • Remote to Raspberry Pi
      • Cross-Compile
        • Lab 1: Programming and cross complier
      • Hardware and Interfaces Usage CLI
        • LAB: Usage GPIO via CLI
        • LAB: Scan I2C bus via CLI
      • Python library for Crow Pi
      • wiringPi library (C) for CrowPi
        • Lab2: Crowpi and sensors
    • LVGL Development
      • LVGL - Light and Versatile Embedded Graphics Library
        • Setting program for LVGL Simulator
        • Get started with LVGL simulator
        • Example Library of LVGL
        • Create your own screen
          • Exercise
        • Style
          • Exercise
        • Event
    • Docker OS
      • Docker OS Part 1
        • Part 1 : Installation
        • Part 2 : Basic Docker OS and Linux CLI
      • Docker OS Part 2
        • Part 1 : Docker communication
        • Part 2 : Docker compose
      • Application Gstreamer on devcontainer
        • STEP 1 : Setting gstreamer environment
        • STEP 2 : Create the Gstreamer element on template
        • STEP 3 : Testing and application on your gst element
  • 🤟Recommended by AIC
    • Skill Roadmap
      • Embedded Engineer
      • Developer
    • Hardware Programming
    • Embedded Programming
    • General-propose Programming
    • Algorithmica
    • Thai Expert Knowledge
    • RT-Thread University Program
      • Infineon PSoC6
      • Kernel
        • Kernel Basics
        • Thread Management
        • Clock Management
        • Inter-thread synchronization
        • Inter-thread communication
        • Memory Management
        • Interrupt Management
        • Kernel porting
        • Atomic Operations
        • RT-Thread SMP
        • Kernel API Changelog
      • Tools
      • Devices & Drivers
        • SENSOR Devices
        • Touch Equipment
        • CRYPTO Devices
        • AUDIO Devices
        • Pulse Encoder Devices
      • Components
        • C Library (libc)
        • ISO/ANSI C Standard
        • POSIX Standard
          • FILE (File IO)
          • Pthread
          • Timer
          • IPC Semaphore
          • IPC Message Queues
          • Dynamic Modules
        • Network Components
          • FinSH Console
          • FAL: Flash Abstraction Layer
          • Virtual File System
          • tmpfs: temporary file system
          • ulog log
          • utest testing framework
          • Power Management
          • RT-Link
        • Software Packages
          • Internet of Things
            • MQTT-umqtt
            • Telnet
          • Tools
            • SystemView
            • SEGGER_RTT
          • LVGL Manual
            • Touch Screen Driver
      • Demo
        • Infineon Gateway
        • Handwriting Recognition (MNIST)
        • Object Detection (Darknet)
        • ROS using RT-Thread
        • Control the car using RT-Thread
        • LiDAR via RT-Thread
        • Detection via RT-Thread and ROS
        • Sensor Driver Development Guide
Powered by GitBook

Assoc. Prof. Wiroon Sriborrirux, Founder of Advance Innovation Center (AIC) and Bangsaen Design House (BDH), Electrical Engineering Department, Faculty of Engineering, Burapha University

On this page
  • ls, cp, mv และ rm
  • cat, tac, less, od, และ split
  • wc, head, and tail
  • Expand, unexpand and tr
  • Sort and uniq
  • Cut, paste, and join

Was this helpful?

  1. Operation Systems
  2. Zero to Linux Hero
  3. Anatomy of Linux System
  4. Command Line Interface (CLI)

File & Dir. Commands

คำสั่งเกี่ยวกับการจัดการไฟล์และไดเรกทอรี (File and Directory Managements)

PreviousLevel up your Linux ShellNextSearching Commands

Last updated 1 year ago

Was this helpful?

ภายในระบบปฏิบัติการลีนุกซ์เกือบทุกสิ่งทุกอย่างที่อยู่ภายในระบบคือไฟล์ทั้งสิ้น (Everything is File) ได้แก่

  • ไฟล์ปกติทั่วไป (Regular files) เช่นไฟล์เอกสาร ไฟล์มัลติมีเดีย ไฟล์โปรแกรม

  • ไดเรกทอรี (Directories) ไฟล์ที่บรรจุรายการของไฟล์ต่างๆ

  • ไฟล์เชื่อมสัญลักษณ์ (Symbolic links) ไฟล์ที่อ้างอิงไปยังไฟล์อื่น

  • ไฟล์ท่อซ็อกเก็ต (Socket) ไฟล์ที่เป็นเป็นท่อเชื่อมต่อการสื่อสารข้อมูลระหว่างโปรเซส ที่อยู่ในเครื่องเดียวกัน หรือต่างเครื่องผ่านระบบเครือข่ายได้

  • ไฟล์ท่อส่งข้อมูล (Name Pipe) ไฟล์ที่ใช้เป็นท่อเชื่อมระหว่างโปรแกรม เพื่อส่งค่าผลลัพธ์ (output) ของโปรแกรมหนึ่ง ให้เป็นค่านำเข้า (input) ของอีกโปรแกรมหนึ่ง

  • ไฟล์อุปกรณ์ (Devices and Peripherals) ไฟล์ที่เชื่อมต่อกับอุปกรณ์ฮาร์ดแวร์ของระบบ

    • character device ไฟล์ที่เชื่อมต่อกับอุปกรณ์ฮาร์ดแวร์ที่สื่อสารแบบอนุกรม (ตัวอักษร)

    • block device ไฟล์ที่เชื่อมต่อกับอุปกรณ์ฮาร์ดแวร์ที่สื่อสารข้อมูลขนาดใหญ่

การกำหนดชื่อไฟล์จึงมีความยืดหยุ่นสูง ซึ่งได้แก่ การตั้งชื่อไฟล์ตัวเล็ก/ตัวใหญ่จะถือว่าเป็นคนละไฟล์กัน ความยาวชื่อไฟล์ไม่มีจำกัด สามารถให้อักขระพิเศษมาใช้ในการตั้งชื่อไฟล์ได้ (ยกเว้นอักขระ /) ไม่จำเป็นต้องมีการระบุสกุลไฟล์ เป็นต้น

ls, cp, mv และ rm

เพื่อให้เกิดความเข้าใจในการใช้งานคำสั่งที่เกี่ยวกับไดเรกทอรีเริ่มต้นชุดคำสั่งกลุ่มนี้จึงถือได้ว่าเป็นชุดคำสั่งพื้นฐานที่ใช้บ่อยครั้ง ไม่ว่าจะเป็นผู้เริ่มต้น หรือผู้ที่เชี่ยวชาญแล้ว เนื่องจากการใช้งานหลักของระบบปฏิบัติการลีนุกซ์นั้นจะเน้นพิมพ์คำสั่งอยู่บนหน้าต่างเทอร์มินัล

ภายในระบบไฟล์ จะเก็บข้อมูลไฟล์หรือไดเรกทอรี ซึ่งจะถูกเก็บในลักษณะของบล็อค (block) และข้อมูลของแต่ละไฟล์จะถูกเก็บใน ไอโหนด (inode) โดยจะมีรายละเอียดเช่น เจ้าของไฟล์ วันที่ใช้งานล่าสุด ขนาดไฟล์ และสิทธิ์การใช้งานต่างๆ โดยใช้้คำสั่ง ls –al นอกจากนั้นถ้าเราอยากได้ข้อมูลที่เกี่ยวกับไดเรกทอรีเท่านั้น ก็สามารถใช้ -ld ได้เมื่อต้องการที่จะคัดลอกไฟล์ เปลี่ยนชื่อไฟล์ ย้ายไฟล์ หรือลบไฟล์ เราจะต้องใช้คำสั่งต่อไปนี้

cp

เป็นคำสั่งที่ใช้ในการคัดลอกไฟล์ (ทั้งไฟล์เดียวและหลายไฟล์) โดยระบุ source และ target

mv

เป็นคำสั่งที่ใช้ในการโยกย้ายไฟล์หรือเปลี่ยนชื่อไฟล์ โดยการใช้งานจะคล้ายกับคำสั่ง cp แต่ค่า inode ของไฟล์ที่ย้ายหรือเปลี่ยนชื่อจะไม่ถูกเปลี่ยน ยกเว้นมีการย้ายของในระดับ filesystem ใหม่

rm

เป็นคำสั่งที่ใช้ในการลบไฟล์ โดยสามารถใช้ได้ทั้งไฟล์เดียวหรือหลายไฟล์

แสดงประเภทไฟล์ต่างๆ

แสดงเฉพาะไฟล์ชนิดทั่วไป (regular file)

$ ls -al | grep ^-                                                                                               ─╯
-rwxr-xr-x  1 wiroon wiroon      1473 ก.ค.   9 16:23 apt.sh
-rw-------  1 wiroon wiroon      1206 เม.ย.  7 20:09 .bash_history
-rw-r--r--  1 wiroon wiroon       220 เม.ย.  7 18:37 .bash_logout
-rw-r--r--  1 wiroon wiroon      3771 เม.ย.  7 18:37 .bashrc
-rw-------  1 wiroon wiroon        20 ก.ค.   9 21:17 .lesshst
-rw-r--r--  1 root   root   208277277 ส.ค.  11  2022 linux-5.19.1.tar.gz
-rw-rw-r--  1 wiroon wiroon       210 มิ.ย.   6 22:43 minicom.log
-rw-rw-r--  1 wiroon wiroon     87470 เม.ย.  7 20:26 .p10k.zsh
-rw-r--r--  1 wiroon wiroon       807 เม.ย.  7 18:37 .profile

แสดงเฉพาะไฟล์ชนิดไดเรกทอรี

$ ls -al | grep ^d                                                                                               ─╯
drwxr-x--- 28 wiroon wiroon      4096 ก.ค.  11 16:21 .
drwxr-xr-x  3 root   root        4096 เม.ย.  7 18:37 ..
drwx------ 17 wiroon wiroon      4096 ก.ค.  10 23:06 .cache
drwx------ 21 wiroon wiroon      4096 ก.ค.   9 22:07 .config
drwxr-xr-x  2 wiroon wiroon      4096 เม.ย.  7 19:02 Desktop
drwxr-xr-x  2 wiroon wiroon      4096 เม.ย.  7 18:57 Documents
drwxrwxr-x  3 wiroon wiroon      4096 มิ.ย.   6 17:54 .dotnet
drwxr-xr-x  2 wiroon wiroon      4096 ก.ค.   3 21:58 Downloads
drwx------  3 wiroon wiroon      4096 ก.ค.   5 10:47 .emacs.d
drwxrwxr-x  5 wiroon wiroon      4096 เม.ย.  7 20:08 gnome-terminal
drwx------  2 wiroon wiroon      4096 ก.ค.   9 22:51 .gnupg
drwxrwxr-x 11 wiroon wiroon      4096 มิ.ย.   5 20:45 gstreamer
drwxrwxr-x 24 wiroon wiroon      4096 ก.ค.   9 23:26 linux-5.19.1
drwx------  3 wiroon wiroon      4096 เม.ย.  7 18:57 .local

แสดงเฉพาะไฟล์ชนิดเชื่อมสัญลักษณ์ (symbolic link file)

$ ls -al /dev/ | grep ^l                                                                                         ─╯
lrwxrwxrwx   1 root   root           3 ก.ค.   9 16:08 cdrom -> sr0
lrwxrwxrwx   1 root   root          11 ก.ค.   9 16:08 core -> /proc/kcore
lrwxrwxrwx   1 root   root          13 ก.ค.   9 16:08 fd -> /proc/self/fd
lrwxrwxrwx   1 root   root          12 ก.ค.   9 16:08 initctl -> /run/initctl
lrwxrwxrwx   1 root   root          28 ก.ค.   9 16:08 log -> /run/systemd/journal/dev-log
lrwxrwxrwx   1 root   root           4 ก.ค.   9 16:08 rtc -> rtc0
lrwxrwxrwx   1 root   root          15 ก.ค.   9 16:08 stderr -> /proc/self/fd/2
lrwxrwxrwx   1 root   root          15 ก.ค.   9 16:08 stdin -> /proc/self/fd/0
lrwxrwxrwx   1 root   root          15 ก.ค.   9 16:08 stdout -> /proc/self/fd/1

แสดงเฉพาะไฟล์ชนิดเชื่อมต่อกับอุปกรณ์ฮาร์ดแวร์ (character and block device file)

$ ls -al /dev/ | grep ^c                                                                                         ─╯
crw-rw----+  1 root   video   511,   0 ก.ค.  10 22:58 media0
crw-rw----+  1 root   video   511,   1 ก.ค.  11 15:02 media1
crw-r-----   1 root   kmem      1,   1 ก.ค.   9 16:08 mem
crw-rw-rw-   1 root   root      1,   3 ก.ค.   9 16:08 null
crw-r-----   1 root   kmem      1,   4 ก.ค.   9 16:08 port
crw-------   1 root   root    108,   0 ก.ค.   9 16:08 ppp
crw-------   1 root   root     10,   1 ก.ค.   9 16:08 psaux
crw-rw-rw-   1 root   tty       5,   2 ก.ค.  11 16:22 ptmx
crw-rw-rw-   1 root   root      1,   8 ก.ค.   9 16:08 random
crw-rw-r--+  1 root   root     10, 242 ก.ค.   9 16:08 rfkill
crw-------   1 root   root    247,   0 ก.ค.   9 16:08 rtc0
crw-rw----   1 root   disk     21,   0 ก.ค.   9 16:08 sg0
crw-rw----+  1 root   cdrom    21,   1 ก.ค.   9 16:08 sg1
crw-rw-rw-   1 root   tty       5,   0 ก.ค.  10 23:07 tty
crw--w----   1 root   tty       4,   0 ก.ค.   9 16:08 tty0
crw--w----   1 root   tty       4,   1 ก.ค.   9 16:08 tty1
crw-rw----+  1 root   video    81,   0 ก.ค.  10 22:58 video0
crw-rw----+  1 root   video    81,   1 ก.ค.  10 22:58 video1
crw-rw----+  1 root   video    81,   2 ก.ค.  11 15:02 video2
crw-rw----+  1 root   video    81,   3 ก.ค.  11 15:02 video3
crw-rw-rw-   1 root   root      1,   5 ก.ค.   9 16:08 zero
crw-------   1 root   root     10, 249 ก.ค.   9 21:06 zfs

$ ls -al /dev/ | grep ^b                                                                                         ─╯
brw-rw----   1 root   disk      7,   0 ก.ค.   9 16:08 loop0
brw-rw----   1 root   disk      7,   1 ก.ค.   9 16:13 loop1
brw-rw----   1 root   disk      7,  10 ก.ค.   9 16:08 loop10
brw-rw----   1 root   disk      7,  11 ก.ค.   9 16:08 loop11
brw-rw----   1 root   disk      7,  12 ก.ค.   9 16:08 loop12
brw-rw----   1 root   disk      7,  13 ก.ค.   9 16:08 loop13
brw-rw----   1 root   disk      7,  14 ก.ค.   9 16:08 loop14
brw-rw----   1 root   disk      7,  15 ก.ค.   9 16:08 loop15
brw-rw----   1 root   disk      7,  16 ก.ค.   9 16:08 loop16
brw-rw----   1 root   disk      7,  17 ก.ค.   9 16:08 loop17
brw-rw----   1 root   disk      7,  18 ก.ค.   9 16:08 loop18
brw-rw----   1 root   disk      7,  19 ก.ค.   9 21:06 loop19
brw-rw----   1 root   disk      7,   2 ก.ค.   9 16:08 loop2
brw-rw----   1 root   disk      7,  20 ก.ค.  11 16:08 loop20
brw-rw----   1 root   disk      7,   3 ก.ค.   9 16:13 loop3
brw-rw----   1 root   disk      7,   4 ก.ค.   9 16:08 loop4
brw-rw----   1 root   disk      7,   5 ก.ค.   9 16:08 loop5
brw-rw----   1 root   disk      7,   6 ก.ค.   9 16:08 loop6
brw-rw----   1 root   disk      7,   7 ก.ค.   9 16:08 loop7
brw-rw----   1 root   disk      7,   8 ก.ค.  11 16:08 loop8
brw-rw----   1 root   disk      7,   9 ก.ค.   9 16:13 loop9
brw-rw----   1 root   disk      8,   0 ก.ค.   9 16:08 sda
brw-rw----   1 root   disk      8,   1 ก.ค.   9 16:08 sda1
brw-rw----   1 root   disk      8,   2 ก.ค.   9 16:08 sda2
brw-rw----+  1 root   cdrom    11,   0 ก.ค.   9 16:08 sr0

แสดงไฟล์ชนิดไฟล์ไปบ์ (Name pipe file)

$ ls -al  | grep ^p                                                                                              ─╯
prw-rw-r--  1 wiroon wiroon         0 ก.ค.  11 16:29 pipe1
prw-rw-r--  1 wiroon wiroon         0 ก.ค.  11 16:29 pipe2

Recursive listing

เราสามารถใช้คำสั่ง ls –R ในการดูรายการไฟล์และไดเรกทอรีรวมถึงไดเรกทอรีย่อยที่อยู่ภายในได้ แต่การใช้คำสั่งนี้จะไม่แสดงรายการของไฟล์ที่อยู่ในไดเรกทอรีย่อย

$ ls -R /opt
X11 intel local sumo


/opt/X11:
bin etc include lib share var
/opt/X11/bin:
X fc-list libpng-config twm xdmshell xkbprint xrandr
Xephyr fc-match libpng15-config ucs2any xdpr xkbvleds xrdb
Xfake fc-pattern listres uxterm xdpyinfo xkbwatch xrefresh
Xnest fc-query lndir viewres xedit xkeystone xscope
Xorg fc-scan luit x11perf xev xkill xset
Xquartz fc-validate makedepend x11perfcomp xeyes xload xsetmode
Xvfb font_cache mkfontdir xauth xfd xlogo xsetpointer
appres fonttosfnt mkfontscale xbacklight xfontsel xlsatoms xsetroot
atobm freetype-config oclock xcalc xfs xlsclients xsm
bdftopcf fslsfonts quartz-wm xclipboard xfsinfo xlsfonts xstdcmap
bdftruncate fstobdf resize xclock xgamma xmag xterm
bitmap gccmakedep sessreg xcmsdb xgc xman xvinfo
bmtoa glxgears setxkbmap xcompmgr xhost xmessage xwd
cvt glxinfo showfont xconsole xinit xmh xwininfo
cxpm gtf showrgb xcursorgen xinput xmodmap xwud
editres iceauth smproxy xcutsel xkbbell xmore
fc-cache ico startx xditview xkbcomp xpr
fc-cat koi8rxterm sxpm xdm xkbevd xprop


/opt/X11/etc:
X11


/opt/X11/etc/X11:
dummy.conf xsm


/opt/X11/etc/X11/xsm:
system.xsm


....

Recursive copy

ในการคัดลอกไดเรกทอรีย่อยที่อยู่ภายในไดเรกทอรีหลักที่ต้องการนั้นเราต้องใช้ option –R หรือ -rp (หรือ --recursive) ต่อท้ายคำสั่ง cp

$ cp -R os/ os_backup
หรือ
$ cp -rp os/ os_backup

Recursive deletion

คำสั่ง rmdir นั้นสามารถลบได้เฉพาะไดเรกทอรีว่างเท่านั้น เราจึงต้องนำ option –R หรือ -rf (หรือ --recursive) ของคำสั่ง rm ซึ่งหลังจากใช้คำสั่งแล้วไดเรกทอรีไฟล์ และไดเรกทอรีย่อยจะถูกลบไปทั้งหมด

$ rmdir -R os/
หรือ
$ rm -rf os/

Wildcards and globbing

ในบางครั้งเราต้องการแก้ไขข้อมูลไฟล์หลายๆไฟล์พร้อมกัน แต่ไม่ต้องการแก้ทุกไฟล์ในไดเรกทอรีเราสามารถแก้ปัญหานี้ได้โดยใช้ globbing ซึ่งอาศัยตัวอักขระพิเศษในการทำงาน เช่น '?', '*' และ '[',

ตารางตัวดำเนินการ

อักขระพิเศษ
รายละเอียด

?

เปรียบเทียบตัวอักษร

*

เปรียบเทียบข้อความ

[ .. ]

เปรียบเทียบตัวอักษรภายใน [ ]

cat, tac, less, od, และ split

คำสั่ง cat (catenate) คือคำสั่งที่ใช้แสดงข้อมูลที่อยู่ในไฟล์ออกมาแสดงครั้งเดียวพร้อมกันทั้งหมด ในบางครั้งก็ใช้ในการรวมไฟล์หลายไฟล์เข้าด้วยกันมาเป็นไฟล์เดียว ส่วนคำสั่ง tac คือคำสั่งที่ทำงานกลับกันจากผลลัพธ์ของคำสั่ง cat ถ้าไฟล์ที่ต้องการเปิดอ่านข้อมูลมีความยาวมาก ตัวอย่างเช่นไฟล์ที่เก็บ log ของระบบ ถ้าใช้คำสั่ง cat เพื่อเปิดไฟล์ log ย่อมไม่เป็นผลดีกับผู้อ่านเองเพราะจะแสดงข้อมูลออกมาอย่างรวดเร็วเกินกว่าจะจับใจความทันได้ ดังนั้นคำสั่ง less จึงเป็นคำสั่งยอดนิยมอีกคำสั่งหนึ่งที่ผู้ดูแลระบบหรือนักพัฒนาจะนิยมนำมาใช้ เนื่องจากมันจะช่วยให้การแสดงข้อมูลของไฟล์ที่มีขนาดใหญ่ให้สามารถเลื่อนหน้าจอขึ้นลงได้หรือแม้กระทั่งค้นหาคำได้ลักษณะคล้ายกับการใช้ text editor ในการเลื่อนหน้าจอของคำสั่ง less นั้นสามารถใช้งานได้ทั้งลูกศรขึ้นลงหรือการใช้ปุ่ม PageUp PageDown ในการควบคุมสำหรับในการค้นหานั้นจะค้นหาได้โดยการพิมพ์เครื่องหมาย / แล้วตามด้วยข้อความที่ต้องการค้นหา คำสั่ง less จะทำหน้าที่แสดงคำที่ผู้ดูแลระบบต้องการค้นหาออกมา ถ้าหากในกรณีที่ต้องการค้นหาคำถัดไป คำสั่ง less ได้้ออกแบบให้มีการกดแป้นพิมพ์ n เพื่อเลื่อนไปยังคำถัดไป

นอกจากคำสั่ง less จะมีความสามารถในการค้นหาแล้วนั้นความสามารถของคำสั่ง less ยังสามารถแสดงข้อมูลที่มีการเปลี่ยนแปลงที่บรรทัดสุดท้ายได้ โดยการกดปุ่ม F เช่นกรณีของไฟล์ log ที่จะมีข้อมูลเข้ามาตลอดเวลา less สามารถแสดงข้อมูลเหล่านั้นได้ทันทีโดยไม่จำเป็นต้องเปิดไฟล์ใหม่ แม้ไฟล์ log จะถูกบีบอัดเป็น .gz ก็ยังสามารถเปิดได้ด้วยคำสั่ง less ได้ทันที ตัวอย่างการใช้คำสั่งดังแสดงข้างล่าง

$ cat Departments.txt   <---- เปิดไฟล์ที่มีอยู่แล้ว
1 Electrical
2 Computer
3 Telecommunication    


$ tac Departments.txt  
3 Telecommunication    
2 Computer
1 Electrical


$ cat >Universities.txt      <---- เปิดไฟล์ใหม่ และป้อนข้อมูลลงไฟล์ทันที
Burapha University
Prince of Songkhla University
Thammasat University
กด Ctrl+D                    <---- กดปุ่ม Ctrl+D เพื่อสิ้นสุดการใส่ข้อมูล


$ cat Departments.txt Universities.txt > All.txt
$ cat All.txt 
1 Electrical
2 Computer
3 Telecommunication
Burapha University
Prince of Songkhla University
Thammasat University 


$ less /var/log/syslog

จากคำสั่งข้างต้นจะเน้นการเปิดไฟล์ชนิดข้อความ (text file) ทั่วไป แล้วแสดงผลเป็นข้อความปกติ แต่ในบางกรณีที่นักพัฒนาระบบสมองกลฝังตัวต้องการมองข้อความภายในไฟล์ในลักษณะอื่น เช่น แปลงเป็นเลขฐานแปด ฐานสิบ หรือ ฐานสิบหก คำสั่งที่นิยมใช้กันทั่วไปคือ od (Octal Dump) ซึ่งมีตัวเลือก -A ที่ไว้สำหรับระบุรากที่ต้องการ (Radix) และ -t สำหรับระบุรูปแบบการแสดงว่าจะเป็นเลขฐานต่างๆ เช่น เลขฐานแปด เลขฐานสิบ เลขฐานสิบหก หรือ รหัสแอสกี้ ด้วย ค่า o, d, x, c ตามลำดับ ดังตัวอย่างข้างล่าง

$ od Departments.txt 
0000000 020061 066105 061545 071164 061551 066141 031012 041440
0000020 066557 072560 062564 005162 020063 062524 062554 067543
0000040 066555 067165 061551 072141 067551 005156
0000054
$ od -t x Departments.txt 
0000000 6c452031 72746365 6c616369 4320320a
0000020 75706d6f 0a726574 65542033 6f63656c
0000040 6e756d6d 74616369 0a6e6f69
0000054
$ od -A d -t c Departments.txt 
0000000   1       E   l   e   c   t   r   i   c   a   l  \n   2       C
0000016   o   m   p   u   t   e   r  \n   3       T   e   l   e   c   o
0000032   m   m   u   n   i   c   a   t   i   o   n  
0000044

ไฟล์ที่ใช้กันส่วนใหญ่อาจจะมีขนาดเล็กแต่เมื่อใดที่มีไฟล์ขนาดใหญ่นักพัฒนาจำเป็นที่จะต้องทำการแยกออก (split) มาให้เป็นไฟล์ชิ้นเล็กๆที่สะดวกต่อระบบสมองกลฝังตัวในการส่งไปทีละก้อน หรือแม้แต่ต้องการส่งผ่านอีเมล์ในขนาดที่พอเหมาะต่อขนาดความจุของช่องข้อมูล ดังนั้นคำสั่งที่สามารถแยกไฟล์ออกเป็นชิ้นได้คือ คำสั่ง split ซึ่งสามารถจะเลือกแยกเป็นไฟล์ชิ้นเล็กๆตามขนาดไบท์ (Byte) หรือ บรรทัด (line) ที่หั่นจากตัวไฟล์ต้นฉบับ เพื่อต้องการนำไฟล์ย่อยที่ถูกแบ่งออกมา กลับมารวมเป็นไฟล์เหมือนตันฉบับดังเดิม ก็เพียงแค่ใช้คำสั่ง cat เพื่อทำการรวมทั้งหมด ดังตัวอย่างคำสั่งข้างล่างนี้

$ split -l 1  Departments.txt   <---- แบ่งออกทีละบรรทัด
$ ls x*
xaa  xab  xac
$ cat xaa xab xac    <---- แสดงข้อมูลในไฟล์ทั้งสามพร้อมกัน
1 Electrical
2 Computer
3 Telecommunication


$ cat xaa xab xac > Departments_copies.txt <---- รวมไฟล์ทั้งหมดมาเป็นไฟล์เดียว
$ cat Departments_copies.txt 
1 Electrical
2 Computer
3 Telecommunication

สามารถใช้คำสั่ง md5sum ทำการตรวจสอบไฟล์ทั้งสองว่ามีขนาดและข้อมูลภายในเหมือนกันหรือไม่

$ md5sum Departments.txt    
c4eef8b561262f39d7ae748566100fe5  Departments.txt
$ md5sum Departments_copies.txt 
c4eef8b561262f39d7ae748566100fe5  Departments_copies.txt

wc, head, and tail

คำสั่ง wc (Word Count) จะเหมาะกับการตรวจสอบรายละเอียดของข้อมูลภายในไฟล์ว่ามีขนาดใหญ่เท่าไหร่ มีบรรทัดทั้งหมดจำนวนเท่าไหร่ จำนวนคำทั้งหมดเท่าไหร่ นอกจากนั้น 2 คำสั่งที่เหมาะสมในการดูไฟล์ที่มีขนาดใหญ่เช่นเดียวกัน แต่จะเน้นดูเพียงแค่ส่วนหัวไฟล์ด้วยคำสั่ง head และส่วนท้ายไฟล์ด้วยคำสั่ง tail ซึ่งสามารถใช้ตัวเลือก option -n <บรรทัด> เพื่อระบุจำนวนบรรทัดที่ต้องการแสดง ดังตัวอย่างคำสั่งข้างล่าง

$ wc -l /var/log/dmesg
1386 /var/log/dmesg


$ head -n 5 /var/log/dmesg
[    0.000000] Initializing cgroup subsys cpuset
[    0.000000] Initializing cgroup subsys cpu
[    0.000000] Linux version 2.6.32-42-server (buildd@batsu) (gcc version 4.4.3 (Ubuntu 4.4.3-4ubuntu5.1) ) #96-Ubuntu SMP Wed Aug 15 19:52:20 UTC 2012 (Ubuntu 2.6.32-42.96-server 2.6.32.59+drm33.24)
[    0.000000] Command line: BOOT_IMAGE=/boot/vmlinuz-2.6.32-42-server root=UUID=4fb97098-124c-489b-a0d1-3eb8846d2f67 ro quiet
[    0.000000] KERNEL supported cpus:


$ tail -n 5 /var/log/dmesg
[   18.896413] acpiphp_glue: Slot 262 already registered by another hotplug driver
[   18.896434] acpiphp_glue: Slot 263 already registered by another hotplug driver
[   19.031705] ENS1371 0000:02:02.0: PCI INT A -> GSI 16 (level, low) -> IRQ 16
[   19.602812] vmmemctl: started kernel thread pid=907
[   19.602826] VMware memory control driver initialized

ในกรณีที่ผู้ดูแลระบบ หรือนักพัฒนาสมองกลฝังตัว ต้องการเฝ้าดูการเปลี่ยนแปลงของไฟล์ว่ามีข้อมูลเข้ามาหรือไม่ ก็สามารถใช้ตัวเลือก -f สำหรับคำสั่ง tail เพื่อเฝ้าดูเหตุการณ์การเปลี่ยนแปลงได้ทันที ดังรูป

Expand, unexpand and tr

ตัวอย่างในการสร้างไฟล์ text2 จากการใช้แท๊ป (Tab) เพื่อเว้นวรรคข้อความ ซึ่งในบางครั้งเราอาจต้องการเปลี่ยนจากแท๊ป (tab) เป็นช่องว่าง (space) หรือเปลี่ยนจาก space เป็น tab โดยการใช้ชุดคำสั่ง expand และ unexpand มาใช้ตามลำดับ

$ cat mytext1.txt
1 Wiroon
2 Nayot
3 Panuwat


$ expend mytext1.txt > mytext2.txt  <---- เปลี่ยนจาก tab เป็น space ลงในไฟล์ใหม่ (mytext2.txt)
$ cat mytext2.txt
1 Wiroon
2 Nayot
3 Panuwat


$ expand --tabs=10 mytext1.txt > mytext3.txt <---- เปลี่ยนจาก tab เป็น 10 spaces ลงในไฟล์ใหม่
$ cat mytext3.txt
1         Wiroon
2         Nayot
3        Panuwat

ตัวอย่างข้างต้นเป็นตัวอย่างการเปลี่ยนแท๊ป (Tab) เป็น space จำนวน 10 spaces (--tab=10 หรือ -t10)

ถ้าต้องการเปลี่ยนจาก space เป็น tab ด้วยคำสั่ง unexpand จะต้องมี space อยู่ติดกันอย่างน้อย 2 ตัวขึ้นไปดังตัวอย่างข้างล่างนี้ แต่อย่างไรก็ตามถ้าต้องการเปลี่ยนที่มี space เพียงตัวเดียวจริงๆ ก็สามารถใช้คำสั่ง tr แทนได้ดังตัวอย่างข้างล่าง

$ cat mytext1.txt
1 Wiroon
2 Nayot
3 Panuwat


$ expand --tabs=2 mytext1.txt > mytext4.txt <---- เปลี่ยนจาก tab เป็น 2 spaces ลงในไฟล์ใหม่
$ cat mytext4.txt
1  Wiroon
2  Nayot
3  Panuwat


$ unexpand --tabs=2 mytext4.txt
1 Wiroon
2 Nayot
3 Panuwat


$ echo "Linux is incredible" | tr [:space:] '\t'
Linux is incredible

Sort and uniq

คำสั่ง sort เป็นคำสั่งที่ใช้ในการจัดเรียงข้อมูล โดยสามารถกำหนดการเรียงข้อมูลได้ว่าจะเรียงตามลำดับตัวเลขหรือลำดับตัวอักษร

$ cat courses.txt
34 Operating System
254 Data Structure
5 Crypo
21 C++
1435 C Language
589 Java 1.6
$ sort -k 1h courses.txt  <---- เรียงตัวเลข (numeric) ในคอลัมน์แรก
5 Crypo
21 C++
34 Operating System
254 Data Structure
589 Java 1.6
1435 C Language


$ sort -k 2 courses.txt  <---- เรียงตัวอักษรในคอลัมน์ที่สอง
1435 C Language
21 C++
5 Crypo
254 Data Structure
589 Java 1.6
34 Operating System

สำหรับคำสั่ง uniq นั้น จะมีตัวอย่างการใช้งานดังแสดงข้างล่างนี้

$ cat cars.txt
1975 Ford
1985 Toyota
1988 Ford
1989 Honda
1990 BMW
1993 BMW
1993 Benz
1995 Mazda
1995 Toyota
1998 Ford


$ cat cars.txt | tr ' ' '\t' | sort -u -k2r
1985 Toyota
1995 Mazda
1989 Honda
1975 Ford
1993 Benz
1990 BMW


$ unexpand --tabs=2 mytext4.txt
1 Wiroon
2 Nayot
3 Panuwat


$ echo "Linux is incredible" | tr [:space:] '\t'
Linux is incredible

Cut, paste, and join

ชุดคำสั่งที่น่าสนใจที่ใช้ในการจัดการฟิลด์ข้อมูล (filed) ซึ่งมีประโยชน์มากในการจัดการข้อมูลที่ถูกเก็บในลักษณะตาราง การใช้งานคำสั่ง paste ตัวอย่างเช่นเมื่อต้องการที่จะดึงคอลัมน์ข้อมูลที่ต้องการจากอีกไฟล์หนึ่งเพื่อที่จะไปรวมเข้ากับอีกไฟล์หนึ่ง ดังรูปข้างล่าง

ตัวอย่างข้างล่างแสดงการรวมข้อมูลจากไฟล์ B.txt มาต่อเป็นอีกคอลัมน์ในไฟล์ A.txt แล้วบันทึกเป็นไฟล์ใหม่ C.txt จะเห็นว่าจะมีช่องว่าง space เป็นค่าปริยาย ถ้าต้องการระบุตัวคั้น (delimiter) เป็นตัวอื่น ก็สามารถระบุโดยใช้ -d ดังแสดงข้างล่าง

$ paste A.txt B.txt > C.txt


$ cat C.txt
a1 b1
a2 b2
a3 b3
a4 b4
a5 b5


$ paste -d”,” A.txt B.txt > D.txt


$ cat D.txt
a1,b1
a2,b2
a3,b3
a4,b4
a5,b5

สำหรับคำสั่ง join จะถูกใช้ในการเชื่อมฟิลด์ที่มีข้อมูลเหมือนกันเข้าด้วยกัน โดยไฟล์ทั้งสองที่ถูกนำมาเชื่อมกันนี้ควรมีการจัดเรียงที่เหมือนกันด้วย ดังรูปข้างล่าง

ตัวอย่างข้างล่างแสดงการ join ข้อมูลจากทั้งสองไฟล์ (people.txt และ age.txt) ที่มีฟิลด์ตรงกัน

$ cat people.txt
Wiroon Male
Nayot Male
Panuwat Male
Jantana Female
Apirath Male
Anuparp Male


$ cat age.txt
Wiroon 38
Nayot 37
Panuwat 38
Jantana 28
Apirath 28
Anuparp 40


$ join people.txt age.txt > profiles.txt


$ cat profiles.txt
Wiroon Male 38
Nayot Male 37
Panuwat Male 38
Jantana Female 28
Apirath Male 28
Anuparp Male 40

คำสั่ง cut นั้นจะถูกใช้ในการตัดทอนฟิลด์ของข้อมูลภายในไฟล์ ซึ่งโดยปกติจะใช้ tab ในการแบ่งข้อมูลแต่ละฟิลด์

$ cat profiles.txt
Wiroon Male 38
Nayot Male 37
Panuwat Male 38
Jantana Female 28
Apirath Male 28
Anuparp Male 40


$ cut -d’ ‘ -f2 profiles.txt
Male
Male
Male
Female
Male
Male


$ cut -d’ ‘ -f2,3 profiles.txt  หรือ  cut -d’ ‘ -f2-3 profiles.txt
Male 38
Male 37
Male 38
Female 28
Male 28
Male 40


$ cut -d’ ‘ -f-2 profiles.txt   <---- ตัดออกมาตั้งฟิลด์แรกจนถึงฟิลด์ที่ 2
M Wiroon Male
Nayot Male
Panuwat Male
Jantana Female
Apirath Male
Anuparp Male


$ cut -d’ ‘ -f2- profiles.txt   <---- ตัดออกมาตั้งแต่ฟิลด์ที่ 2 จนถึงฟิลด์สุดท้าย
Male 38
Male 37
Male 38
Female 28
Male 28
Male 40


$ cut -d ' ' -f-2 --output-delimiter=',' profiles.txt   <---- ใส่เครื่องหมาย , แทนช่องว่าง
Wiroon,Male
Nayot,Male
Panuwat,Male
Jantana,Female
Apirath,Male
Anuparp,Male
pastedGraphic_2.png
🖥️
โครงสร้างไดเรกทอรีภายในระบบปฏิบัติการลีนุกซ์
รูปแสดงผลลัพธ์การเปิดไฟล์ /var/log/syslog ด้วยคำสั่ง less
รูปแสดงผลลัพธ์การติดตามการเปลี่ยนแปลงข้อมูลในไฟล์ด้วยคำสั่ง tail