Linux file management command syntax, parameters, instance summary

Command: cat

The cat command is used to concatenate files and print them to the standard output device. It is one of the most commonly used commands in Unix-like operating systems for viewing, creating, merging, and copying files.

Usage Rights:

All users

Syntax Format:

cat [-AbeEnstTuv] [--help] [--version] fileName

Parameter Description:

-n or --number: Number all output lines starting from 1.

-b or --number-nonblank: Similar to -n but does not number blank lines.

-s or --squeeze-blank: Replace multiple consecutive blank lines with a single blank line.

-v or --show-nonprinting: Display non-printing characters using ^ and M- symbols (except for LFD and TAB).

-E or --show-ends: Display $ at the end of each line.

-T or --show-tabs: Display TAB characters as ^I.

-e: Equivalent to -vE.

-A, --show-all: Equivalent to -vET.

Examples:

Add line numbers to textfile1 and save it to textfile2:

cat -n textfile1 > textfile2

Append contents of textfile1 and textfile2 into textfile3 without adding extra blank lines:

cat -b textfile1 textfile2 >> textfile3

Empty the contents of /etc/test.txt:

cat /dev/null > /etc/test.txt

Create an image file of a floppy disk by reading from /dev/fd0:

cat /dev/fd0 > OUTFILE

Write the image file back to the floppy disk:

cat IMG_FILE > /dev/fd0

Note:

OUTFILE refers to the name of the output image file.

IMG_FILE refers to the image file you want to write back.

Ensure that the device capacity matches when writing back to the device.

Commonly used for creating boot disks.

Command: chattr

The Linux chattr command is used to change file attributes on the ext2 file system. These attributes can control various behaviors such as preventing modification, ignoring access times, and more.

Available modes include:

- Immutable: Prevents the file from being modified.

- No access time update: Does not update the last access time.

- Compressed: Compresses the file.

- No dump: Excludes the file from being dumped.

- Append only: Allows data to be added but not deleted.

- Secure deletion: Deletes the file securely.

- Sync: Ensures immediate updates.

- Not removable: Prevents accidental deletion.

Syntax Format:

chattr [-RV][-v][+/-/=][file or directory...]

Parameters:

-R: Recursively process directories.

-v: Set the version number.

-V: Verbose mode.

+: Enable the attribute.

-: Disable the attribute.

=: Set the attribute.

Example:

Prevent a critical file from being modified:

chattr +i /etc/resolv.conf

List the attributes of a file:

lsattr /etc/resolv.conf

This will display something like:

----i-------- /etc/resolv.conf

Make a file append-only, suitable for log files:

chattr +a /var/log/messages

Command: chgrp

The chgrp command is used to change the group ownership of a file or directory in a UNIX-like system. This allows for better management of file access permissions based on group settings.

Usage Rights:

Root user

Syntax Format:

chgrp [-cfhRv][--help][--version][group][file or directory...] or chgrp [-cfhRv][--help][--reference=][--version][file or directory...]

Parameters:

-c or --changes: Only show changes made.

-f or --quiet: Suppress error messages.

-h or --no-dereference: Do not follow symbolic links.

-R or --recursive: Process directories recursively.

-v or --verbose: Show detailed information.

--reference: Set the group to match that of another file or directory.

Example:

Change the group of a file to 'bin':

chgrp -v bin log2012.log

Change the group of a file to match another file's group:

chgrp --reference=log2012.log log2013.log

Transport Drones

5-50kg Transport drones,A large payload unmanned aerial vehicle that can be used for multiple purposes and functions such as rescue, transportation, lighting, law enforcement, etc
We can customize drones with different distances, weights, and application scenarios according to customer needs, hoping to bring higher efficiency to your work. Please do not use them for warfare

5-50kg multifunctional load-bearing unmanned 5-50kg multifunctional load-bearing unmanned 5-50kg multifunctional load-bearing unmanned

Customized Throwing Transport Drones,Heavy Duty Drone,Firefighting and Rescue Heavy Drones

Jiangsu Yunbo Intelligent Technology Co., Ltd , https://www.fmodel-ai.com

This entry was posted in on