Operations 24 min read

Master Essential Linux Commands: cat, chmod, chown, cp, and More

This guide provides concise syntax, descriptions, common options, and practical examples for essential Linux commands such as cat, chattr, chmod, chown, cp, ln, locate, lsattr, mv, rm, tee, touch, umask, whereis, and which, helping users efficiently manage files and system attributes from the command line.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Master Essential Linux Commands: cat, chmod, chown, cp, and More

cat

Usage: cat [-AbeEnstTuv] [--help] [--version] FILENAME Description: Displays the contents of a file or concatenates multiple files to standard output (the output can be redirected to create a combined file).

Common options and examples:

# cat test1 -n
1  1111
2
3  22222
4  333333

# cat test2 -b
1  1111
2  3333

# cat test1 test2 -n > test3
# cat test3
1  1111
2
3  22222
4  333333
5  1111
6
7  3333

chattr

Usage:

chattr [-RV] [-v<version>] [+/-/=<attribute>] FILE...

Description: Changes file hidden attributes on ext2/ext3/ext4 file systems.

Attribute modes:

a – allow only append operations.

b – do not update the file's last access time.

c – compress the file on disk.

d – do not allow the file to be deleted.

i – immutable; the file cannot be modified.

s – secure deletion.

S – synchronous updates.

u – undelete protection.

Common options and examples:

# chattr -RV +i test
Flags of test set as ----i-----------
# lsattr test
----i----------- test

# chattr -RV -i test
Flags of test set as ----------------
# lsattr test
---------------- test

# chattr -RV =idS test
Flags of test set as --S-i-d---------
# lsattr test
--S-i-d--------- test

chmod

Usage: chmod [-cfRv] [--help] [--version] [<mode>] FILE... or chmod [-cfRv] [--reference=<ref>] FILE... Description: Changes file or directory permissions.

Permission symbols:

u – user (owner)

g – group

o – others

a – all (u,g,o)

r – read (4)

w – write (2)

x – execute (1)

- – no permission (0)

Common options and examples:

# chmod -Rv +w test
mode of 'test' retained as 0755 (rwxr-xr-x)

# chmod -Rv a-w test
mode of 'test' changed from 0755 to 0555 (r-xr-xr-x)

# chmod -Rv a=w test
mode of 'test' changed from 0555 to 0222 (-w--w--w-)

# chmod --reference sh test
# ls -d test sh
drwxr-xr-x. 2 root root 4.0K test
drwxr-xr-x. 2 root root 4.0K sh

chown

Usage:

chown [-cfhRv] [--dereference] [--reference=<ref>] USER[:GROUP] FILE...

Description: Changes the owner and/or group of a file or directory.

Common options and examples:

# chown -Rc gwx.gwx test
changed ownership of 'test' from root:root to gwx:gwx
# ls -d test
drwxr-xr-x. 2 gwx gwx 30 Nov 4 16:04 test

# chown -hc gwx.gwx test1
changed ownership of 'test1' from root:root to gwx:gwx
# ls -l test1
lrwxrwxrwx. 1 gwx gwx 4 Nov 4 16:02 test1 -> test/

# chown --reference=/home/gwx/sh/back-etc.sh test
# ls -d test
drwxr-xr-x. 2 gwx gwx 30 Nov 4 16:04 test

cp

Usage: cp [-abdfilpPrRsuvx] SOURCE DEST Description: Copies files or directories.

Common options and examples:

# cp -aiv test test1
'test' -> 'test1'
'test/test1' -> 'test1/test1'
'test/test2' -> 'test1/test2'

# cp -sv sh.tar.xz sh.tar.xz.ln
'sh.tar.xz' -> 'sh.tar.xz.ln'
# ls -l sh.tar.xz.ln
lrwxrwxrwx. 1 root root 9 Nov 4 16:40 sh.tar.xz.ln -> sh.tar.xz

# cp -d sh.tar.xz.ln sh1.tar.xz
# ls -l sh1.tar.xz
lrwxrwxrwx. 1 root root 9 Nov 4 16:41 sh1.tar.xz -> sh.tar.xz

# cp -l sh.tar.xz sh2.tar.xz
# ls -l sh2.tar.xz
-rw-r--r--. 2 root root 2.7K sh2.tar.xz

ln

Usage: ln [-bdfinsv] TARGET LINK_NAME or ln [-bdfinsv] TARGET... DIRECTORY Description: Creates hard or symbolic links.

Common options and examples:

# ln -s nginx-1.11.5.tar.gz nginx
# ln nginx-1.11.5.tar.gz nginx1
# ls -l nginx*
lrwxrwxrwx. 1 root root 19 Nov 4 17:06 nginx -> nginx-1.11.5.tar.gz
-rw-r--r--. 2 root root 935K nginx1

locate

Usage: locate [-d DATABASE] PATTERN... Description: Searches for files using a local filename database (updated with updatedb).

Common options and examples:

# locate nginx-1.11.5.tar.gz
/root/nginx-1.11.5.tar.gz

lsattr

Usage: lsattr [-adlRvV] FILE... Description: Displays file hidden attributes.

Common options and examples:

# lsattr -a
---------------- ./.
---------------- ./..
---------------- ./test1
---------------- ./test2

# lsattr -d
---------------- .

# lsattr -R test
---------------- test/test1
---------------- test/test2
---------------- test/test.ln

mv

Usage: mv [-bfiuv] SOURCE DEST Description: Moves or renames files or directories.

Common options and examples:

# mv ../passwd .
# ls -l passwd
-rw-r--r--. 1 root root 3.0K passwd

# mv test.ln test.mv
# ls -l test.mv
-rw-r--r--. 2 root root 16 Nov 4 16:03 test.mv

rm

Usage: rm [-dfirv] FILE... Description: Removes files or directories.

Common options and examples:

# rm -dirv test1
rm: descend into directory 'test1'? y
rm: remove regular file 'test1/test1'? y
removed 'test1/test1'
rm: remove regular file 'test1/test2'? y
removed 'test1/test2'
rm: remove directory 'test1'? y
removed directory: 'test1'

tee

Usage: tee [-ai] FILE... Description: Reads from standard input and writes to both standard output and files.

Common options and examples:

# tee -ai test1
(test1 now contains appended lines)

touch

Usage: touch [-acfm] [-d DATE] [-r REFERENCE] [-t TIME] FILE... Description: Changes file timestamps; creates the file if it does not exist.

Common options and examples:

# touch -at 201611041700.25 test1
# ls -u test1
-rw-r--r--. 2 root root 24 Nov 4 17:00 test1

# touch -c gghgag   (no file created)

# touch -mt 201611010000 test1
# ls -l test1
-rw-r--r--. 2 root root 24 Nov 1 00:00 test1

# touch -r test1 test2
# ls -l test2
-rw-r--r--. 1 root root 9 Nov 1 00:00 test2

umask

Usage: umask [-S] [MASK] Description: Sets the default permission mask applied when creating new files.

Common options and examples:

# umask
0022
# umask -S
u=rwx,g=rx,o=rx

whereis

Usage: whereis [-bfmsu] FILE... Description: Locates the binary, source, and manual page files for a command.

Common options and examples:

# whereis -b ls
ls: /usr/bin/ls

which

Usage: which FILE... Description: Searches the directories listed in the $PATH environment variable for executable files.

Common options and examples:

# which ls
ls is aliased to `ls -hF --color'
ls is /usr/bin/ls
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

LinuxShellUnixcommand-line
MaGe Linux Operations
Written by

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.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.