Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 5 years ago.
Improve this question
How do I remove files, with specific names.. For example, my file name is
This File Example (England).txt
This File Example (US).txt
I want to remove all the files with (England) in the name.
So I tried,
rm -f "*(Eng*"
But it doesn't work. Is there something needed for special chars?
This should do it:
rm -f ./*'(England)'*
Escape the special ones:
rm -f *\(Eng*
^
Or use single quotes for literal parts:
rm -f *'(Eng'*
^ ^
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 4 years ago.
Improve this question
I often find myself wanting to copy files from one of the directories in my directory stack to another, and the best solution I've come up with is cp $(dirs -p | tail -n 1)/somefile.txt ./somefile.txt
Is there a better solution for this?
You can access the directory stack directly via the DIRSTACK array; no command substitutions are needed.
cp "${DIRSTACK[-1]}/somefile.txt" .
Your original code was buggy for the same reason the output of ls should not be used programmatically; a directory name containing a newline character could break it. For example:
$ pushd $'foo\nbar'
$ dirs -p | head -1
~/bin/foo
Using dirs +0 at least fixes that problem (assuming you correctly quote the command substitution as cp "$(dirs +N)"/somefile.txt ./somefile.txt, anyway):
$ dirs +0
~/bin/foo
bar
After referncing the https://www.gnu.org/software/bash/manual/html_node/Directory-Stack-Builtins.html#Directory-Stack-Builtins, a slightly better solution is cp $(dirs +N)/somefile.txt ./somefile.txt
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 6 years ago.
Improve this question
I would like to cut my input file to the output file in Linux shell script.
Input file
ANI_NO;ANI_IDNO;BIRTH_D;SEX;SIRE_ANI.NO;SIRE_ANI_IDNO;DAM_ANI_NO;DAM_ANI_IDNO
17441163;BRMMGDP880054;19881019;M;12566287;BRMMAGG850096;3754140;BRMFGDP068100
19750215;BRMMGDP890040;19891006;M;12566287;BRMMAGG850096;11743556;BRMFGDP860019
24955692;BRMMGDP910080;19911212;M;12566287;BRMMAGG850096;12034096;BRMFGDP860029
18135053;BRMMGDP890008;19890216;M;12566287;BRMMAGG850096;10777720;BRMFGDP860009
22679344;BRMFGDP900019;19901023;F;12566287;BRMMAGG850096;13002167;BRMFGDP870007
23285273;BRMMGDP910005;19910125;M;12566287;BRMMAGG850096;14041693;BRMFGDP870010
Output file
ANI_IDNO;BIRTH_D;SEX;SIRE_ANI_IDNO;DAM_ANI_IDNO
BRMMGDP880054;19881019;M;BRMMAGG850096;BRMFGDP068100
BRMMGDP890040;19891006;M;BRMMAGG850096;BRMFGDP860019
BRMMGDP910080;19911212;M;BRMMAGG850096;BRMFGDP860029
BRMMGDP890008;19890216;M;BRMMAGG850096;BRMFGDP860009
BRMFGDP900019;19901023;F;BRMMAGG850096;BRMFGDP870007
BRMMGDP910005;19910125;M;BRMMAGG850096;BRMFGDP870010
Just use cut, specifying the delimiter and the fields you want:
cut -d';' -f2,3,4,6,8 input.file > output.file
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I wanted to find a bash script for renaming files with _ (underscore) to - (hyphen)
for example changing file name my_page_name.php to my-page-name.php,
keeping the name of the file of those without .php extension same
I attempted:
Nothing yet , just used the script found here bbs.archlinux.org/viewtopic.php?id=36305 and replace space with _ and underscore with -
If you only need to do it in one directory (and not subdirectories):
for f in *_*; do mv "$f" "${f//_/-}"; done
Otherwise, you can use find to -exec a bash subshell.
Use the rename program:
rename s:_:-: *.php
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
How is it possible to delete files containing a string as an embedded string except at the
beginning or end by using wild-cards.
I'm an amateur started Ubuntu less than a month.
rm ?*foo?*
removes files containing foo provided that there is at least one character before and after, so "foobar" and "barfoo" will NOT be deleted, whereas "barfoobar" will be.
As a precaution, do
ls ?*foo?*
first to make sure that you aren't deleting the wrong stuff. And be very careful not to accidentally include any spaces as rm ?* foo?* is almost certainly very bad. To provide some protection, wrap the argument in quotes, thus
rm "?*foo?*"
I don't think this is possible with a single expansion pattern. You can use grep for filtering instead:
ls -d '*foo*' | egrep -v '^foo|foo$' | xargs rm
So the ls lists everything containing foo, then egrep removes the files with matches at the beginning/end, and finally xargs runs a command (rm in this case) on each remainder.
The dangerous thing about this technique is that filenames may contain special characters like line breaks or asterisks, so use at your own risk!
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
I have a directory named "--table" that i'd like to remove. I tried rmdir --table, rmdir --table and still it wouldnt work. What is the correct method ?..
rmdir -- --table
The -- in the middle signals the end of options.
The rm man page states
To remove a file whose name starts with a '-', for example '-foo', use
one of these commands:
rm -- -foo
rm ./-foo
Although it does not state it, the double-hyphen is used by many unix commands (e.g. rmdir) to separate options from the rest of the arguments.
You can use -- alone to signal that what follows are file names, not switches. So, the correct method would be rmdir -- --table.
rm -rf ./--table
or simply, but with great care, rm -rfi * and answer y only for --table