Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the js_composer domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /home/holhol2/public_html/wp-includes/functions.php on line 6121

Step by step instructions to Duplicate Erase Move File Starting with a Dash in Linux

By holhol24 | November 21, 2020

This post will guide you how to copy, delete or move files starting with a dash character under command line interface in your Linux Operating system.

Create a Test file with A Dash. To create a file whose name begins with dash under command line interface, and you use the following command with “—” option, type:

$ touch -- "--test1"
$ echo "test" > "test2"

List Files Starting with a Dash


We have created files with a dash in the above section, and now you may be want to list all files starting with dash character, you can use “ls” command with “—” option to list them, type:

$ ls -l -- *test*

Outputs:

[root@bogon tmp]# ls -l -- *test*
-rw-r--r--. 1 root root 0 May 17 20:55 --test1
-rw-r--r--. 1 root root 5 May 17 20:57 --test2

If you just only use “ls” command to list files, and you will get an error as follows:

[root@bogon tmp]# ls -l *test*
ls: unrecognized option '--test1'
Try 'ls --help' for more information.

Move File Starting with a Dash


If you want to move file or rename file starting with a dash character, and you can also pass the “–” option to Linux mv command, and the syntax is as follow:

$ mv -- filename NewFileName
$ mv [option] -- filename NewFileName

The “–” option will make Linux command to stop parse shell command line options.

Copy Files Starting with a Dash


If you want to use Linux cp command to copy files, and you can use the following commands:

$ cp -- “--test.txt” /home

Remove Files Starting with a Dash


If you want to remove or delete files starting with a dash character, and you can not use rm command directly, and also need to pass “—” option, the syntax is as follows:

$ rm -- “--text.txt”
$ rm -rf -- ‘--text.txt’

Conclusion


You should know that how to create/list/delete/move files that filename starting with a dash on your Linux system.

holhol24

I am a Linux server pro admin and enthusiast, an upcoming web developer, junior php developer. I am currently a content creator for Holhol24, I love to play with Linux and all other distributions of it. I loves working with computers and strongly believes in sharing knowledge. Follow me For more insight into what is happening in Tech.

Advertisement Share: Facebook Twitter WhatsApp

Deprecated: File Theme without comments.php is deprecated since version 3.0.0 with no alternative available. Please include a comments.php template in your theme. in /home/holhol2/public_html/wp-includes/functions.php on line 6121

Leave a Reply

Your email address will not be published. Required fields are marked *