How to write a file's name with special character in command line? - special-characters

I've got a file named '-help.txt' in Ubuntu. I know that I should use command like this:
> rm ./-help.txt
Could anyone give me an url where I can learn systematically on how to deal with the special characters in Ubuntu command line. Thanks a lot!

Try the manpages first:
> man rm
Undoubtedly, you are using GNU rm, and you will find that GNU programs use -- to separate options from arguments, even though using ./ works.
> rm -- -help.txt
Then, try the GNU info system:
> info rm
> info fileutils

Related

How can I get zsh to inherit the complete autocompletion?

I have an little shell script (named "run") which redirects all output of a program to /dev/null:
#!/bin/bash
$# &> /dev/null &
disown +
How can I say zsh that the whole autocompletion shall work for this?
I mean
$ run git com<TAB>
autocomplete to
$ run git commit
I was able to make that work by adding:
compdef _command run
to my .zshrc file.
I've based my answer on this bash question. It was worth giving it a try with compdef - surprisingly it worked.
As I'm still zsh/autocompletion newbie I cannot explain the inner workings and you should probably go through the documentation or other sources to find more on the topic.

/usr/bin/env: «node\r» "no such file" error using JS Best Practices

Im trying to use js best practices, i use js-best-practices then the error /usr/bin/env: «node\r» "no such file" appear and the program don't run
I appreciate any solution you put. Thanks
Looks like your script file has been created on Windows, the file is DOS format (line endings in DOS). So, you may use a module which converts a file to a Unix format :
brew install dos2unix
sudo dos2unix your_script
or use tr command to remove \r from your file:
cat your_script.js | tr -d '\r' > fixed_script.js
P.S. You can also use vim to convert Windows-style to Unix-style:
vim script
:se ff=unix
:wq

Batch rename with command line

I have some files: file1.txt, file2.txt and I would like to rename them like this: file1.something.txt and file2.something.txt
I looked for some similar questions and I come up with this:
for i in file*.txt; do echo mv $i file*.something.txt; done
but unfortunately the output is:
mv file1.txt file*.something.txt
mv file2.txt file*.something.txt
and therefore only 1 file is created.
Could please somebody help?
(I am using a macbook air, I am not sure if this is relevant)
Thank you very much
Try this :
rename -n 's/\.txt/something.txt' *
(remove -n switch when your tests are OK)
There are other tools with the same name which may or may not be able to do this, so be careful.
If you run the following command (GNU)
$ file "$(readlink -f "$(type -p rename)")"
and you have a result like
.../rename: Perl script, ASCII text executable
and not containing:
ELF
then this seems to be the right tool =)
If not, to make it the default (usually already the case) on Debian and derivative like Ubuntu :
$ sudo update-alternatives --set rename /path/to/rename
(replace /path/to/rename to the path of your perl's rename command.
If you don't have this command, search your package manager to install it or do it manually
Last but not least, this tool was originally written by Larry Wall, the Perl's dad.

Force Netbeans to generate partially-qualified javadoc

several methods I have return Map objects like (partially-qualified)
Map<Integer,String>
which turn out in the NetBeans (7.0.1) generated javadoc as fully-qualified:
java.util.Map<java.lang.String,java.lang.Integer>
Do you know whether it's possible (and how) to tell NetBeans javadoc generator to use partially-qualified class names? Through Google I was only able to find related Oracle's naming convetion but there seems to be no useful option switch.
Thanks in advance!
I've resolved to post-production modification of javadoc generated files with this simple grep & sed command. It is platform dependent though (*nix os):
For example, to hide all "java.lang" package prefixes, run this in javadoc directory:
grep -rl "java.lang." ./ | xargs sed -i 's/java.lang.//g'
And in the same fashion with "java.util." package:
grep -rl "java.util." ./ | xargs sed -i 's/java.util.//g'
Hope it helps someone out there.

Sed on AIX does not recognize -i flag

Does sed -i work on AIX?
If not, how can I edit a file "in place" on AIX?
The -i option is a GNU (non-standard) extension to the sed command. It was not part of the classic interface to sed.
You can't edit in situ directly on AIX. You have to do the equivalent of:
sed 's/this/that/' infile > tmp.$$
mv tmp.$$ infile
You can only process one file at a time like this, whereas the -i option permits you to achieve the result for each of many files in its argument list. The -i option simply packages this sequence of events. It is undoubtedly useful, but it is not standard.
If you script this, you need to consider what happens if the command is interrupted; in particular, you do not want to leave temporary files around. This leads to something like:
tmp=tmp.$$ # Or an alternative mechanism for generating a temporary file name
for file in "$#"
do
trap "rm -f $tmp; exit 1" 0 1 2 3 13 15
sed 's/this/that/' $file > $tmp
trap "" 0 1 2 3 13 15
mv $tmp $file
done
This removes the temporary file if a signal (HUP, INT, QUIT, PIPE or TERM) occurs while sed is running. Once the sed is complete, it ignores the signals while the mv occurs.
You can still enhance this by doing things such as creating the temporary file in the same directory as the source file, instead of potentially making the file in a wholly different file system.
The other enhancement is to allow the command (sed 's/this/that' in the example) to be specified on the command line. That gets trickier!
You could look up the overwrite (shell) command that Kernighan and Pike describe in their classic book 'The UNIX Programming Environment'.
#!/bin/ksh
host_name=$1
perl -pi -e "s/#workerid#/$host_name/g" test.conf
Above will replace #workerid# to $host_name inside test.conf
You can simply install GNU version of Unix commands on AIX :
http://www-03.ibm.com/systems/power/software/aix/linux/toolbox/alpha.html
You can use a here construction with vi:
vi file >/dev/null 2>&1 <<#
:1,$ s/old/new/g
:wq
#
When you want to do things in the vi-edit mode, you will need an ESC.
For an ESC press CTRL-V ESC.
When you use this in a non-interactive mode, vi can complain about the TERM not set. The solution is adding export TERM=vt100 before calling vi.
Another option is to use good old ed, like this:
ed fileToModify <<EOF
,s/^ff/gg/
w
q
EOF
you can use perl to do it :
perl -p -i.bak -e 's/old/new/g' test.txt
is going to create a .bak file.