How to open a - dashed filename using terminal?
This type of approach has a lot of misunderstanding because using - as an argument refers to STDIN/STDOUT i.e dev/stdin or dev/stdout .So if you want to open this type of file you have to specify the full location of the file such as ./- .For eg. , if you want to see what is in that file use cat ./-
How do I deal with a filename that starts with the hyphen (-) character?
You can refer to it either using ./-filename
or some command will allow you to put it after double dash:
rm -- -filename
How to create a file with its name starting with dash in Linux? (ex -file )
ls -ltr | awk '$NF ~ /^--/{print "rm ./" $NF}'|sh
Recursively replacing a dash with an underscore in terminal
Is there much crossover between files that contain spaces and hyphens? Because, if that's not the case, you may not be getting the files you want from the find
options.
In other words, your second command looks for files containing a space and then replaces all hyphens with underscores in those files. I suspect you should probably be doing this instead:
find ./ -depth -name "*-*" -execdir rename 's/-/_/g' "{}" \;
# ^
# note this bit
How to read - (dash) as standard input with Python without writing extra code?
The argparse
module provides a FileType
factory which knows about the -
convention.
import argparse
p = argparse.ArgumentParser()
p.add_argument("-p", type=argparse.FileType("r"))
args = p.parse_args()
Note that args.p
is an open file handle, so there's no need to open it "again". While you can still use it with a with
statement:
with args.p:
for line in args.p:
...
this only ensures the file is closed in the event of an error in the with
statement itself. Also, you may not want to use with
, as this will close the file, even if you meant to use it again later.
You should probably use the atexit
module to make sure the file gets closed by the end of the program, since it was already opened for you at the beginning.
import atexit
...
args = p.parse_args()
atexit.register(args.p.close)
Move file with a dash
It's not mc
, it's mv
. Quoting doesn't help because the quotes are interpreted by the shell so mv
receives unquoted parameters name.csv
and -name.csv
. You need to hide the dash so that option parser in mv
stops thinking it's an option. Use relative path ./
for the current directory, or full path:
mv name.csv ./-name.csv
mv name.csv "`pwd`"/-name.csv
Related Topics
Cpu Usage Percent from Linux Server
Highlight Text Similar to Grep, But Don't Filter Out Text
Using a Remote Host's Usb Port as Local Usb (Linux and Windows)
Find Files in Created Between a Date Range
How to Clean Caches Used by the Linux Kernel
How to Execute a Series of Commands in a Bash Subshell as Another User Using Sudo
Install Zsh Without Root Access
Why Does Perf Stat Show "Stalled-Cycles-Backend" as <Not Supported>
How to Add a Custom Footer to Sphinx Documentation? (Restructuredtext)
How to Automatically Pipe to Less If the Result Is More Than a Page on My Shell
Creating an Installer for Linux Application
How to Find Which Yocto Project Recipe Populates a Particular File on an Image Root Filesystem