Ravindra BagaleCourses & study guides मराठी Track your progress

Linux files: touch, cat, nano, vi, brace shortcuts, ls -R and tree

Let's start. Last class we learned to walk around the server: pwd, ls, mkdir, cd, and absolute, relative and ~ paths. Folders are only boxes, though. The real work on a server happens inside files: settings, web pages, scripts, logs. Today we make files four different ways, write in them, read them, add to them and edit them. We also learn a shortcut that builds a whole family tree of folders in one line. Keep your server running and type every command with me.

What you will learn in this class

  • A one-minute recap of directories and paths
  • Building a folder tree (the Ramayan example), step by step and in one line
  • The brace shortcut {a,b,c}, and why -p matters
  • Four ways to make a file: touch, cat, nano, vi
  • touch: empty files, and its real job (the timestamp)
  • Dots and extensions: why photo.jpg is just a name
  • Why anyone would want an empty file
  • One name, one item; capital letters count
  • cat: write with >, read, append with >>, and finish with Ctrl+D
  • nano: the easiest editor, and how to save and exit
  • File names with spaces, and opening several files
  • Practice task: the calendar, in the fewest commands
  • ls -R and tree
  • Every command is a small program
  • vi: modes, i a o, Esc, :wq and :q!
  • Try-at-home tasks

1. One-minute recap: directories and paths

Why. Everything today builds on last class. If any line below feels new, read Linux directories and paths: pwd, ls, mkdir, cd, absolute vs relative paths and ~ first.

What you should already know:

Command What it does
ls list what is here
ls -r the same list in reverse order (small r)
mkdir ravi raja rani three folders at once
mkdir 'ravicha folder' one folder whose name has a space
mkdir -p one/two/three nested folders, parents made for you
cd one/two/three go down several levels
cd .., cd ../.., cd ../../.. up one, two, three levels
cd - back to the previous folder
cd home (/home/ec2-user)
cd /home/ec2-user/ravi jump anywhere with an absolute path

Keep ls -r (small r, reverse) apart from ls -R (capital R, recursive). We meet ls -R in section 14.

2. Assignment: build the Ramayan tree

Why. Real projects are trees: a website folder with css, images and js inside; an app with logs and config. You must be able to turn a drawing into folders.

The task. In your home folder, make this tree: Ramayan, inside it Dasarath, and inside Dasarath four folders: Ram, Laxman, Bharat, Shatrughna.

Handwritten board: a box Ramayan, an arrow down to a box Dasarath, and four boxes under Dasarath: RAM, Laxman, Bharat and Shatrughna.

From the class board: The assignment: Ramayan at the top, Dasarath inside it, and four folders inside Dasarath: Ram, Laxman, Bharat and Shatrughna.

How, step by step (from ~):

  1. cd (make sure you are home).
  2. mkdir Ramayan
  3. mkdir Ramayan/Dasarath
  4. mkdir Ramayan/Dasarath/Ram
  5. mkdir Ramayan/Dasarath/Laxman
  6. mkdir Ramayan/Dasarath/Bharat
  7. mkdir Ramayan/Dasarath/Shatrughna
  8. Check: ls Ramayan/Dasarath → Bharat Laxman Ram Shatrughna

Each step only works because the step before it made the parent. That is the whole idea of a path: you can't put a folder inside a folder that doesn't exist yet.

The same thing in one line (long version):

mkdir -p Ramayan/Dasarath/Ram Ramayan/Dasarath/Laxman Ramayan/Dasarath/Bharat Ramayan/Dasarath/Shatrughna
  1. Four paths, separated by spaces, so four folders.
  2. -p makes Ramayan and Ramayan/Dasarath on the way, if they are missing.

Correction

In class the one-line version was typed without -p. That only works if Ramayan/Dasarath already exists from the earlier steps. On a fresh start, plain mkdir stops with mkdir: cannot create directory ‘Ramayan/Dasarath/Ram’: No such file or directory. Add -p and it works from nothing.

3. The brace shortcut: {a,b,c}

