Alpine Linux: Delete Files or Directories

This post will guide you how to delete or remove files on your Alpine Linux. How do I remove directories under your Alpine Linux. How to quickly delete a file under a directory in Alpine Linux.

Delete a Files On Alpine Linux


You need to user the rm command to remove files on Alpine Linux . Assuming that you want to delete a file called alpinetmp.txt under /myfio directory, you just need to execute the rm command with the file name that you want to remove in command line interface of your Alpine Linux system.

Just do the following steps:

#1 open a termial or command line interface on your Alpine Linux
#2 type the following command to remove alpinetmp.txt file

$ rm alpinetmp.txt

Delete Multiple Files on Alpine Linux


If you want to remove multiple files on a directory, you can can use the rm command to achieve it. you just need to pass the file names to rm command and separated by space. For example, you want to delete two files under the /mylinux directory, type the following command:

$ rm myalpine1.txt myalpine2.txt

Note: before removing the files, you need to change the current directory to /mylinux directory. type:

$ cd /mylinux

or you can also use the absolute path while you delete file, type:

$ rm /mylinux/myalpine1.txt /mylinux/myalpine2.txt

Confirm each file before removal on Alpine Linux


if you want to get the confirmation for each file while removing, you can use the rm command with -i option, type:

$ rm -i myalpine.txt

Outputs:

[osetc@osetc_x8664 ~]$ rm -i myalpine.txt
rm: remove regular empty file ‘myalpine.txt’? y


[osetc@osetc_x8664 ~]$

Show report of each file removed


if you want to get the report of each file removed, you need to use the rm command with -v option, type:

$rm -v myalpine.txt

outputs:

[osetc@osetc_x8664 ~]$ rm -v myalpine.txt
rm: remove regular empty file ‘myalpine.txt’? y
removed ‘myalpine.txt’

Remove Directory on Alpine Linux


if you want to use the rm command to remove a directory , you need to use the -d option, type:

$ rm -d dalpine

Outputs:

[osetc@osetc_x8664 ~]$ rm dalpine
rm: cannot remove ‘dalpine’: Is a directory
[osetc@osetc_x8664 ~]$ rm -d dalpine
rm: remove directory ‘dalpine’? y

Remove all files under a directory(Recursive) on Alpine Linux


if you want to remove a directory and its files or its sub-directory, and you need to use the rm command with rf option, type:

$ rm -rf myalpine

if you want to get more information about rm command, you can directory run “rm –help” or “man rm” command.
type:

$ rm --help

outputs:

[osetc@osetc_x8664 ~]$ rm --help
BusyBox v1.27.2 (20180129 15:48:57 GMT) multicall binary.

Usage: rm [irf] FILE...

Remove (unlink) FILEs

i Always prompt before removing
f Never prompt
R,r Recurse

Or

$ man rm

You might also like:

Sidebar



back to top