Все вопросы: [bash]

1 184 вопросов

1
голосов
4ответов
2942 просмотров

Looking for recommendations on a good ** beginners ** bash tutorial

I am an ETL developer by profession that just started reading The Pragmatic Programmer by Dave Thomas & Andrew Hunt. I have been meaning to learn more about bash & command line in Ubuntu for a while but reading this book made me realize how essential it is for me to start learning it. The...

0
голосов
6ответов
849 просмотров

bash : Make job every x days

I have a bash script runned every day via cron. In this bash I want to run some command but only every x day (x is fixed and will be 3, 4 or 5 I don't know at the moment) I can test if the remainder of the division day of month / x equal 0 day_of_month % x = 0 I will work on a single month bu...

13
голосов
4ответов
17147 просмотров

Regex match a string with spaces (use quotes?) in an if statement

How would I do a regex match as shown below but with quotes around the ("^This") as in the real world "This" will be a string that can have spaces in it. #!/bin/bash text="This is just a test string" if [[ "$text" =~ ^This ]]; then echo "matched" else echo "not matched" fi I want to do som...

2
голосов
2ответов
322 просмотров

graceful degradation for globbing on terminal

Whenever glob pattern match fails, it stops the whole job. For instance, $ mv *.jpg *.png folder1 && blahblah mv: cannot stat `*.jpg': No such file or directory *.png isn't moved to folder1 and blahblah is not run. And the script below works only for the case when both .[A-z]* and * s...

51
голосов
6ответов
16183 просмотров

How to programmatically determine whether the Git checkout is a tag and if so, what is the tag name

In a Unix or GNU scripting environment (e.g. a Linux distro, Cygwin, OSX), what is the best way to determine whether the current checkout is a Git tag. If it is a tag, how can I determine the tag name? One use of this technique would be automatically labeling a release (like svnversion would do ...

284
голосов
20ответов
116913 просмотров

How to programmatically determine the current checked out Git branch

In a Unix or GNU scripting environment (e.g. a Linux distro, Cygwin, OSX), what is the best way to determine which Git branch is currently checked out in a working directory? One use of this technique would be automatically labeling a release (like svnversion would do with Subversion). Please a...

0
голосов
3ответов
285 просмотров

How to supply many argv and outputredirection with one bash var?

In file a.lst: in1.a in1.b > out1.a 2> out1.b in2.a in2.b > out2.a 2> out2.b In do.sh: CLI=$(sed -n -e "1 p" a.lst) perl a.pl $CLI I want to run like perl a.pl in1.a in1.b > out1.a 2> out1.b, how can I make it work ?

9
голосов
4ответов
867 просмотров

PowerShell eye for the Bash guy

For someone who has been using bash for years, what's the quickest way to get productive with Microsoft's PowerShell? I've noticed my old friends ls and ps work, but sadly grep didn't. I could just man up and read through the piles of documentation, but I'm guessing there is a quicker path to p...

11
голосов
7ответов
16709 просмотров

Shell Scripting: Using bash with xargs

I'm trying to write a bash command that will delete all files matching a specific pattern - in this case, it's all of the old vmware log files that have built up. I've tried this command: find . -name vmware-*.log | xargs rm However, when I run the command, it chokes up on all of the folders ...

19
голосов
5ответов
19282 просмотров

Opening a new terminal tab in OSX(Snow Leopard) with the opening terminal windows directory path

I've been Googling for a while looking for a simple way to do this, and I can't find one. I have a custom terminal environment set up (zsh) with various aliases and functions to make things easier. One thing I keep running into is that I will quickly APPLE-t to create a new tab and then type a c...

13
голосов
9ответов
14533 просмотров

Find highest numbered filename in a directory where names start with digits

I have a directory with files that look like this: 001_something.php 002_something_else.php 004_xyz.php 005_do_good_to_others.php I ultimately want to create a new, empty PHP file whose name starts with the next number in the series. LIST=`exec ls $MY_DIR | sed 's/\([0-9]\).*//g' | tr...

10
голосов
6ответов
2971 просмотров

Bash globbing - autoexpand for a few specific cases?

I understand that the wildcard * (by itself) will expand in such a way that it means "all non-hidden files in the current folder" with hidden files being those prefixed by a period. There are two use cases that I would think are useful, but I don't know how to properly do: How can you glob for...

0
голосов
1ответов
1184 просмотров

How to extract archive from this script (using tar)

I have absolutly no idea how to unpack the created archive. I give you the complete Script. A Debian based Distibution named Univention uses this to backup several files in an tar archive. The real archive is packed in an function. The main Content where they create the actual tar file is: cat ...

1
голосов
3ответов
86 просмотров

Sorting and extracting of dirnames

There are a lot of directories named like web001 web002 ... web123 ... I want to extract a max-number from this set... Something like num="´find -name /dirname sort ... | tail´" with extracting. I have no ideas... Thank you

4
голосов
2ответов
14209 просмотров

Append to /etc/apt/sources.list

I'm creating some scripts to streamline application installations and I need to append to the end of /etc/apt/sources.list This code below append to files in ~ but not in /etc/apt/ echo "deb http://ppa.launchpad.net/person/ppa/ubuntu karmic main" >> /etc/apt/sources.list @meder I have ...

2
голосов
2ответов
4450 просмотров

How to create Cron job to backup MySQL and FTP backup to my backup server?

I want to setup a cron job to run so that it will automatically backup my MySQL database, while the database is running, and then FTP that backup to my backup server. I assume I can do this using a bash script. Anyone know of a good way to accomplish this? Thanks in advance.

693
голосов
35ответов
537551 просмотров

How to do a recursive find/replace of a string with awk or sed?

How do I find and replace every occurrence of: subdomainA.example.com with subdomainB.example.com in every text file under the /home/www/ directory tree recursively?

1
голосов
3ответов
2266 просмотров

How can I split a file into a given number of parts in Perl? (On Unix)

I have several large files, each of which I want to chunk/split it in to predefined number of parts. Is there an efficient way to do it in Unix (e.g. via awk/sed/perl)? Also each file can have varied number of lines. File1.txt 20,300,055 lines File2.txt 10,033,221 lines etc...

25
голосов
5ответов
32442 просмотров

matching a line with a literal asterisk "*" in grep

Tried $ echo "$STRING" | egrep "(\*)" and also $ echo "$STRING" | egrep '(\*)' and countless other variations. I just want to match a line that contains a literal asterisk anywhere in the line.

4
голосов
1ответов
4934 просмотров

netcat "Connection refused" on localhost

I'm trying to get a value from a netcat connection started at a php file, but it dies with: localhost [127.0.0.1] 2000 (?) : Connection refused I don't know why but it works well if I ssh it as apache user (www-data), this is what I've done: 1) Start an endless loop serving a date with a litt...

2
голосов
5ответов
6124 просмотров

How do I use tr to substitute '--' string

I have an output: -- out1 -- out2 -- out3 I want to get the output: out1 out2 out3 I thought of using: tr '--' '' but it doesn't recognize '--' to be the first string I want to substitute. How do I solve this?

6
голосов
2ответов
2341 просмотров

Why does bash sometime not flush output of a python program to a file

I have a crontab job calling a python script and outputting to a file: python run.py &> current_date.log now sometimes when I do tail -f current_date.log I see the file filling up with the output, but other times the log file exists, but stays empty for a long time. I am sure that t...

0
голосов
3ответов
1732 просмотров

How to check for an exploding zip file in bash?

I have a bash shell script that unzips a zip file, and manipulates the resulting files. Because of the process, I expect all the content I am interested to be within a single folder like so: file.zip /file /contentFolder1 /contentFolder2 stuff1.txt stuff2.txt ... I've...

1
голосов
5ответов
9463 просмотров

Best tool in unix for viewing large files

I am a novice in unix. I am facing a problem in viewing big log files in unix using vi. Could you please suggest the best tool for fast viewing of big files on unix? Additionally, could you to post your own ways of viewing the big files on unix?

3
голосов
5ответов
830 просмотров

Using [email protected] properly

I am trying to write a tiny script that accepts any number of command line arguments that prints out the rwx permissions for a file (not directory) What I have is [email protected] if [ -f $file ] ; then ls -l $file fi This accepts only one command line argument however. Thanks for any he...

25
голосов
6ответов
23544 просмотров

Bash and filenames with spaces

The following is a simple Bash command line: grep -li 'regex' "filename with spaces" "filename" No problems. Also the following works just fine: grep -li 'regex' $(<listOfFiles.txt) where listOfFiles.txt contains a list of filenames to be grepped, one filename per line. The problem occu...

15
голосов
8ответов
18162 просмотров

List all leaf subdirectories in linux

Is there an easy way to list only directories under a given directory in Linux? To explain better, I can do: find mydir -type d which gives: mydir/src mydir/src/main mydir/bin mydir/bin/classes What I want instead is: mydir/src/main mydir/bin/classes I can do this in a bash script that l...

1
голосов
2ответов
4598 просмотров

Cygwin Bash, loading a history file

I use Cygwin's bash shell (bash -i) daily for common tasks. In my .bashrc file, I have the following: history -rc bashcommands.history history Above the first prompt line, I see the list of history commands from bashcommands.history, so it looks like the history has been changed. However, if...

2
голосов
1ответов
4924 просмотров

BASH script passing stdin input to a program and giving control back to user input

(I looked everywhere for this, perhaps my googling skill is off today) I have a program that requires a handful of initialization cmds from stdin (and not through arguments). It'd be nice to move those commands into a script so when the script completes I can start keying the real work. So somet...

0
голосов
5ответов
119 просмотров

problem in shell script

I am trying this option #!/bin/ksh echo $1 awk '{FS="=";print $2}' $1 and on the command line test_sh INSTANCE=VIJAY but awk is failing. Is there any problem here? Basically I need the value VIJAY passed on the command line.