Why. The long line above repeats Ramayan/Dasarath/ four times. More typing means more typos.

What. Write the common part once, and put the different names in curly braces, separated by commas:

mkdir -p Ramayan/Dasarath/{Ram,Laxman,Bharat,Shatrughna}
  1. Ramayan/Dasarath/ is the common path.
  2. {Ram,Laxman,Bharat,Shatrughna} is the list of names.
  3. Commas between names, and no spaces anywhere inside the braces.
  4. Before mkdir even starts, the shell (bash) expands the line into the four full paths. mkdir receives the long version.
Handwritten board with three prompt lines: mkdir Ramayan; mkdir Ramayan/Dasarath; mkdir Ramayan/Dasarath/ followed by curly braces around RAM, Laxman, Bharat, Shatrughna separated by commas.

From the class board: mkdir Ramayan, then mkdir Ramayan/Dasarath, then the four children in one line with braces. Because the first two lines already made the parents, the third line works without -p.

Braces: the shell turns one line into many paths mkdir -p Ramayan/Dasarath/{Ram,Laxman,Bharat,Shatrughna} blue = the common path, written onceorange = the names, comma-separated, no spaces before mkdir runs, bash expands it to: mkdir -p Ramayan/Dasarath/Ram Ramayan/Dasarath/Laxman Ramayan/Dasarath/Bharat Ramayan/Dasarath/Shatrughna RamayanDasarath Ram Laxman Bharat Shatrughna -p also makes Ramayan and Dasarath if they are missing mkdir -p Ramayan/Dasarath/{Ram, Laxman}a space after the comma breaks it: you get a folder named {Ram, and a folder Laxman} in the current folder Preview any brace line first with echo: echo Ramayan/Dasarath/{Ram,Laxman}

Figure 1. Animation: bash expands Ramayan/Dasarath/{Ram,Laxman,Bharat,Shatrughna} into four paths before mkdir runs, and the four folders appear. A space after a comma breaks the expansion.

See the expansion yourself. echo prints what the shell will hand to the command, without creating anything:

  1. echo Ramayan/Dasarath/{Ram,Laxman} → Ramayan/Dasarath/Ram Ramayan/Dasarath/Laxman
  2. echo file{1,2,3}.txt → file1.txt file2.txt file3.txt

Worked example: a website skeleton.

  1. mkdir -p mysite/{css,images,js}
  2. ls mysite → css images js

Correction

Two details from the board. First, -p: without it the brace line fails if Ramayan/Dasarath doesn't exist yet (on the board it worked because the two lines above had already made them). Second, spaces: {Ram, Laxman} with a space is not expanded. The shell sees two separate words, Ramayan/Dasarath/{Ram, and Laxman}, and you end up with strangely named folders. Keep braces tight: {Ram,Laxman}.

4. Files: four ways to make one

Why. Up to now we only made folders. A folder is an empty box until you put files in it.

What. There are four common ways to create a file:

  1. touch: makes an empty file.
  2. cat: makes a file and lets you type lines into it.
  3. nano: a simple editor, like Notepad inside the terminal.
  4. vi: a powerful editor found on every Linux server.

They differ in what else they can do after creating:

Four ways to make a file, and what each can do create write read modify append touch cat cat > f cat > f cat f cat >> f nano vi touch makes an empty file only. cat cannot change line 2 of a file; it can only add lines at the end.nano and vi are editors: they do everything.

Figure 2. touch can only create an empty file. cat can create, write, read and append, but not change a line in the middle. nano and vi can do everything.

Tool Create Write Read Modify Append
touch yes (empty) no no no no
cat yes (cat > f) yes (cat > f) yes (cat f) no yes (cat >> f)
nano yes yes yes yes yes
vi yes yes yes yes yes

"Modify" means changing something in the middle, for example turning hi on line 2 into bye. Only an editor can do that.

5. touch: empty files

What. touch followed by one or more names makes empty files.

