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/ashals: 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 2Mcd: Change Folder
cd documents # enter a folder
cd .. # go up one level
cd ~ # go to the home folder
cd - # jump back to the previous folderCreate 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 togetherCopy, 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 fileThe 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 contentsThe 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 linesThe 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 programUseful Shortcuts
| Shortcut | Action |
|---|---|
| Tab | Complete file and command names |
| Up Arrow | Recall the previous command |
| Ctrl+C | Stop the running command |
| Ctrl+L | Clear the screen |
| Ctrl+R | Search command history |
| Ctrl+A / Ctrl+E | Jump 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 practiceThe final ls shows one.txt, second.txt, and three.txt.
Key Takeaways
pwd,ls, andcdhandle navigation.mkdirandtouchcreate folders and files.cp,mv, andrmcopy, move, and delete.cat,head,tail, andlessread content.- The Tab key saves typing and prevents spelling mistakes.
