Fundamentals 29 min read

Understanding the Command Line: Bash Basics, File Operations, Permissions, and Common CLI Tools

This tutorial introduces the command‑line interface, explains key terminology, demonstrates Bash prompt customization, shows how to navigate and manipulate files, manage I/O redirection and permissions, and provides practical examples of common Unix commands such as cat, grep, pipe, sed, and network utilities.

Qunar Tech Salon
Qunar Tech Salon
Qunar Tech Salon
Understanding the Command Line: Bash Basics, File Operations, Permissions, and Common CLI Tools

The command‑line interface (CLI) is a text‑based environment where users type commands to control the operating system; it can be a powerful ally or a daunting foe depending on how it is used.

Terminology : In Unix‑like systems the terms terminal , console , and shell are often confused. A console is a physical keyboard‑monitor pair, a terminal emulates a console, and a shell (e.g., Bash) is the program that reads user input and executes commands.

Bash (Bourne Again SHell) is the default shell on most Linux distributions. It interprets commands, runs scripts, and manages processes, windows, and other system resources.

Bash Prompt : The prompt (PS1) shows user, host, and current directory. Example: csaba@csaba-pc ~/Personal/Programming/NetTuts$ You can view the current prompt variable with: echo $PS1 Typical output: \[\033[01;32m\]\u@\h\[\033[01;34m\] \w \$\[\033[00m\] The escape sequences set colors (e.g., \[\033[01;32m\] for green) and placeholders such as \u (username), \h (hostname), and \w (working directory).

Operating on Directories and Files : Common commands include mkdir, cd, ls, touch, pushd, and popd. Example workflow:

mkdir ~/tmp/NetTuts
cd ~/tmp/NetTuts
mkdir AnotherDir
mkdir SecondDir
touch SecondDir/aFile
pushd ~/tmp/NetTuts
ls -al
popd

Standard I/O : Commands read from stdin (default keyboard) and write to stdout (default console) or stderr (error output). File descriptors 0, 1, and 2 correspond to these streams.

Redirection : Use < to read from a file, > to write (overwrite) to a file, and >> to append. Example: ls -al > ./ThirdFile Redirecting only standard error: ls nonexistent 2> error.log Redirect both streams to the same file: find . -name '*File' > results.txt 2>&1 Permissions : Unix permissions are expressed as rwx for user, group, and others. They can be set symbolically ( chmod +rwx file) or numerically ( chmod 765 file).

Changing ownership uses chown user:group file. Example: chown csaba:users ./AnotherDir Common Commands : cat file – display file contents. grep "pattern" file – search for a pattern. sed -e "s/old/new/" – stream editor for substitutions.

Pipes ( |) connect commands, e.g., cat file | grep "text".

Custom Commands : Define shortcuts with alias (temporary) or add them to ~/.bashrc (persistent). Example alias:

alias sshcon='ssh [email protected] -p 8743'

After editing ~/.bashrc, reload with source ~/.bashrc or start a new shell.

Network Utilities : ping 8.8.8.8 – test reachability. traceroute 8.8.8.8 – show path to a host. route (or netstat -nr) – display routing table.

These commands together form a solid foundation for working efficiently in a Unix‑like command‑line environment.

By mastering the CLI, you gain a versatile toolset that extends far beyond the graphical interface.

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.

networkShellBashPermissionscommand-line
Qunar Tech Salon
Written by

Qunar Tech Salon

Qunar Tech Salon is a learning and exchange platform for Qunar engineers and industry peers. We share cutting-edge technology trends and topics, providing a free platform for mid-to-senior technical professionals to exchange and learn.

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.