How.

  1. cd (go home), then mkdir -p practice and cd practice.
  2. touch my.txt
  3. touch 1.txt 2.txt 3.txt (three files in one command)
  4. ls → 1.txt 2.txt 3.txt my.txt
  5. ls -l my.txt → -rw-r--r--. 1 ec2-user ec2-user 0 Jan 5 10:15 my.txt

The 0 before the date is the size in bytes: the file is empty. You can't write in it, read anything from it or edit it with touch. It only creates.

Its real job: the timestamp.

  1. Run ls -l my.txt and note the time, for example 10:15.
  2. Wait a minute, then touch my.txt again.
  3. ls -l my.txt → the time is now the current time, for example 10:20.
  4. The content (still empty here) is unchanged.
What touch really does 1. The file does not exist$ touch my.txta new, empty file is createdsize 0 bytestouch 1.txt 2.txt 3.txt makes three at once 2. The file already exists$ touch my.txtcontent stays exactly the same;only the modified time changes:before: ... 0 Jan 5 10:15 my.txtafter: ... 0 Jan 5 10:20 my.txtsee it with ls -l before and after The name comes from this: touch a file = mark it as just changed. Creating an empty file is the side job everyone uses.

Figure 3. If the file does not exist, touch creates an empty one. If it exists, touch leaves the content alone and only updates the modified time that ls -l shows.

Correction

In class touch was taught only as "the command that makes empty files". Its main job is to update a file's timestamp, as if you had just touched it. Creating the file when it's missing is a side effect, and it's the one everyone uses. Scripts and tools such as make use the timestamp to decide what is new.

6. Dots and extensions: just part of the name

Why. On Windows, .jpg means picture and .mp4 means video. In Linux, things work differently, and knowing how prevents confusion later.

What.

  1. A dot is just a character in a name. touch report.ppt photo.jpg song.mp4 makes three empty files.
  2. None of them is a real presentation, picture or song. They are empty, whatever the name says.
  3. Linux doesn't need an extension to know what's inside a file. The file command looks at the content:
    • file photo.jpg → photo.jpg: empty
    • echo hello > notes.jpg, then file notes.jpg → notes.jpg: ASCII text
  4. A name without any dot is fine too: touch ravi makes a file named ravi.

So why use extensions at all? They help people and programs:

  1. You see backup.sh and know it's a script.
  2. Nginx loads the settings files in its conf.d folder only if they end in .conf.
  3. A browser treats index.html as a web page.

Correction

In class this was described as "Linux has no extensions". Better: Linux doesn't need extensions, because it looks at the content. Extensions are still used everywhere as a convention, and some programs rely on them (like Nginx and .conf). Renaming a file to .jpg never turns it into a picture.

7. Why would anyone want an empty file?

Why ask. An empty file sounds useless. In real server work, it isn't.

Real uses:

  1. A log file a script will fill. You touch backup.log, then a scheduled script writes a line into it every night: "backup done at 12:00".
  2. A placeholder. You plan a website: touch index.html about.html contact.html. The structure is ready; you write the content later.
  3. A marker (flag) file. A script creates maintenance.on while it works; other scripts check whether that file exists and wait.
  4. Quick test files. Before you learn copying and deleting, you need something harmless to practise on: touch file1 file2 file3.

The idea from class still holds: servers are full of automation (start at 9 AM, stop in the evening, back up at noon, upload every 4 hours). Automation needs files to write into, and those often start empty.

Correction

In class the answer was "for automation", without a concrete link. To be precise: the empty file is a starting point that a script or a person fills in later, or a marker that other scripts check for. touch itself doesn't automate anything.

8. One name, one item; capital letters count

What.

  1. Inside one folder, a name can be used once: by a file or by a folder, not both.
  2. Linux names are case-sensitive: ravi, Ravi, rAvi and RAVI are four different names.

How it behaves (try it):

  1. mkdir ravi (a folder)
  2. touch ravi → no error, and no file appears. touch just updates the folder's time. ravi is still a folder.
  3. touch raju (a file), then mkdir raju → mkdir: cannot create directory ‘raju’: File exists
  4. touch Ravi RAVI → two new files. ls shows the folder ravi and the files Ravi and RAVI side by side.
