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

Moving, renaming and deleting in Linux: mv, rm, rmdir, ls -l and hidden files

Let's start. We can make files and folders, and we can copy them. On a laptop the other everyday jobs are cut-paste, rename and delete. On a server, two commands do all three: mv moves and renames, rm deletes. Today we also learn to tell a file from a folder without guessing, how to hide a file with a dot, and what the mysterious . and .. are. Keep your server running and type every command with me.

What you will learn in this class

  • Today's practice folders, and the real prompt after cd
  • An interview question: copy only what is inside a folder
  • mv = cut-paste: four ways to move a file into a folder
  • Renaming with mv, in the same folder and inside a subfolder
  • Moving folders, and why mv needs no -r (same disk vs across disks)
  • Wildcards with mv, and the silent overwrite (mv -i)
  • Deleting: rm, rm -r, rmdir and rm -i
  • Practice task: mv, cp and rm on one tree
  • Working smart: relative paths, braces and Tab
  • File or folder? Why names and colours don't decide
  • ls -l: the first character
  • The command summary
  • Hidden files, ls -a, and the entries . and ..
  • Before you leave: terminate or stop
  • Try-at-home tasks

1. Today's practice folders

Why. Moving and deleting need something to move and delete. Build these first. Copying is in Copying in Linux: cp, cp -r, wildcards (* ?) and brace ranges; paths are in Linux directories and paths.

How (start in your home folder). Run these lines one by one:

cd
mkdir ravi raj
cd ravi
touch 1.txt 2.logs 3.mp3
mkdir one two three
cd

Classroom line

Say we're in ec2-user's home, and I've made two folders there: one called ravi, one called raj.

Watch the prompt. It always tells you where you are. On Amazon Linux 2023 it looks like this (the ip-... part is your server's private hostname):

[ec2-user@ip-172-31-xx-xx ~]$ cd ravi
[ec2-user@ip-172-31-xx-xx ravi]$ cd
[ec2-user@ip-172-31-xx-xx ~]$
  1. ~ means you are in your home, /home/ec2-user.
  2. After cd ravi the prompt shows ravi, the name of the current folder.
  3. After cd alone, you are home again and ~ comes back.

Correction

On the board, every line after cd ravi was still written with ~]. The real prompt changes with you: it shows the name of the folder you are in, here ravi. Check it after every cd, or run pwd.

2. Interview question: copy only what is inside a folder

Why. "Copy the contents of ravi into raj, not the folder itself" is a favourite interview question. It tests whether you really understand cp -r.

Classroom line

And they ask this question in interviews.

