Master Essential Linux Commands: ls, cd, mkdir, rm, cp, mv, and More
This guide explains the core Linux command‑line tools—including ls, cd, mkdir, pwd, rmdir, rm, cp, mv, and ln—detailing their syntax, common options, example outputs, file‑permission notation, and the purpose of standard system directories for beginners and seasoned users alike.
Command Prompt
The prompt root@localhost ~# shows the current user ( root), hostname ( localhost) and the present working directory ( ~ = home). A trailing # indicates a super‑user prompt; a regular user sees $.
Command Syntax
General form: command [options] [arguments]. Square brackets denote optional parts.
Listing Directory Contents – ls
Common options: -a: show all files, including hidden ones. -l: long listing with detailed information. -d: display directory attributes instead of its contents. -h: human‑readable file sizes. -i: show inode numbers.
[root@localhost ~]# ls
anaconda-ks.cfg test
[root@localhost ~]# ls -a
. .. anaconda-ks.cfg .bash_history .bash_logout .bash_profile .bashrc .cache .config .cshrc .tcshrc test
[root@localhost ~]# ls -l
total 4
-rw-------. 1 root root 2752 Nov 10 02:51 anaconda-ks.cfg
drwxr-xr-x. 2 root root 6 Nov 12 19:26 test
[root@localhost ~]# ls -lh
total 4.0K
-rw-------. 1 root root 2.7K Nov 10 02:51 anaconda-ks.cfg
drwxr-xr-x. 2 root root 6 Nov 12 19:26 test
[root@localhost ~]# ls -i
71259104 anaconda-ks.cfg 36099565 testFile‑permission strings consist of ten characters. The first character indicates the file type ( - regular file, d directory, l symbolic link). The next nine characters are three groups of rwx for owner, group and others. Example: -rw------- means a regular file readable and writable only by the owner; drwxr-xr-x grants full access to the owner and read/execute to group and others. A trailing dot ( .) signals ACL information; the number after it is the link count.
Directory Management Commands
Create Directory – mkdir
[root@localhost ~]# mkdir otherFolder
[root@localhost ~]# ls
anaconda-ks.cfg otherFolder test
[root@localhost ~]# mkdir folder_2/test_2
mkdir: cannot create directory "folder_2/test_2": No such file or directory
[root@localhost ~]# mkdir -p folder_2/test_2
[root@localhost ~]# ls
anaconda-ks.cfg folder_2 otherFolder test
[root@localhost ~]# ls folder_2/
test_2Without -p, mkdir cannot create nested directories; -p enables recursive creation.
Change Directory – cd
[root@localhost ~]# cd /folder_2/test_2
[root@localhost test_2]# cd
[root@localhost ~]# cd -
/root/folder_2/test_2
[root@localhost test_2]# cd ../../otherFolder
[root@localhost otherFolder]# cd ..
[root@localhost ~] cd ~– go to the current user’s home directory. cd - – return to the previous directory. cd .. – move up one level. cd (no arguments) – go to the home directory.
Absolute paths start with /; relative paths are resolved from the current directory.
Print Working Directory – pwd
[root@localhost ~]# pwd
/rootDisplays the full path of the current directory.
Remove Empty Directory – rmdir
[root@localhost ~]# rmdir otherFolder
[root@localhost ~]# ls
anaconda-ks.cfg folder_2 test
[root@localhost ~]# rmdir folder_2
rmdir: failed to remove "folder_2": Directory not empty rmdirsucceeds only on empty directories.
Remove Files or Directories – rm
Typical usage:
rm -rf [file_or_directory] -r: recursive removal (files and sub‑directories). -f: force removal without prompts.
[root@localhost ~]# rm abc.txt
rm: remove regular empty file "abc.txt"? y
[root@localhost ~]# rm test
rm: cannot remove "test": Is a directory
[root@localhost ~]# rm -r test
rm: remove directory "test"? y
[root@localhost ~]# rm -rf folder_2Copy Files – cp
Syntax:
cp [options] source target -r: copy directories recursively. -p: preserve mode, ownership and timestamps. -d: preserve links. -a: archive mode (equivalent to -rpd).
[root@localhost ~]# cp bbc.txt folder_a
[root@localhost ~]# cp folder_a folder_b
cp: omitting directory "folder_a"
[root@localhost ~]# cp -r folder_a folder_b
[root@localhost ~]# ls folder_b
folder_a test_1
[root@localhost ~]# cp -a bbc.txt folder_bWithout -p or -a, the copy’s modification time may differ from the source. Using -a or -p retains the original timestamps.
Move or Rename – mv
[root@localhost ~]# mv bbc.txt abc.txt
[root@localhost ~]# ls
abc.txt anaconda-ks.cfg
[root@localhost ~]# mkdir test
[root@localhost ~]# mv abc.txt test/
[root@localhost ~]# ls test/
abc.txtIf source and destination are in the same directory, mv acts as a rename; otherwise it moves the file.
Link Files – ln
Hard link (shares the same inode):
[root@localhost ~]# touch bbb.txt
[root@localhost ~]# ln bbb.txt folder/ccc.txtHard links cannot cross filesystem boundaries and cannot be created for directories.
Symbolic (soft) link:
[root@localhost ~]# ln -s bbb.txt folder_b/eee.txtSoft links store the pathname of the target and have their own inode. If the target is removed, the link becomes dangling.
Common Top‑Level Directories
/– root directory. /bin – essential user commands. /sbin – system administration commands (root only). /boot – boot loader files. /dev – device files. /etc – configuration files. /home – regular user home directories. /lib – shared libraries. /mnt – temporary mount points. /media – removable media mount points. /root – super‑user home directory. /tmp – temporary files. /proc – kernel and process information (virtual filesystem). /sys – device and driver information (virtual filesystem). /usr – user utilities and applications. /var – variable data such as logs and databases.
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.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
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.