Names in one folder: one name = one item A folder ravi existsravi$ touch ravino error, no new file:the folder's time is updatedit is still a folder A file ravi existsravi$ mkdir ravimkdir: cannot createdirectory ‘ravi’:File exists Capital letters count$ touch ravi Ravi RAVI ravi Ravi RAVI three different filesLinux names are case-sensitive Rule: inside one folder a name can be used once, by a file or by a folder. ravi, Ravi and RAVI are different names.

Figure 4. touch on an existing folder only updates its time; mkdir with the name of an existing file fails with File exists; ravi, Ravi and RAVI are three different names.

Classroom line

Inside one folder, a name can be used only once.

Correction

In class it was said that touch ravi fails when a folder ravi exists. It doesn't fail: it quietly updates the folder's timestamp and creates nothing. The opposite direction is the one that errors: mkdir ravi when a file ravi exists gives File exists. Either way the rule is the same: one name, one item.

Ravindra Bagale's Tip

Stick to small letters for file and folder names at work. Then you never have to remember whether it was Report, report or REPORT.

9. cat: writing a file with cat >

Why. touch can't put text in a file. cat can, without opening any editor.

What. cat > my.txt means "take what I type and write it into my.txt". The > sends the output into the file instead of the screen.

How.

  1. cat > my.txt
  2. The cursor waits on an empty line. There is no prompt: cat is listening.
  3. Type first line and press Enter.
  4. Type second line and press Enter.
  5. On the new empty line, press Ctrl+D. You are back at the prompt.
  6. Check: cat my.txt.

Ctrl+D means "end of input". Press it at the start of an empty line. In the middle of a line it only sends that line, so you would have to press Ctrl+D a second time.

Correction

In class cat > was finished with Ctrl+C. Ctrl+C interrupts (kills) the command. Lines you already ended with Enter usually survive, but anything typed on the last line, before Enter, is lost. The correct way is: press Enter on the last line, then Ctrl+D.

10. cat: reading, appending, and the > trap

Read. cat my.txt prints the whole file:

first line
second line

Append (add at the end).

  1. cat >> my.txt (two >)
  2. Type third line, press Enter, then Ctrl+D.
  3. cat my.txt → three lines. The old text stayed; the new line went below it.

The trap: a single > replaces everything.

  1. cat > my.txt
  2. Type new, Enter, Ctrl+D.
  3. cat my.txt → only new. The three old lines are gone.
cat: write with >, read, add with >> $ cat > my.txtwrite: type, Enter after each line first line⏎ second line⏎ [Ctrl+D]Ctrl+D on an empty line = finished $ cat my.txtread: prints the file first line second line $ cat >> my.txtappend: adds below the old text third line⏎ [Ctrl+D] $ cat > my.txtsingle > again: the file is emptied first! new⏎ [Ctrl+D] my.txt now contains: first linesecond line first linesecond linethird line newold lines are gone: > empties thesame file, then writes into it > = write (replace everything)>> = append (keep, add at the end)cat alone = readStuck in cat? Press Enter, then Ctrl+D.

Figure 5. Animation: cat > writes two lines, cat reads them, cat >> adds a third, and cat > again empties the file and leaves only the new line.

What cat can't do. In a five-line file, cat can't change line 2 from hi to bye. It can only replace the whole file (>) or add lines at the bottom (>>). To change a line in the middle, use an editor (sections 11 and 16).

Correction

In class cat > on an existing file was explained as "the old file is deleted and a new one is created". It isn't deleted: the same file is emptied (truncated) and then written again. Its permissions and owner stay the same. The effect you see is the same: the old content is gone.

Ravindra Bagale's Tip

Before you press Enter on a cat > command, look at the arrows once more. > replaces, >> adds. On a real server, one missing > can wipe a settings file. For reading big files without cat flooding your screen, see 3.4 Viewing files.

11. nano: the easiest editor

