Bash Basic Commands

Basic commands are the daily tools of every terminal user. They move between folders, create files, copy data, and show information. Every script in this course builds on them, so a firm grip on these commands makes all later topics easier.

Know Where You Are

A terminal always sits inside one folder, called the current working folder. Think of it as the room you stand in while inside a large house.

  /home
    |
    +-- asha
         |
         +-- documents
         |      +-- notes.txt
         +-- scripts
                +-- hello.sh

pwd: Print Working Folder

pwd
/home/asha

ls: List Contents

ls            # names only
ls -l         # details such as size and date
ls -a         # include hidden files
ls -lh        # readable sizes like 4K and 2M

cd: Change Folder

cd documents    # enter a folder
cd ..           # go up one level
cd ~            # go to the home folder
cd -            # jump back to the previous folder

Create Folders and Files

mkdir projects            # new folder
mkdir -p work/2026/reports  # nested folders in one step
touch notes.txt           # new empty file
touch a.txt b.txt c.txt   # several files together

Copy, Move, and Rename

cp notes.txt backup.txt        # copy a file
cp -r projects projects_old    # copy a folder
mv backup.txt archive/         # move a file
mv notes.txt diary.txt         # rename a file

The mv command handles both moving and renaming. A new name in the same folder means a rename. A different folder means a move.

Delete With Care

rm old.txt          # delete a file
rm -i old.txt       # ask before deleting
rmdir empty_folder  # delete an empty folder
rm -r old_folder    # delete a folder and its contents

The terminal has no recycle bin. A deleted file is gone for good. The -i flag adds a safety question and suits beginners.

View File Content

cat notes.txt        # show the whole file
head -n 3 notes.txt  # first three lines
tail -n 3 notes.txt  # last three lines
less notes.txt       # scroll page by page (press q to quit)
wc -l notes.txt      # count lines

The command tail -f app.log keeps showing new lines as they arrive, which helps when watching a live log.

Get Help

man ls          # full manual page
ls --help       # short summary
type cd         # shows whether a command is built in
which bash      # shows the file location of a program

Useful Shortcuts

ShortcutAction
TabComplete file and command names
Up ArrowRecall the previous command
Ctrl+CStop the running command
Ctrl+LClear the screen
Ctrl+RSearch command history
Ctrl+A / Ctrl+EJump to line start or end

Practice Session

Type the commands below one at a time and watch each result:

mkdir practice
cd practice
touch one.txt two.txt
ls
cp one.txt three.txt
mv two.txt second.txt
ls
cd ..
rm -r practice

The final ls shows one.txt, second.txt, and three.txt.

Key Takeaways

  • pwd, ls, and cd handle navigation.
  • mkdir and touch create folders and files.
  • cp, mv, and rm copy, move, and delete.
  • cat, head, tail, and less read content.
  • The Tab key saves typing and prevents spelling mistakes.