Blog

03/06/2019

How to delete and remove files on Alpine Linux



I am a new Alpine Linux user. How do I delete and remove a file on Alpine Linux based system?

You need to use the rm command. It tries to remove the files specified on the command line. Use the rm command to delete files and directories on Alpine Linux. This page shows how to delete and remove files on Alpine Linux.

Command to delete and remove files on Alpine Linux

kbd { display: inline-block; margin: 0 .1em; padding: .1em .6em; font-family: Arial,”Helvetica Neue”,Helvetica,sans-serif; font-size: 11px; line-height: 1.4; color: #242729; text-shadow: 0 1px 0 #FFF; background-color: #e1e3e5; border: 1px solid #adb3b9; border-radius: 3px; box-shadow: 0 1px 0 rgba(12,13,14,0.2), 0 0 0 2px #FFF inset; white-space: nowrap;}

The syntax is as follows for the rm and unlink command to remove files on Alpine Linux:

  1. Open the Alpine terminal application (bash shell)
  2. Type any one of the following command to delete a file named debra.doc in the current directory
  3. rm debra.doc
    OR
    unlink debra.doc

Let use see all the rm command options to delete and remove files on Alpine Linux.

Delete multiple files

Type the following command to delete the file named dexter.jpg, rita.png, and dance.jpg located in the current directory:
alpineVM:~$ rm dexter.jpg rita.png dance.jpg
You can specify path too. If a file named dexter.jpg located in /tmp/ directory, you can run:
alpineVM:~$ rm /tmp/dexter.jpg
alpineVM:~$ rm /tmp/dexter.jpg /home/vivek/dance.jpg /home/vivek/data/rita.png

Alpine Linux delete a file and prompt before every removal

To get confirmation before attempting to remove each file pass the -i option to the rm command on Alpine Linux:
alpineVM:~$ rm -i file1
alpineVM:~$ rm -i dexter.jpg

Force rm command on Alpine Linux to explain what is being done with file

Pass the -v option as follows to get verbose output on Alpine Linux box:
alpineVM:~$ rm -v file1
alpineVM:~$ rm -v cake-day.jpg

Alpine Linux delete all files in folder or directory

You need to pass the following options:
alpineVM:~$ rm -rf dir1
alpineVM:~$ rm -rf /path/to/dir/
alpineVM:~$ rm -rf /home/vivek/oldschoolpics/

It will remove all files and subdirectories from a directory. So be careful. Always keep backups of all important data on Alpine Linux.

Alpine Linux delete file begins with a dash or hyphen

If the name of a file or directory or folder starts with a dash (- or hyphen --), use the following syntax:
alpineVM:~$ rm -- -file1
alpineVM:~$ rm -- --file1
alpineVM:~$ rm -rf --folder1
alpineVM:~$ rm ./-file
alpineVM:~$ rm -rf ./--folder1

Do not run ‘rm -rf /‘ command as an administrator/root or normal Alpine Linux user

rm -rf (variously, rm -rf /, rm -rf *, and others) is frequently used in jokes and anecdotes about Alpine Linux disasters. The rm -rf / variant of the command, if run by an administrator, would cause the contents of every writable mounted filesystem on the computer to be deleted. Do not try these commands on Alpine Linux:
alpineVM:~$ rm -rf /
alpineVM:~$ rm -rf *

Conclusion

And there you have it, the rm command which is used to delete files and directories on Alpine Linux operating systems. Please note that Alpine Linux provides busybox version of rm command. It has a limited number of options. To see all available options type the following command:
rm --help
Sample outputs:

BusyBox v1.27.2 (2018-01-29 15:48:57 GMT) multi-call binary.
 
Usage: rm [-irf] FILE...
 
Remove (unlink) FILEs
 
	-i	Always prompt before removing
	-f	Never prompt
	-R,-r	Recurse

BusyBox v1.27.2 (2018-01-29 15:48:57 GMT) multi-call binary. Usage: rm [-irf] FILE… Remove (unlink) FILEs -i Always prompt before removing -f Never prompt -R,-r Recurse

(adsbygoogle = window.adsbygoogle || []).push({});

Posted by: SXI ADMIN

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

14/08/2019

How to KVM, QEMU start or stop virtual machine from command line (CLI)

KVM or Kernel Based Virtual Machine is a popular virtualization technology. It allows you to run virtual guest machines over a host machine. To start...
14/08/2019

How to Docker backup Saving and restoring your volumes

Running a Docker volume backup First, we spin up a temporary container, and we mount the backup folder and the target Docker volume to this container....
12/08/2019

How to Start and Enable Firewalld on CentOS 7

In this article, we discuss how to start and enable firewalld. It is highly recommended that you have a firewall protecting your server.Pre-Flight CheckThese...