Why. cat can't edit a line in the middle. You need an editor, and nano is the friendliest one: it feels like Notepad.

What. nano my.txt opens the file in the editor. If it doesn't exist, nano starts a new, empty file and shows [ New File ] at the bottom.

How to edit.

  1. nano my.txt
  2. Move with the arrow keys. The mouse doesn't move the cursor by default.
  3. Type, delete with Backspace, change anything, anywhere.
  4. The bottom two lines list the shortcuts. ^ means Ctrl, so ^X is Ctrl+X.

Classroom line

nano is the easiest one.

How to save and exit.

  1. Press Ctrl+X.
  2. nano asks Save modified buffer?
  3. Press Y to save (N discards your changes, Ctrl+C cancels and takes you back to editing).
  4. nano shows File Name to Write: my.txt. Press Enter to keep the name.
  5. You are back at the prompt. Check with cat my.txt.

If you changed nothing, Ctrl+X exits straight away and asks nothing.

Leaving nano: Ctrl+X, then answer the question nano my.txttype with the keyboard Ctrl+X changed anything? noexits straight away yes Save modified buffer? Y Yes N No ^C Cancel Y → File Name to Write: my.txtpress Enter to keep the name N → exits without savingyour changes are lost Ctrl+C → cancelback to editing Tip: Ctrl+O then Enter saves and keeps you in nano. The shortcuts are listed at the bottom of the nano screen (^ means Ctrl).

Figure 6. Ctrl+X: if nothing changed, nano exits. If something changed, it asks Save modified buffer?: Y then Enter saves, N exits without saving, Ctrl+C goes back to editing.

Classroom line

If you didn't change anything, it exits directly; it asks only when you changed something.

Classroom line

From here on, our life is inside nano.

Ravindra Bagale's Tip

Ctrl+O then Enter saves without leaving nano. Use it while working on a long file, so a dropped SSH connection doesn't cost you your work. More nano and vim shortcuts are in 3.10 Text editors: nano and vim.

12. File names with spaces, and several files at once

What. A space separates arguments, for files exactly as for folders.

  1. nano my file opens two files, my and file, one after the other.
  2. nano 'my file' opens one file named my file. "my file" and my\ file work too.
  3. Turned into a feature: nano file1 file2 file3 opens three files. Ctrl+X closes the current one and moves to the next. Newer nano versions show which one you are on, for example [1/3].

Classroom line

When you use a space in a name, use single quotes... but better, simply use one single word.

Ravindra Bagale's Tip

Name files like my-file.txt or my_file.txt. No quotes, no backslashes, no surprises.

13. Practice task: the calendar, in the fewest commands

The task.

  1. In ~, create a folder calendar.
  2. Inside it, three folders: months, weeks, days.
  3. In months: files jan, feb, mar.
  4. Write January inside jan.
  5. In weeks: files week1, week2, week3.
  6. In days: files 1, 2, 3.
Handwritten board: a box calendar with three branches to boxes months, weeks and Days; under months the names jan, feb, march with an arrow from jan to the word January; under weeks week1 week2 week3; under Days 1 2 3.

From the class board: The calendar task: calendar contains months, weeks and days; months holds jan, feb and march, weeks holds week1 to week3, days holds 1 to 3, and jan contains the text January.

Try it yourself before reading on.

Solution (five commands):

  1. mkdir -p calendar/{months,weeks,days}
  2. touch calendar/months/{jan,feb,mar}
  3. touch calendar/weeks/{week1,week2,week3}
  4. touch calendar/days/{1,2,3}
  5. nano calendar/months/jan → type January → Ctrl+X, Y, Enter.

Check:

  1. cat calendar/months/jan → January
  2. ls calendar/weeks → week1 week2 week3
Handwritten board with four prompt lines: mkdir -p calendar/ followed by braces with months, weeks, Days; touch calendar/months/ with braces jan, feb, mar; touch calendar/weeks/ with braces week1, week2, week3; touch calendar/Days/ with braces 1, 2, 3.

