INSIGHTS
Infrastructure & Systems

10 Must-Know Bash Commands You Can’t Live Without (Beginner to Pro Guide)

In this article
  1. 1. pwd — confirm where you are
  2. 2. ls — inspect files before acting
  3. 3. cd — change directories deliberately
  4. 4. mkdir — create a controlled workspace
  5. 5. cp — copy rather than overwrite your only copy
  6. 6. mv — rename or relocate a file
  7. 7. cat — read and combine small text files
  8. 8. grep — search for a known pattern
  9. 9. find — locate files using explicit conditions
  10. 10. chmod — understand and adjust permissions
  11. Understand quoting, expansions and safe practice

Bash is useful because it turns a collection of files and processes into a workflow that can be inspected, repeated and eventually automated. But learning the shell is not the same as memorizing a long list of commands. A beginner needs a small toolkit, an understanding of current directories and arguments, and a habit of verifying what a command will change before running it with elevated privileges.

These ten commands provide that foundation: pwd, ls, cd, mkdir, cp, mv, cat, grep, find, and chmod. The examples are designed for a practice directory, not a production server. Bash is the shell that interprets the commands; several of the named utilities are separate programs supplied by the operating system. Available options may differ slightly across GNU, BSD and other Unix-like systems.

1. pwd — confirm where you are

The pwd command displays the current working directory. This matters whenever a subsequent command uses a relative path such as reports/ or ./backup. If your shell is in the wrong directory, a command that looked harmless can create, copy or modify the wrong files.

pwd

For a training exercise, open a terminal and note the directory. Commands in this article should operate on files you created yourself under a dedicated practice folder. Never use a guessed current directory when dealing with production data. In a script, record or deliberately set the working directory instead of assuming the script always starts from the location where it was saved.

2. ls — inspect files before acting

ls lists directory entries. Options such as -l add ownership, permission, size and timestamp information; -a shows entries whose names begin with a dot. Hidden files are not inherently suspicious or disposable: many applications store configuration in them.

ls
ls -la

Use listings to confirm exact names and identify whether a target is a regular file, directory or symbolic link. Filenames can contain spaces, tabs and unusual characters, so avoid constructing automatic modification commands by blindly parsing the default output of ls. A graphical file browser may show the same information, but the terminal listing is especially helpful during remote administration and troubleshooting.

3. cd — change directories deliberately

The cd builtin changes the shell’s working directory. cd .. moves to the parent directory; cd with no argument usually returns to the user’s home directory. Relative paths are interpreted against the current directory, while absolute paths begin at the filesystem root.

cd ~
cd Documents
cd ..
pwd

Quoted paths protect names containing spaces. For example, cd "Project Notes" treats the two words as one directory name. An error from cd means the directory did not change; a robust script should stop rather than continue using the wrong location. An explicit test or shell setting can help prevent later commands from operating on unexpected files.

4. mkdir — create a controlled workspace

The mkdir utility creates directories. With -p, it creates missing parent directories and does not fail merely because the target directory already exists. This is useful when preparing a repeatable practice hierarchy without manually making each intermediate folder.

mkdir -p "$HOME/bash-practice/reports"
cd "$HOME/bash-practice"
pwd

This folder gives you a safe location for the remaining exercises. Quoting "$HOME/bash-practice" matters if a variable contains spaces; in general, quote variable expansions when they are supposed to represent one filesystem path. Do not create practice files under service, system or application directories simply because the shell allows it.

5. cp — copy rather than overwrite your only copy

cp copies files and, with appropriate options, directories. A basic copy keeps the original file and creates a destination file. The -i option requests confirmation before overwriting an existing destination in common GNU and BSD implementations; it is useful interactively but should not be the only safeguard for unattended automation.

cp -i notes.txt reports/notes-copy.txt

The example assumes you created notes.txt in your practice folder. When verifying a critical copy, check contents or hashes and ensure that ownership and permissions meet the application requirement. Copying a file is not the same as performing an application-consistent database backup; databases and other stateful services need their own supported backup procedures.