Three tries (from your home folder):

  1. cp ravi raj → cp: -r not specified; omitting directory 'ravi'. A folder needs -r.
  2. cp -r ravi raj → works, but you get raj/ravi/...: the folder itself went inside raj.
  3. cp -r ravi/* raj → raj/1.txt, raj/2.logs, raj/3.mp3, raj/one... Only the contents. This is the answer they expect.

ravi/* means "every name inside ravi". The shell expands it before cp runs, so cp sees ravi/1.txt ravi/2.logs ravi/3.mp3 ravi/one ravi/three ravi/two raj.

The catch: hidden files. * doesn't match names that start with a dot (section 18). Make one and try again:

touch ravi/.notes
rm -r raj/*
cp -r ravi/* raj
ls -A raj

.notes is missing. To copy everything, hidden files included, copy the folder's own .:

cp -r ravi/. raj
Copy the folder, or only what is inside it? ravi contains: 1.txt 2.logs 3.mp3 one/ and a hidden file .notes $ cp -r ravi raj raj/ └── ravi/ ├── .notes ├── 1.txt ├── 2.logs ├── 3.mp3 └── one/ the folder itself goes inside raj $ cp -r ravi/* raj raj/ ├── 1.txt ├── 2.logs ├── 3.mp3 └── one/ .notes is NOT copied contents only; * skips hidden files $ cp -r ravi/. raj raj/ ├── .notes ├── 1.txt ├── 2.logs ├── 3.mp3 └── one/ all the contents, hidden files too $ cp ravi rajcp: -r not specified; omitting directory 'ravi' ravi/* = every visible name inside ravi. ravi/. = the folder ravi itself, seen from inside, so everything in it.

Figure 1. cp -r ravi raj puts the folder itself inside raj. cp -r ravi/* raj copies only the contents but skips the hidden file .notes. cp -r ravi/. raj copies all the contents, hidden files too.

Correction

The class answer cp -r ravi/* raj is right for normal files, but ravi/* skips hidden files (names that start with a dot). cp -r ravi/. raj copies everything inside ravi, hidden files included.

3. mv: cut-paste for Linux

Why. On Windows you cut a file and paste it somewhere else; the original is gone from the old place. Linux does the same with one command.

Classroom line

mv means cut-paste. The cut-paste we use in Windows is what we now do in Linux.

What. mv SOURCE DESTINATION, the same shape as cp. The difference: after mv, the source is gone from where it was.

How: four ways to move my.txt into ravi. Make the file first with touch my.txt in your home. Each line moves it away, so run touch my.txt again before trying the next one:

  1. mv my.txt ravi → ravi/my.txt
  2. mv my.txt ravi/ → the same; Tab adds the slash for you.
  3. mv my.txt ravi/my.txt → the same, with the name written out.
  4. mv my.txt ravi/you.txt → moved and renamed: ravi/you.txt.

Check each time: ls (my.txt is gone from home) and ls ravi (it's there).

Handwritten board: a prompt with mv my.txt ravi, with source written under my.txt and destination under ravi; below it three lines mv my.txt ravi/, mv my.txt ravi/my.txt and mv my.txt ravi/you.txt.

From the class board: mv my.txt ravi: my.txt is the source, ravi the destination. Then the three other ways: mv my.txt ravi/, mv my.txt ravi/my.txt, and mv my.txt ravi/you.txt, which also renames the file.

4. Renaming with mv

Why. Linux has no separate rename command for everyday use. Renaming is just moving a file to a new name in the same place.

Classroom line

mv is also the command for renaming.

How:

  1. touch my.txt
  2. mv my.txt our.txt
  3. ls → our.txt (and no my.txt)

How mv decides:

  1. Destination is an existing folder → the item moves inside it.
  2. Destination doesn't exist → the item gets that name (rename).
  3. Destination is the same as the source → nothing to do.

Try it:

mv my.txt my.txt
mv: 'my.txt' and 'my.txt' are the same file
One command, four jobs: mv $ mv my.txt ravibefore~/├── my.txt└── ravi/mvafter~/└── ravi/ └── my.txt1. Move: ravi is a folder, so my.txt goes inside it. Nothing stays behind. $ mv my.txt our.txtbefore~/└── my.txtmvafter~/└── our.txt2. Rename: our.txt does not exist, so my.txt just gets the new name. $ mv my.txt ravi/you.txtbefore~/├── my.txt└── ravi/mvafter~/└── ravi/ └── you.txt3. Move and rename in one step. $ mv ravi onebefore~/├── one/└── ravi/ └── 1.txtmvafter~/└── one/ └── ravi/ └── 1.txt4. Move a folder: everything inside goes with it. No -r needed. Rule: if the destination is an existing folder, mv puts the item inside it. Otherwise the destination is the new name.

Figure 2. Animation: mv my.txt ravi moves the file into ravi; mv my.txt our.txt renames it; mv my.txt ravi/you.txt moves and renames; mv ravi one moves a whole folder, without -r.

5. Renaming inside a subfolder, without going there

Why. You don't have to cd into a folder to rename something in it. Give both names as paths.

How (you stay in /home/ec2-user):

  1. mv ravi/1.txt ravi/2.txt
  2. ls ravi → 2.txt is there, 1.txt is gone.

Both paths point into the same folder, so it's a rename. If the second path pointed into another folder, it would be a move and rename.

Handwritten board: a prompt with mv my.txt our.txt; on the right a small tree ec2-user, ravi, 1.txt; below, a prompt with mv ravi/1.txt ravi/2.txt and a line mv ravi one.

From the class board: mv my.txt our.txt renames in the same folder. With the tree ec2-user, ravi, 1.txt on the right: mv ravi/1.txt ravi/2.txt renames a file inside ravi without leaving home, and mv ravi one moves the folder ravi into one.

6. Moving folders: no -r

Why. With cp, a folder needs -r. With mv, it doesn't. Good to know before an interviewer asks "why?".

How:

  1. mkdir one (in your home; ravi already exists)
  2. mv ravi one
  3. ls one → ravi, with everything that was inside it.

To bring it back: mv one/ravi . (. = here).

Correction

In class the option was read out as "slash r". It's dash r: a hyphen, -r. The board had it right. A slash is the path separator, as in ravi/1.txt.

7. Why mv needs no -r

Why. Understanding this explains why mv of a huge folder takes no time at all, while cp of the same folder can take minutes.

Classroom line

When we move, what really happens? Only the path changes. But when we copy, the file is actually stored again.

What happens on the same disk:

  1. A file's data sits in blocks on the disk.
  2. The folder only keeps an entry: the name, and where the data is.
  3. cp writes the data again into new blocks, file by file. For a folder it has to go inside every folder: that's what -r asks for.
  4. mv leaves the data alone and only changes the entry: the old name goes, the new path appears. A folder moves as a whole, in one step, so there is nothing to recurse into.

Across disks (for example from the root volume to a second EBS volume), an entry can't point to another disk. So mv copies the data to the other disk, then deletes the original. It takes as long as a copy, and it still needs no -r.

Why mv is instant and needs no -r (same disk) $ cp my.txt ravi $ mv my.txt ravi disk blocksfolder entries: name → where the data ismy.txt→ blocks 1-3disk blocksfolder entries: name → where the data ismy.txt→ blocks 1-3 disk blocksfolder entries: name → where the data ismy.txt→ blocks 1-3ravi/my.txt→ blocks 6-8disk blocksfolder entries: name → where the data isravi/my.txt→ blocks 1-3 the data is written again, file by file;for a folder, -r tells cp to go inside no data is touched, only the nameentry changes, so a folder moves as a whole Across disks (for example to a second EBS volume) mv copies the data, then deletes the original. Still no -r.

Figure 3. Animation: cp my.txt ravi writes the data again into new blocks and adds a second entry. mv my.txt ravi on the same disk leaves the blocks alone and only changes the entry to ravi/my.txt. Across disks, mv copies, then deletes.

One move mv refuses, for the same reason as cp in the last chapter. Make one/two with mkdir -p one/two, then try:

mv one one/two
mv: cannot move 'one' to a subdirectory of itself, 'one/two/one'

Correction

The board drew this with "memory" boxes. To be precise, it's the disk: on the same disk (filesystem), mv only renames the directory entry, so no data is copied. Across disks it copies and then deletes. Either way, no -r is needed.

8. Wildcards with mv

Why. Same as with cp: describe a pattern instead of typing every name.

Classroom line

We can use wildcards while moving files or folders too.

How:

  1. mv *.txt ravi → every name ending in .txt goes into ravi.
  2. mv 2.* ravi → 2.logs and anything else starting with 2..
  3. Preview first: echo *.txt shows what the pattern picks, without moving anything.

The * and ? rules are in the copy chapter.

9. mv overwrites without asking: mv -i

Why. If the destination file already exists, mv replaces it. No question, no message, and the old file is gone.

See it happen:

echo old > b.txt
echo new > a.txt
mv a.txt b.txt
cat b.txt

Output: new. The old b.txt is lost, and a.txt no longer exists.

The safe way: mv -i asks first:

mv -i a.txt b.txt
mv: overwrite 'b.txt'?

Type y to replace, n to keep b.txt.

Ravindra Bagale's Tip

When you move files into a folder that already has files, use mv -i. One n can save a file you can't get back.

10. rm: deleting files

Why. Old logs, test files, mistakes. Servers fill up, and a full disk stops everything.

How:

  1. rm my.txt → one file.
  2. rm 1.txt my.mp3 3.logs → several files at once.
  3. rm *.txt → every .txt file here.
  4. rm file* → every name that starts with file.
Handwritten board: four lines, rm my.txt with a tick, rm 1.txt my.mp3 3.logs, rm *.txt, and rm file*.

From the class board: rm my.txt deletes one file, rm 1.txt my.mp3 3.logs deletes three, rm *.txt every name ending in .txt, and rm file* every name starting with file.

Things to know:

  1. There is no recycle bin. Deleted means gone.
  2. For ec2-user, rm doesn't ask before deleting.
  3. A name that doesn't exist: rm: cannot remove 'nothere': No such file or directory.
  4. A folder isn't deleted by plain rm.

Try it on a folder:

rm ravi
rm: cannot remove 'ravi': Is a directory

11. rm -r: deleting a folder and everything in it

What. rm -r ravi deletes the folder ravi, every file in it, every folder in it, all the way down. -r = recursive, the same idea as cp -r.

How:

  1. rm -r ravi
  2. ls → ravi is gone.

Ask before each delete:

rm -i my.txt
rm: remove regular empty file 'my.txt'?

For a folder, combine it with -r:

rm -ri ravi
rm: descend into directory 'ravi'?

rm -ri asks for every file and folder inside, one by one. Answer n at any point to keep that item.

Correction

In class it was said that rm -r on a single file wastes CPU and RAM. It doesn't; the difference is too small to notice. The real reason not to type -r out of habit is safety: with -r, one wrong name deletes a whole folder instead of failing with Is a directory. Use plain rm for files, rm -r only when you mean a folder, and rm -i when in doubt.

Ravindra Bagale's Tip

Before rm with a wildcard, run ls with the same pattern: ls *.txt, then rm *.txt. You see exactly what will go. And read any rm -r line twice before pressing Enter. More on this in 3.3 Working with files and directories.

12. rmdir: deleting only empty folders

Why. rmdir is a safety net. It refuses to delete a folder that still has something inside.

How:

  1. mkdir empty
  2. rmdir empty → gone, no message.
  3. rmdir my.txt → rmdir: failed to remove 'my.txt': Not a directory

Now a folder with files inside:

rmdir ravi
rmdir: failed to remove 'ravi': Directory not empty
Which delete command works on what a file an empty folder a folder with files rm deleted Is a directory Is a directory rmdir Not a directory deleted Directory not empty rm -r works, but risky habit deleted everything inside gone Red boxes show the real error text. There is no recycle bin: deleted means gone.Add -i to be asked before each delete: rm -i, rm -ri.

Figure 4. rm deletes files but says Is a directory for folders. rmdir deletes only empty folders and says Not a directory or Directory not empty otherwise. rm -r deletes anything, including a folder with everything inside.

Which one to use:

  1. A file → rm
  2. An empty folder → rmdir
  3. A folder with things inside → rm -r (and think twice)

13. Practice task: mv, cp and rm on one tree

The task. Do everything from /home/ec2-user; don't cd anywhere.

  1. Make a folder projects, inside it web, and inside web four folders: frontend, backend, database, testing.
  2. Make two files, notes.txt and report.txt, inside web, next to the four folders.
  3. Move notes.txt into backend.
  4. Move report.txt into database.
  5. Copy report.txt from database into testing.
  6. Delete report.txt from database.
  7. End state: notes.txt only in backend, report.txt only in testing.

Classroom line

Do all the work while staying in ec2-user's home.

Classroom line

We have to use all the commands: cp, mv, rm.

Try it yourself before reading on.

Solution:

cd
mkdir -p projects/web/{frontend,backend,database,testing}
touch projects/web/{notes.txt,report.txt}
mv projects/web/notes.txt projects/web/backend
mv projects/web/report.txt projects/web/database
cp projects/web/database/report.txt projects/web/testing
rm projects/web/database/report.txt

Check with tree projects:

projects
└── web
    ├── backend
    │   └── notes.txt
    ├── database
    ├── frontend
    └── testing
        └── report.txt

6 directories, 2 files
Practice task: mv, cp and rm on one tree projectsweb frontend backend database testing # start: both files sit in web, next to the four foldersnotes.txtreport.txtstep 0 / 4 $ mv projects/web/notes.txt projects/web/backendnotes.txtreport.txtstep 1 / 4 $ mv projects/web/report.txt projects/web/databasenotes.txtreport.txtstep 2 / 4 $ cp projects/web/database/report.txt projects/web/testingnotes.txtreport.txtreport.txtstep 3 / 4 $ rm projects/web/database/report.txtnotes.txtreport.txtstep 4 / 4 End state: notes.txt only in backend, report.txt only in testing. Every command runs from /home/ec2-user.

Figure 5. Animation: notes.txt is moved into backend, report.txt into database, report.txt is copied to testing, and the copy in database is removed. End state: notes.txt in backend, report.txt in testing.

Why stay in your home? ec2-user may only write inside its own home (and a few places like /tmp). Outside it you get:

mkdir /projects
mkdir: cannot create directory ‘/projects’: Permission denied

14. Working smart: relative paths, braces and Tab

Why. In an interview task, the person who finishes first, correctly, wins. Typing less also means fewer typos.

  1. Relative paths. You're already in /home/ec2-user. Write projects/web/backend, not /home/ec2-user/projects/web/backend.
  2. Braces. One line makes many names: mkdir -p projects/web/{frontend,backend,database,testing}.
  3. Tab. Type projects/w and press Tab; the shell completes web/. Fewer keys, no spelling mistakes.

Classroom line

You're already in ec2-user, so why are you typing the path from the very start?

Classroom line

When you need many files in one place: curly braces.

15. File or folder? Names and colours don't decide

Why. Before you rm or rmdir, you must know which one you have. Guessing from the name doesn't work.

Names don't decide:

  1. touch report → a file called report, no extension needed.
  2. mkdir photos.txt → a folder, even though its name ends in .txt.

Colours don't decide either. In ls, folders often show in blue and files in white, but that's only a display setting. The colours come from the LS_COLORS variable, which a startup script fills in (with the dircolors command) when you log in. Change the setting, use another terminal, or pipe the output, and the colours change or disappear.

What does decide: ask Linux.

  1. ls -F → folders get a / at the end: photos.txt/ report
  2. ls -l → the first character (next section).

Correction

In class the colour settings were said to come from a ".dash profile" file. The colour rules come from LS_COLORS (set up by dircolors), usually loaded through startup files such as ~/.bashrc or ~/.bash_profile. Either way, colour is a display choice, not the file type.

16. ls -l: the first character

Why. ls -l (long listing) is the reliable way to see what something is, who owns it and when it changed.

How. In a folder with one empty file my.txt and one empty folder ravi:

[ec2-user@ip-172-31-xx-xx ~]$ ls -l
total 0
-rw-r--r--. 1 ec2-user ec2-user 0 Jan  5 10:15 my.txt
drwxr-xr-x. 2 ec2-user ec2-user 6 Jan  5 10:15 ravi

Read it column by column:

  1. First character: - = a regular file, d = a directory.
  2. rw-r--r--: permissions (read, write, execute). That's the next topic.
  3. .: an SELinux label is attached (Amazon Linux uses SELinux).
  4. 1 / 2: the number of links. A folder has at least 2: its name, and its own ..
  5. ec2-user ec2-user: the owner and the group.
  6. 0 / 6: the size in bytes. A folder's size is the size of its own list of names, not of what's inside. On Amazon Linux (XFS) a small folder shows a small number like 6; on other systems you'll often see 4096.
  7. Jan 5 10:15: last modified.
  8. The name.

Classroom line

The very first character tells us whether it's a file or a directory.

Handwritten board: ls -l at the top; two lines, one starting with a boxed dash and rw- r-- r--, the other with a boxed d and rwx r-x r-x; ec2-user ec2-user on each line; the names my.txt and ravi on the right.

From the class board: The board's simplified ls -l: the first character, boxed, is a dash for the file my.txt and d for the folder ravi, followed by the permissions and the owner and group ec2-user. The real output also shows links, size and time.

Reading ls -l: the first character says file or folder $ ls -ltotal 0 -d rw-r--r--rwxr-xr-x .. 12 ec2-userec2-user ec2-userec2-user 06 Jan 5 10:15Jan 5 10:15 my.txtravi type permissions SELinux links owner group size modified name -dash = a regular filetouch, cat, nano and vi make these dd = a directory (folder)mkdir makes these Permissions (r w x) are the next topic. A folder size is the size of its own list, not of its contents.

Figure 6. ls -l for a file and a folder, every column labelled: type, permissions, SELinux dot, links, owner, group, size, modified time and name. A dash means a file, d means a directory.

To see a folder's own line instead of its contents: ls -ld ravi.

Correction

The board showed a shortened ls -l line with only the type, permissions, owner, group and name. Above is the real output, with the link count, size and date too. The dates are examples.

17. The command summary

Job A file A folder
Copy cp cp -r
Move or rename mv mv (no -r)
Delete rm rmdir (empty only), rm -r (with everything inside)

Add -i to cp, mv or rm to be asked before anything is overwritten or deleted.

18. Hidden files: a dot at the start of the name

Why. Your home already has files you can't see with ls. Linux keeps its settings in them.

What. A name that starts with a dot is hidden from a normal ls. That's the whole rule.

How (from your home folder):

  1. touch notes.txt
  2. Hide it: mv notes.txt .notes.txt
  3. ls → it's not listed.
  4. ls -a → there it is, next to files that were hidden all along.

Your list will look something like this:

ls -a
.  ..  .bash_logout  .bash_profile  .bashrc  .notes.txt  .ssh  projects  raj  ravi

To unhide it, rename it back: mv .notes.txt notes.txt. Folders work the same way: mv ravi .ravi hides, mv .ravi ravi unhides.

ls -A is the same without . and ...

Hidden files: a name that starts with a dot $ mv notes.txt .notes.txt$ lsprojects ravi report.txt$ ls -a. .. .bash_logout .bash_profile .bashrc .notes.txt .ssh projects ravi report.txt Hide and unhide = renamemv notes.txt .notes.txt (hide)mv .notes.txt notes.txt (unhide)mv ravi .ravi (folders too) Hidden is not secretanyone who types ls -a sees it.To protect a file, use permissions.The dot only keeps ls output tidy. Linux hides its own settings this way: .bashrc, .bash_profile, .ssh. ravi/* skips dot-names too.

Figure 7. mv notes.txt .notes.txt hides the file from ls; ls -a shows it next to .bashrc, .bash_profile and .ssh. Renaming back unhides it. Hidden is not secret: anyone can run ls -a.

Real examples of hidden files:

  1. .bashrc, .bash_profile: your shell's settings.
  2. .ssh/: holds authorized_keys, the list of public keys allowed to log in as you.
  3. Remember section 2: ravi/* skips these. ravi/. doesn't.

Correction

In class, the dot was suggested as a way to hide files from people who don't know Linux. A dot only hides a name from a plain ls; anyone who types ls -a sees it. It is not security. To protect a file, use permissions (next topic).

19. The entries . and ..

What. ls -a shows two names in every folder, even a brand-new empty one:

  1. . = this folder itself.
  2. .. = the parent folder, one level up.

They are real entries in the folder's list, pointing to the folder and to its parent. That's why they work everywhere:

  1. cd .. → up one level.
  2. cd . → stay where you are.
  3. cp one/a.txt . → copy here.
  4. mv ravi/2.txt .. → move one level up.
Every folder has two built-in entries: . and .. / home ec2-user ravi one .= ravi ..= ec2-user ● you are in ravi $ cd ravi$ ls -a. .. 1.txt one$ cd .stays in ravi$ cp one/a.txt .copy here$ cd ..up to ec2-usereven a brand-new empty folder shows . and .. . points to the folder itself, .. to its parent. Like a chain:each folder knows where it is and where its parent is.

Figure 8. You are in ravi: . points to ravi itself, .. points to its parent ec2-user. ls -a shows . and .. in every folder, even an empty one.

Think of a chain: every folder knows where it is (.) and where its parent is (..), so you can always walk back up to /.

20. Before you leave: terminate or stop

At the end of class the instance was stopped and then terminated.

  1. Stop = switch off. The disk (EBS) stays; you can start it again later.
  2. Terminate = delete the server. By default the root EBS volume is deleted too. It can't be undone.
  3. You don't need to stop before terminating. Terminate shuts it down by itself.

Stop vs terminate, and what each costs, is in Inside an EC2 server: EBS, ENI, instance states, connecting with SSH, and what Linux is.

Correction

In class the instance was stopped first and then terminated. The stop isn't needed: terminate shuts the instance down by itself and deletes the root volume by default. Terminate only a server you no longer need; for practice servers you'll use again, stop is enough.

21. Try at home

Try at home

Task 1: contents only

  1. Make src with a.txt, b.txt and a hidden .env. Make an empty dst.
  2. Copy only the contents of src into dst with src/*. Check with ls -A dst. Is .env there?
  3. Empty dst (rm -r dst/*) and do it again with src/..

Task 2: mv

  1. touch my.txt, then rename it to our.txt.
  2. Move our.txt into src and rename it to final.txt in one command.
  3. Rename src/final.txt to src/done.txt without leaving home.
  4. mkdir box and move the whole src folder into box. Did you need -r?

Task 3: delete

  1. Try rmdir box. Read the error.
  2. Try rm box. Read the error.
  3. Delete it with rm -ri box; answer y to everything.

Task 4: look closely

  1. touch report and mkdir photos.txt. Run ls -l and ls -F. Which is the folder?
  2. Hide report with a dot, find it with ls -a, then unhide it.
  3. Redo the practice task (section 13) with your own folder names, from home, in as few commands as you can.

When you finish, stop the instance from the console, or terminate it if you won't use it again.

Recap

In short

  1. The prompt shows your current folder: [ec2-user@ip-... ravi]$. ~ means home.
  2. Contents only: cp -r ravi/* raj. With hidden files: cp -r ravi/. raj.
  3. mv SOURCE DESTINATION = cut-paste. Existing folder → moves inside; new name → rename.
  4. mv my.txt ravi/you.txt moves and renames in one step; mv ravi/1.txt ravi/2.txt renames without leaving home.
  5. mv needs no -r: on the same disk it only changes the name entry; across disks it copies, then deletes.
  6. mv overwrites silently; mv -i asks. Wildcards work: mv *.txt ravi.
  7. rm files, rmdir empty folders, rm -r folders with everything. No recycle bin.
  8. rm -r on a file is a safety risk, not a speed problem. Use rm -i / rm -ri when unsure.
  9. Work from home with relative paths, braces and Tab.
  10. Names and colours don't tell file from folder; ls -l (first character - or d) and ls -F do.
  11. Hidden = name starts with a dot. ls -a shows them. Hidden is not secret.
  12. Every folder has . (itself) and .. (its parent).
  13. Terminate needs no stop first, and it deletes the root volume by default.

Samjla ka? Ghari practice task parat kara, ani rm vaparnyaadhi don vela vichar kara.


Ravindra Bagale, trainer: linkedin.com/in/ravindra-bagale. The folder and file names (ravi, raj, projects, notes.txt, report.txt and the rest) are examples for learning. Command outputs and error messages were checked with GNU bash and coreutils, the same tools Amazon Linux 2023 uses; the hostname in the prompt and the dates in ls -l are illustrative.