From the class board: The solution: mkdir -p calendar/{months,weeks,Days}, then one touch line each for months, weeks and Days, all with braces. The board writes Days with a capital D; with the lower-case days used on this page, keep the same spelling in every command.

Common mistakes:

  1. Slashes inside the braces: {months/weeks/days} is one name with slashes, not three folders. Use commas.
  2. Spaces after the commas: {jan, feb, mar} isn't expanded (see section 3).
  3. Mixed case: the folder Days and a command with days are two different names.

Shorter still

touch accepts several brace groups in one command: touch calendar/months/{jan,feb,mar} calendar/weeks/{week1,week2,week3} calendar/days/{1,2,3}. And echo January > calendar/months/jan writes the word without opening nano. That makes it three commands in total.

14. ls -R: list everything inside

What. ls -R (capital R, recursive) lists a folder, then every folder inside it, then every folder inside those, and so on.

How.

  1. cd (home)
  2. ls -R calendar

Output:

calendar:
days  months  weeks

calendar/days:
1  2  3

calendar/months:
feb  jan  mar

calendar/weeks:
week1  week2  week3

Each block starts with a folder's path and a colon, followed by what's inside. It works for small trees; for big ones the output scrolls off the screen.

Don't confuse it with ls -r (small r), which only reverses the order of one listing.

15. tree: the picture view, and installing software

What. tree draws the same information as a picture. It isn't installed on Amazon Linux by default.

How to install it:

sudo yum install tree -y
  1. sudo: run this one command as the administrator (root). Installing software changes the system, so it needs admin rights.
  2. yum: the package manager. It downloads software from Amazon's repositories and installs it.
  3. install: the action.
  4. tree: the package name.
  5. -y: answer "yes" automatically to the "Is this ok?" question.

Then:

  1. tree calendar
  2. The output ends with 4 directories, 9 files.
Seeing a whole tree: ls -R and tree $ ls -R calendar calendar: days months weeks calendar/days: 1 2 3 calendar/months: feb jan mar calendar/weeks: week1 week2 week3 $ tree calendar calendar ├── days │ ├── 1 │ ├── 2 │ └── 3 ├── months │ ├── feb │ ├── jan │ └── mar └── weeks ├── week1 ├── week2 └── week3 4 directories, 9 files -R (capital) = recursive: every folder,one block each. Hard to read when big.ls -r (small) only reverses the order. tree draws the same thing as a picture. It is not installed by default: sudo yum install tree -y

Figure 7. ls -R lists each folder in its own block; tree draws the same calendar as a tree and ends with 4 directories, 9 files.

Every command is a small program.

  1. ls, mkdir, touch and cat are programs stored in /usr/bin. They come with Linux.
  2. tree is one more program; we installed it ourselves.
  3. Before installing, command -v tree prints nothing. After installing, it prints /usr/bin/tree.

Correction

In class it was said that "these are not commands, they are software". Both words are right: every command you type runs a small program. Some, like ls and mkdir, come pre-installed; others, like tree, we install with the package manager. On Amazon Linux 2023 the package manager is called dnf; yum still works as another name for it, so sudo yum install tree -y and sudo dnf install tree -y do the same thing. Package managers in detail: 3.7 Package managers.

16. vi: the editor on every server

Why. nano is friendly, but it isn't always installed. vi is on practically every Linux server, so you must at least know how to type, save and get out.

What. vi has modes:

  1. Command mode. vi opens here. Keys are commands, so stray key presses don't type into your file.
  2. Insert mode. Now keys type text. The bottom line shows -- INSERT --.

How.

  1. vi notes.txt
  2. Press i. The bottom shows -- INSERT --.
  3. Type your text. Use the arrow keys to move.
  4. Press Esc. You are back in command mode.
  5. Type :wq and press Enter: write (save) and quit.
  6. Check: cat notes.txt.

Three ways into insert mode:

Key Starts typing
i before the cursor (insert)
a after the cursor (append)
o on a new line below

To leave without saving: Esc, then :q! and Enter.

