Master Linux Command Line: cat, chattr, chgrp, chmod, find and More Explained
This guide provides detailed explanations of essential Linux commands—including cat, chattr, chgrp, chmod, chown, cksum, cmp, diff, diffstat, file, find, git, gitview, and indent—covering their purpose, syntax, options, and practical examples for effective system administration.
cat
The cat command concatenates files and prints their contents to standard output.
Usage
All users can run the command.
Syntax
cat [-AbeEnstTuv] [--help] [--version] fileNameOptions
-nor --number: number all output lines starting at 1. -b or --number-nonblank: number non‑blank lines only. -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‑ notation, except LFD and TAB. -E or --show-ends: display $ at line ends. -T or --show-tabs: display TAB characters as ^I. -e: equivalent to -vE. -A, --show-all: equivalent to -vET.
Examples
cat -n textfile1 > textfile2 cat -b textfile1 textfile2 >> textfile3 cat /dev/null > /etc/test.txt cat /dev/fd0 > OUTFILE # create floppy image cat IMG_FILE > /dev/fd0 # write image to floppychattr
The chattr command changes file attributes on ext2/3/4 file systems.
Syntax
chattr [-RV][-v<version>][+/-=<attr>] file...Options
-R: recursively process directories. -v<version>: set file version. -V: verbose output. +<attr>: add attribute. -<attr>: remove attribute. =<attr>: set exact attribute.
Examples
chattr +i /etc/resolv.conf # make immutable lsattr /etc/resolv.conf chattr +a /var/log/messages # append‑onlychgrp
The chgrp command changes the group ownership of files or directories.
Syntax
chgrp [-cfhRv][--help][--version] group file... chgrp [-cfhRv][--help][--reference=<ref>][--version] file...Options
-cor --changes: report only when a change is made. -f or --quiet or --silent: suppress error messages. -h or --no-dereference: affect symbolic links themselves. -R or --recursive: recurse into directories. -v or --verbose: verbose output. --help: display help. --reference=<ref>: set group to match that of the reference file. --version: display version.
Examples
chgrp -v bin log2012.log chgrp --reference=log2012.log log2013.logchmod
The chmod command modifies file permission bits.
Syntax
chmod [-cfvR] [--help] [--version] mode file...Mode format
[ugoa...][[+-=][rwxX]...][,...]Options
-c: report only when a change is made. -f: suppress error messages. -v: verbose output. -R: apply recursively. --help: display help. --version: display version.
Examples
chmod ugo+r file1.txt chmod a+r file1.txt chmod ug+w,o-w file1.txt file2.txt chmod u+x ex1.py chmod -R a+r * chmod 777 file chmod abc file # a,b,c represent user, group, other permissionschown
The chown command changes file owner and/or group.
Syntax
chown [-cfhvR] [--help] [--version] user[:group] file...Options
-c: report only when a change is made. -f: suppress errors. -h: affect symbolic links themselves. -v: verbose output. -R: recursive. --help: help. --version: version.
Examples
chown jessie:users file1.txt chown -R lamport:users *cksum
The cksum command computes a CRC checksum and byte count for files.
Syntax
cksum [--help][--version][file...]Options
--help: display help. --version: display version.
Example
cksum testfile1Output shows checksum, byte count, and filename.
cmp
The cmp command compares two files byte by byte.
Syntax
cmp [-clsv][-i <bytes>][--help] file1 file2Options
-cor --print-chars: show differing characters. -i<bytes> or --ignore-initial=<bytes>: skip initial bytes. -l or --verbose: list all differences. -s or --quiet: silent mode. -v or --version: version. --help: help.
Example
cmp prog.o.bak prog.oIf files differ, the first differing byte and line are reported.
diff
The diff command compares files line by line.
Syntax
diff [options] file1 file2Common options
-aor --text: treat all files as text. -b or --ignore-space-change: ignore changes in whitespace. -B or --ignore-blank-lines: ignore blank lines. -c: context diff. -u or --unified: unified diff. -r or --recursive: recurse into directories. -q or --brief: report only if files differ. --help: help.
Examples
diff log2014.log log2013.log diff -y -W 50 log2014.log log2013.logSymbols |, <, and > indicate differences, missing lines, and extra lines respectively.
diffstat
The diffstat command summarizes the output of diff, showing insertions and deletions per file.
Syntax
diffstat [-wV] [-n <len>] [-p <len>] [-w <width>]Example
diff -r test1 test2 | diffstatDisplays a concise change summary.
file
The file command determines the type of a file.
Syntax
file [-bcLvz] [-f namefile] [-m magicfile...] file...Options
-b: omit filename in output. -c: verbose (debug) output. -L: follow symbolic links. -v: version. -z: try to examine compressed files.
Example
file install.logOutput:
install.log: UTF-8 Unicode textfind
The find command searches for files and directories matching given criteria.
Syntax
find path [expression]Common options
-namepattern : match filename. -iname pattern : case‑insensitive name match. -type c : file type (f, d, l, etc.). -size n : file size. -perm mode : match permission bits. -mtime n : modification time. -exec command {} \\; : execute command on each match. -ok command {} \\; : like -exec but ask before execution.
Examples
find . -name "*.c" find . -type f find . -ctime -20 find /var/logs -type f -mtime +7 -ok rm {} \; find . -type f -perm 644 -exec ls -l {} \; find / -type f -size 0 -exec ls -l {} \;git
The git command in this context refers to a text‑mode file manager offering shortcuts for common operations.
Key shortcuts
F1 – info
F2 – cat (display file)
F3 – gitview (hex/ASCII view)
F4 – vi (edit)
F5 – cp (copy)
F6 – mv (move/rename)
F7 – mkdir (create directory)
F8 – rm (delete)
F9 – make (run build commands)
F10 – exit
gitview
The gitview command displays a file in both hexadecimal and ASCII formats.
Syntax
gitview [-bchilv] fileOptions
-b: monochrome mode. -c: color mode. -h: help. -i: show program location. -l: no previous screen. -v: version.
Example
gitview -c /home/rootlocal/demo.txtindent
The indent command reformats C source code according to specified style options.
Syntax
indent [options] source.c [-o output.c]Selected options
-bador --blank-lines-after-declarations: add blank line after declarations. -bap or --blank-lines-after-procedures: add blank line after functions. -bl or --braces-after-if-line: place { on a new line after if. -i<n> or --indent-level<n>: set indentation width. -kr or --k-and-r-style: use Kernighan & Ritchie style. -gnu or --gnu-style: use GNU style (default). -ut or --use-tabs: indent with tabs. -ts<n> or --tab-size<n>: set tab size.
Example
indent -gnu -i4 -ut source.c -o formatted.cSigned-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
