Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to copy a file with '$' in name in Linux

Tags:

linux

Inside of my Linux directory, I have a file named TopSample$Config.class. Whenever I try to copy this file to another location/directory, it is not allowing me to do so.

I am doing it this way:

cp TopSample$Config.class /home/praveen/com/config/

Please let me know if this isn't possible.

like image 320
Pawan Avatar asked Mar 12 '12 13:03

Pawan


People also ask

How copy file with long name?

Windows has a limitation where the entire path to a file cannot be over 255 characters. Microsoft has a command line copy program called "Robocopy" (Robust Copy) that can copy files without this limitation. ROBOCOPY will accept UNC pathnames including UNC pathnames over 256 characters long.

How do I copy a specific file in Linux?

You can copy files by right-clicking on the file and selecting "Copy", then going to a different directory and selecting "Paste". For my terminal friends, you can also perform file copy-paste operations without leaving the terminal. In a Linux-based terminal, you do this using the cp command.

How do I copy a file to another name in Linux?

By Using cp Command Linux system users can copy folders, directories, and files using the cp command. We can use cp commands along with destination and source only. Here along with the file's path, the filename is also changed—the syntax for the cp command.

How do I copy and rename a file in Unix?

Unix does not have a command specifically for renaming files. Instead, the mv command is used both to change the name of a file and to move a file into a different directory.


2 Answers

The shell will interpret $Config as a variable. And it will expand to empty string.
You can put single quotes around to keep the literal value:

cp 'TopSample$Config.class' /home/praveen/com/config/

Another way is to escape the $(dollar sign) by using \(backslash)

cp TopSample\$Config.class /home/praveen/com/config/
like image 79
kev Avatar answered Oct 09 '22 07:10

kev


Put single quotes around the filename.

cp 'TopSample$Config.class' /home/praveen/com/config
like image 34
Fred Foo Avatar answered Oct 09 '22 08:10

Fred Foo