Linux Filesystem Overview, Common Issues, and Vim/Shell Command Guide
This article introduces the Linux filesystem hierarchy, explains typical directories, provides solutions for MobaTextEditor garbled text, and offers a concise guide to Vim modes, settings, search/replace commands, and useful shell scripts for system administrators.
This article, contributed by the FunTester learning community, presents a comprehensive overview of the Linux filesystem directories and their purposes.
Filesystem
/bin (including /usr/bin, /usr/local/bin) – stores frequently used commands.
/sbin (including /usr/sbin, /usr/local/sbin) – system administration programs.
/home – user home directories, one per user.
/root – home directory for the superuser.
/lib – dynamic shared libraries required at boot, similar to Windows DLLs.
/lost+found – usually empty; stores files after an improper shutdown.
/etc – configuration files and subdirectories for system management.
/usr – major directory containing many applications and files, analogous to Windows Program Files.
/boot – kernel and related boot files.
/proc – virtual filesystem exposing kernel and process information.
/srv – data for services after they start.
/sys – sysfs, a newer kernel filesystem.
/tmp – temporary files.
/dev – device files representing hardware, similar to Windows Device Manager.
/media – mount points for detected devices (e.g., USB drives).
/run – temporary files created by processes.
/mnt – temporary mount points for other filesystems.
/opt – directory for additional software installations.
/usr/local – programs installed from source.
/var – logs and frequently changing data.
Linux Work Issue Solutions
MobaTextEditor Garbled Text
Problem:
/bin/bash^M: bad interpreter: No such file or directoryRoot Cause
In Windows each line ends with
, while Linux expects only
. When a shell script edited on Windows is copied to Linux, an extra \r character appears (displayed as ^M), causing garbled text in MobaTextEditor.Solution
Remove carriage returns: sed -i 's/\r$//' filename (replace filename with your script name).
Use dos2unix:
dos2unix xxx.shVim Commands
Three Modes
Command mode (cursor navigation)
Insert mode – text entry
Ex mode (also called “quit” mode)
Mode Settings
:set– display options :set nu – show line numbers :set nonu – hide line numbers :set cursorline – highlight current line
Search and Replace
Search: /keyword (use n / N to move forward/backward)
Replace examples: :s/aa/bb – replace first aa on the current line with
bb :s/aa/bb/g– replace all aa on the current line :%s/aa/bb/g – replace all aa in the file :3,10s/aa/bb/g – replace aa with bb from line 3 to 10 :%s/\\/\//g – replace backslash with slash (escape special characters) :%s,\\,/,g – alternative delimiter :%s,aa,bb,gic – case‑insensitive replace with confirmation
Edit Multiple Files Simultaneously
Open a split:
:sp filename Ctrl+w ↑– move cursor to the upper window Ctrl+w ↓ – move cursor to the lower window
Attached Shell Script Example
#!/bin/bash
# Construct trivial files and compute MD5 values
# author: brh
# date: 2020-10-09
case $1 in
"-h")
echo "1: ./xxx.sh touch_file num"
echo "2: ./xxx.sh touch_md5_file num"
echo "3: ./xxx.sh check_md5_file num"
;;
"touch_file")
# generate trivial files
for((i=1;i<=$2;i++)); do
echo $i > $i.txt
done
;;
"touch_md5_file")
# compute MD5 and save
for((i=1;i<=$2;i++)); do
md5sum $i.txt > $i.txt.md5
done
;;
"check_md5_file")
# compare MD5 values
for((i=1;i<=$2;i++)); do
md5num1=`md5sum $i.txt`
md5num2=`cat $i.txt.md5`
if [ "$md5num1"x = "$md5num2"x ]; then
echo "$i.txt MD5 data consistent"
else
echo "$i.txt MD5 data inconsistent"
fi
done
;;
esacAuthor: FunTester – Tencent Cloud annual author, Boss Direct hiring author, GDevOps official media partner.
Signed-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.
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.
