How to copy/move to a file with a special character as the 1st char in the filename?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to copy/move to a file with a special character as the 1st char in the filename?
# 1  
Old 12-08-2008
How to copy/move to a file with a special character as the 1st char in the filename?

I am trying to create files with special characters in its filenames for testing purposes. This is on a Linux RHEL4 but this should also be applicable on a Unix shell.

I am able to create files with special characters in the filenames...e.g.

cp -pv foo.gif \*special.gif
cp -pv foo.gif \ blank.space.start.gif

I cannot create this filename:

-special.filename.txt

The cp or mv command thinks that the '-' character specifies a flag.

I've tried the following commands:

cp -pv foo.bar \-special.txt (this results in a filename of '\-special.txt')
cp -pv foo.bar '-special.txt' (cp thinks '-special.txt' is an invalid option)
cp -pv foo.bar '\-special.txt' (the result is the same as \-special.txt)

This might be a simple question but does anyone know how to create a file, either by cp or mv, with a filename that has the dash '-' character as the first character in the filename?
# 2  
Old 12-08-2008
try doing in this way
Code:
cp -pv foo.bar "-filename"

and to remove that you can use
Code:
rm -- "-filename"

it worked for me in AIX
# 3  
Old 12-08-2008
The double-quote doesn't work

I tried using double-quotes:

cp -pv foo.bar "-filename"
That doesn't work on my Linux machine - the cp command still thinks that the -filename is an option, not the destination filename.
# 4  
Old 12-10-2008
For removing
find . -name "-*" -exec rm -f {} \;
# 5  
Old 12-10-2008
Assuming this is on a non-operational system.

cp -p foo.bar ./-rubbish

To remove file.
rm -i ./-rubbish

You would be advised to not leave files like this on a live server. They upset basic unix commands and backup software.
# 6  
Old 12-26-2008
Code:
cp -pv foo.bar "-filename"
cp: invalid option -- e
Try `cp --help' for more information.

# 7  
Old 12-26-2008
try using the complete path of the file

Code:
cp /home/user/-unwanted_file /home/user/useful_file

or find the inode of the file and do the operation

Code:
find . -inum | <operation>

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

^M special character in Filename

Hi All, Special character ? is added in between filename. Am not able to figure our why this is happening. In my Development environment special characters are not present. This issue is happening in the higher environment. It would be helpful if somebody can tell what are the possible... (3 Replies)
Discussion started by: weknowd
3 Replies

2. Shell Programming and Scripting

To search distinct special char in file

hi, i need to search distinct special character from a file which is a pipe delimited from a specific column for eg: input file.txt aa|bb|cc|$abc aa|bb|ccc|#abol bb|xss|ddd|$xyz nn|yyy|qqq|=qqqq abe|qqq|yyy|=aaa aaa|yyy|zzzz|#aaaa . . . my desired output $ (10 Replies)
Discussion started by: rohit_shinez
10 Replies

3. UNIX for Advanced & Expert Users

Stty and copy special character

Hello, I do have a little issue here and Google doesn't give me any solution @this moment. In HP UX Vi editor: I want to place this character: ® I copied it from internet or for example Word Special Symbols. But how do I paste it in Vi? Many thanks in advance :) Sincerely, Arjan (7 Replies)
Discussion started by: velde_van_der_a
7 Replies

4. Shell Programming and Scripting

remove the special characters and move the file into another server

(5 Replies)
Discussion started by: number10
5 Replies

5. Shell Programming and Scripting

Move file based on filename

Hi All I need a script to manipulate files based on a filename: example filename: 66600_042706.pdf the script will create a directory 66000 only if this directory is not existing. If that directory is existing it will just move the file to 66000/666000_042706.pdf in addition, i want to... (4 Replies)
Discussion started by: aemestech
4 Replies

6. Shell Programming and Scripting

Remove special char from end of the file

Hi I am working on a bash script and would know how to use cut or sed to remove (F/.M/d h) from a text file. Before 1 text to save (F/.M/d h) after 1 text to save Thanks in advance (5 Replies)
Discussion started by: pelle
5 Replies

7. Shell Programming and Scripting

Special Char in Data file

Hi All, I have a data file in UNIX which i am trying to load into Oracle table using Oracle SQL Loader. The problem is, one of the filed contains special character (ex: Square). And due to this reason, my script fails. Could you please let me know, how to identify which character is... (1 Reply)
Discussion started by: Amit.Sagpariya
1 Replies

8. Shell Programming and Scripting

File Move Based on 1st Character of File Name

I need some help with a unix script to mv image files to subdirectories based on the 1st character of the filename. See example below... /images/main 1191.jpg 9999.jpg A101.jpg A102.jpg B201.jpg c333.jpg ... Z999.jpg I would like to move to the following: ... (11 Replies)
Discussion started by: srdconsulting
11 Replies

9. Shell Programming and Scripting

move filenames with to another filename without the last character ~

Hi, I need to move filenames with the following format below into filenames without the ~ like sample below. I hope you can help me create a simple unix script that will do this. Thanks in advance! move filename from: AIRS20081225-235641.BSP~ AIRS20081225-235648.BSP~ AIRS20081225-235640.BSP~... (3 Replies)
Discussion started by: ayhanne
3 Replies

10. HP-UX

special character on Filename.. help!!!urgent

I'm trying to rename a file name but the original file has a special character caused by typo. I've tried numerous combination of characters but the file name (original) is still not being recognized which in turn, would not allow me to rename the file. Can someone help? The filename is a... (1 Reply)
Discussion started by: genzbeat
1 Replies
Login or Register to Ask a Question