6. mv — rename or relocate a file

mv moves an entry or changes its name. Within one filesystem a rename may be very fast; across filesystems the implementation may need to copy data and remove the original. A careless command can replace an important destination or leave a workflow incomplete after an error.

mv -i reports/notes-copy.txt reports/notes-archived.txt

Inspect both source and destination before using mv, especially in scripts that process many files. Do not rely on prompts in automated jobs. If a business workflow requires atomic version transitions, design around supported filesystem operations and check exit status rather than assuming every move is atomic regardless of source and destination.

7. cat — read and combine small text files

The cat utility writes file contents to standard output. It is a quick way to inspect short configuration examples, text notes or a script you have just created. It is not ideal for large binary files, rapidly changing logs or secrets that should not be displayed in a shared terminal.

cat notes.txt

Output can be redirected to a file, but redirection is interpreted by the shell and can truncate the destination before the command begins. For example, using > on the wrong filename can destroy existing content. Practice redirection only with disposable files and understand the difference between writing a new file and appending to one.

8. grep — search for a known pattern

grep searches input for lines matching a pattern. -n includes line numbers and -i performs case-insensitive matching. It is useful for finding an error term inside a small log or discovering which of several sample files contains an expected setting.

grep -n 'ERROR' sample.log
grep -ni 'timeout' sample.log

Patterns are not always literal strings: default regular-expression behavior gives some characters special meaning. If you want a fixed text search, use grep -F. A search returning no matches does not establish that an application is healthy; it only says those input lines did not match that particular search expression.

Do not pipe sensitive logs into third-party tools or upload them for troubleshooting without reviewing names, tokens, internal addresses and personal data. Local search is often safer and faster for an initial investigation.

9. find — locate files using explicit conditions

find walks a directory tree and tests each entry against conditions such as name, type or modification time. It can be more precise than a large listing when you are looking for a known class of files rather than every directory entry.

find ./reports -type f -name '*.txt'

The quoted wildcard is important. If the shell expands *.txt before find receives it, the result can change or the command may fail unexpectedly. This read-only example finds regular text files in the practice reporting directory. Production administrators should test a search’s output carefully before adding an action that deletes or changes every match.

Symbolic links, permissions and mount points may affect how a traversal behaves. When running a large search on a production server, restrict the starting directories and consider the filesystem I/O cost.

10. chmod — understand and adjust permissions

chmod changes filesystem mode bits where the operating system and permissions allow it. A practical beginner example is adding read and write permission for the file’s owner. This is safer to teach than broadly enabling access for every user or making every downloaded file executable.

chmod u+rw notes.txt
ls -l notes.txt

The example affects only the specified file’s owner permission bits; it does not change file ownership, ACLs, mandatory access controls or the security model of an entire application. Before altering a shared or system-managed file, establish what access it should have and which service accounts depend on it. Do not use permissive modes as a quick substitute for debugging ownership or group membership.

Understand quoting, expansions and safe practice

The shell’s power comes from more than individual utilities. It expands variables and wildcards, handles redirection and pipes, runs command substitutions, and decides how words are passed as arguments. Small quoting errors can change the targets of a command. For paths and ordinary variables, double quotes commonly preserve a value as one argument while still allowing variable expansion; single quotes prevent most expansions. The official GNU Bash quoting explanation describes the exact rules.

Use a deliberate practice sequence. Create disposable notes and logs inside $HOME/bash-practice, confirm the directory with pwd, list content, make one copy, rename it, search its text, and inspect permissions. For each operation predict its output and verify the actual result. This teaches not only commands but the assumptions you will eventually need to defend in a script review.

On a managed machine, escalate privileges only for an approved administrative task and understand what the command is going to change. The Bash reference manual provides complete language semantics, including expansions, redirections and error handling. A useful beginner becomes a safer operator by checking paths and arguments, not by using the shortest or most destructive command possible.

Filed under Infrastructure & Systems