Many meta-characters such as semicolons, spaces, backslashes, dollar signs, question marks, and asterisks are characters that are interpreted under Unix as commands. - or -- interpreted as an option passed to the command. Try the following suggestions for moving (mv) or copying (cp) these files.
Create Test File
Type the following command:cd /tmp/
> '-foo.txt'
> '--bar.txt'
List Files Starting With a Dash
Try to list them, enter:ls -l *.txtYou will get an error as follows:ls: unrecognized option '--bar.txt'To delimit the option list use -- i.e. type the following command:
Try `ls --help' for more information.
ls -l -- *.txtcp and mv commands
Same can be used to copy or move files:cp -- '--bar.txt' /path/to/destOR
cp -v -- '--bar.txt' /path/to/destTo move files:
mv -- '--bar.txt' /path/to/destOR
mv -v -- '--bar.txt' /path/to/destIn short the syntax is as follows:
cp options -- '--filename' /destThe -- delimit the option list. Later arguments, if any, are treated a operands even if they begin with - or --. This applies to all commands such as rm, cp, mv, ls, ln and so on:
mv options -- '--filename' /dest
command -- 'file'
command [options] -- 'file'
rm -- '--filename'
rm -fr -- '-dirname'
rmdir -- '--dirname'
No comments:
Post a Comment