vi has modes: you type text only in insert mode Command modevi opens here; keys are commands(stray keys do not type) Insert mode-- INSERT --shown at the bottom; now you type i a o Esc : :wq ⏎write (save) and quit:q! ⏎quit without saving Keys to typeibefore cursoraafter cursoronew line belowStuck? Esc,then :q! ⏎ The orange box follows a normal edit: open → i → type → Esc → :wq → Enter.

Figure 8. Animation: vi opens in command mode; i, a or o switch to insert mode; Esc goes back; :wq saves and quits, :q! quits without saving.

Correction

In class s was listed with i and a as a key to start typing. s is not an insert key: it first deletes the character under the cursor and then lets you type in its place. To start typing without changing anything, use i, a or o.

Ravindra Bagale's Tip

Stuck in vi and nothing works? Press Esc twice, type :q!, press Enter. You are out, and nothing was saved. Then try again calmly.

17. Try at home

Try at home

Task 1: braces

  1. Make this tree in one command: school → class1, class2, class3, and inside each class divA and divB. (Hint: mkdir -p school/{class1,class2,class3}/{divA,divB}; preview it with echo first.)
  2. Check it with ls -R school.

Task 2: touch

  1. touch a.txt, then ls -l a.txt. Note the time.
  2. Wait a minute, touch a.txt again, ls -l a.txt. What changed?
  3. Make a folder test and try touch test. What happens?
  4. Make a file demo and try mkdir demo. Read the error.

Task 3: cat

  1. Write three lines into fruits.txt with cat >. Finish with Ctrl+D.
  2. Add two more with cat >>.
  3. Read it with cat.
  4. Run cat > fruits.txt once more, type one line, Ctrl+D. Read it again and explain what happened.

Task 4: editors

  1. Open fruits.txt in nano, change line 1, save with Ctrl+X, Y, Enter.
  2. Open it in vi, add a line at the bottom with o, save with :wq.
  3. Open it in vi again, change something, and leave with :q!. Check that the change was not saved.

Task 5: tree

  1. sudo yum install tree -y
  2. tree calendar and tree school.
  3. When you finish, stop the instance from the console.

Recap

In short

  1. Turn a drawing into folders step by step, or in one line with full paths and -p.
  2. Braces: mkdir -p Ramayan/Dasarath/{Ram,Laxman,Bharat,Shatrughna}. Commas, no spaces. The shell expands it; preview with echo.
  3. Four ways to make a file: touch, cat, nano, vi.
  4. touch makes empty files (size 0); on an existing file or folder it only updates the time.
  5. Extensions are just part of the name. Linux checks the content (file), but people and programs still use extensions.
  6. Empty files are useful: logs to be filled, placeholders, markers, practice files.
  7. One name = one item per folder. mkdir on an existing file's name → File exists. Capital letters count.
  8. cat > f writes (empties first), cat f reads, cat >> f appends. Finish typing with Enter, then Ctrl+D.
  9. cat can't change a line in the middle; editors can.
  10. nano: arrows to move; Ctrl+X, Y, Enter to save and exit; Ctrl+O to save and stay.
  11. Spaces split names: nano my file opens two files. Quote names, or better, avoid spaces.
  12. ls -R lists recursively; ls -r only reverses.
  13. sudo yum install tree -y installs tree; tree folder draws it.
  14. Every command is a small program; some come with Linux, others you install.
  15. vi: opens in command mode; i/a/o to type; Esc to stop; :wq save and quit; :q! quit without saving.

Samjla ka? Ghari tree install kara, vi madhe ek file lihun bagha. Pudhchya class madhe copy karayla shikuya.


Ravindra Bagale, trainer: linkedin.com/in/ravindra-bagale. The folder and file names (Ramayan, calendar, ravi, my.txt, photo.jpg, fruits.txt and the rest) are examples for learning. Command outputs were checked with GNU bash, coreutils, nano and tree, the same tools Amazon Linux 2023 uses; the time in ls -l examples is illustrative.