bash

Linux Bash: Move multiple different files into same directory

别来无恙 提交于 2021-02-06 02:27:56
问题 As a rather novice Linux user, I can't seem to find how to do this. I am trying to move unique files all in one directory into another directory. Example: $ ls vehicle car.txt bicycle.txt airplane.html train.docx (more files) I want car.txt, bicycle.txt, airplane.html, and train.docx inside vehicle. Right now I do this by moving the files individually: $ mv car.txt vehicle $ mv bicycle.txt vehicle ... How can I do this in one line? 回答1: You can do mv car.txt bicycle.txt vehicle/ (Note that

Bash: Why does parent script not terminate on SIGINT when child script traps SIGINT?

心已入冬 提交于 2021-02-06 02:27:45
问题 script1.sh: #!/bin/bash ./script2.sh echo after-script script2.sh: #!/bin/bash function handler { exit 130 } trap handler SIGINT while true; do true; done When I start script1.sh from a terminal, and then use Ctrl + C to send SIGINT to its process group, the signal is trapped by script2.sh and when script2.sh terminates, script1.sh prints "after-script". However, I would have expected script1.sh to immediately terminate after the line that invokes script2.sh. Why is this not the case in this

Bash: Why does parent script not terminate on SIGINT when child script traps SIGINT?

折月煮酒 提交于 2021-02-06 02:26:32
问题 script1.sh: #!/bin/bash ./script2.sh echo after-script script2.sh: #!/bin/bash function handler { exit 130 } trap handler SIGINT while true; do true; done When I start script1.sh from a terminal, and then use Ctrl + C to send SIGINT to its process group, the signal is trapped by script2.sh and when script2.sh terminates, script1.sh prints "after-script". However, I would have expected script1.sh to immediately terminate after the line that invokes script2.sh. Why is this not the case in this

Linux Mint - adding environment variables permanently [closed]

 ̄綄美尐妖づ 提交于 2021-02-06 01:44:27
问题 Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 8 months ago . Improve this question I was trying to modify the ~/.profile file to add a line to the PATH variable. I added this line: PATH=$PATH:/home/paul/avatar-gf-1.0-ea/glassfish4/bin/ at the end. I restarted the terminal, but it still did not identify commands in that directory. Does anyone

Write to custom log file from a Bash script

a 夏天 提交于 2021-02-05 20:43:16
问题 In Linux, I know how to write a simply message to the /var/log/messages file, in a simple shell script I created: #!/bin/bash logger "have fun!" I want to stop throwing messages into the default /var/log/messages file, and create my own. I tried this: #!/bin/bash logger "have more fun" > /var/log/mycustomlog It still logs to /var/log/messages . It did create the /var/log/mycustomlog , but it's empty. Anyone see what I'm missing? 回答1: logger logs to syslog facilities. If you want the message

How do I exclude a folder when performing file operations i.e. cp, mv, rm and chown etc. in Linux

前提是你 提交于 2021-02-05 20:29:23
问题 How do you exclude a folder when performing file operations i.e. cp etc. I would currently use the wild card * to apply file operation to all, but I need to exclude one single folder. The command I'm actually wanting to use is chown to change the owner of all the files in a directory but I need to exclude one sub directory. 回答1: If you're using bash and enable extglob via shopt -s extglob then you can use !(<pattern>) to exclude the given pattern. 回答2: find dir_to_start -name dir_to_exclude

Generate script in bash and save it to location requiring sudo

北城以北 提交于 2021-02-05 20:23:51
问题 In bash I can create a script with a here-doc like so as per this site: http://tldp.org/LDP/abs/html/abs-guide.html#GENERATESCRIPT ( cat <<'EOF' #!/bin/bash #? [ ] / \ = + < > : ; " , * | #/ ? < > \ : * | ” #Filename="z:"${$winFn//\//\\} echo "This is a generated shell script." App='eval wine "C:\Program Files\foxit\Foxit Reader.exe" "'$winFn'"' $App EOF ) > $OUTFILE If my $OUTFILE is a directory requiring sudo privileges where do I put the sudo command or what else can I do to make it work?

Generate script in bash and save it to location requiring sudo

人盡茶涼 提交于 2021-02-05 20:17:22
问题 In bash I can create a script with a here-doc like so as per this site: http://tldp.org/LDP/abs/html/abs-guide.html#GENERATESCRIPT ( cat <<'EOF' #!/bin/bash #? [ ] / \ = + < > : ; " , * | #/ ? < > \ : * | ” #Filename="z:"${$winFn//\//\\} echo "This is a generated shell script." App='eval wine "C:\Program Files\foxit\Foxit Reader.exe" "'$winFn'"' $App EOF ) > $OUTFILE If my $OUTFILE is a directory requiring sudo privileges where do I put the sudo command or what else can I do to make it work?

Quick ls command

旧街凉风 提交于 2021-02-05 20:12:21
问题 I've got to get a directory listing that contains about 2 million files, but when I do an ls command on it nothing comes back. I've waited 3 hours. I've tried ls | tee directory.txt , but that seems to hang forever. I assume the server is doing a lot of inode sorting. Is there any way to speed up the ls command to just get a directory listing of filenames? I don't care about size, dates, permission or the like at this time. 回答1: ls -U will do the ls without sorting. 回答2: Try using: find .

Bash Boolean testing

送分小仙女□ 提交于 2021-02-05 20:11:51
问题 I am attempting to run a block of code if one flag is set to true and the other is set to false. ie var1=true var2=false if [[ $var1 && ! $var2 ]]; then var2="something"; fi Since that did not evaluate the way that I expected I wrote several other test cases and I am having a hard time understanding how they are being evaluated. aa=true bb=false cc="python" if [[ "$aa" ]]; then echo "Test0" ; fi if [[ "$bb" ]]; then echo "Test0.1" ; fi if [[ !"$aa" ]]; then echo "Test0.2" ; fi if [[ ! "$aa" ]