# find /home/shantanu -name 'my_stops*' | xargs ls -lt | head -2
The command mentioned above will list the latest 2 files having my_stops in it's name. I want to keep these 2 files. But I want to delete all other files starting with "my_stops" from the current directory.
...
I have a web server that saves the logs files of a web application numbered. A file name example for this would be:
dbsclog01s001.log
dbsclog01s002.log
dbsclog01s003.log
The last 3 digits are the counter and they can get sometime up to 100.
I usually open a web browser, browse to the file like:
http://someaddress.com/logs/dbsclog01s...
I have a PHP program that uses a Bash script to convert a pdf. However if the filename contains spaces it is not passed through the bash script correctly.
How do you escape filenames with spaces within a bash script? Do you have to do something special to quote the filename for the "OUTFILE" variable?
Bash script:
#!/bin/bash
INFI...
Is there any bash command that will let you get the nth line of STDOUT?
That is to say, something that would take this
$ ls -l
-rw-r--r--@ 1 root wheel my.txt
-rw-r--r--@ 1 root wheel files.txt
-rw-r--r--@ 1 root wheel here.txt
and do something like
$ ls -l | magic-command 2
-rw-r--r--@ 1 root wheel files.txt
I realize this wo...
I'm porting a Linux tool-set that makes frequent use of shell functions to provide certain functionality. These functions are automatically sourced when you start a new shell and include things like changing the working directory, which is nigh impossible with stand-alone programs because child processes can't change their parent's envir...
I have a problem replacing a command inside of a script, the offending line in the script looks like this:
mail -s "$(hostname) on $(date)"
It should be replaced with a line like this:
nail -r "[email protected]" -s "Subject" -S smtp=255.255.255.255
But I can't get sed to do a replacement :) I wrote a small script for that purpose:...
How would you write this having only batch files and VBScript at your disposal in a Windows environment?
find -name '*.ext' -exec cp --parents {} destination/ \;
Or put it this way:
Look recursively in the current folder for some filename pattern (ending with an extension called ext in the example above),
Copy each of these files to...
I have a bash script I want to run every 5 minutes from cron... but there's a chance the previous run of the script isn't done yet... in this case, i want the new run to just exit. I don't want to rely on just a lock file in /tmp.. I want to make sure sure the process is actually running before i honor the lock file (or whatever)...
He...
In my script in bash, there are lot of included libs and I use functions declared in these files. Like this:
#!/bin/bash
. foo.inc
. bar.inc
. baz.inc
function_1
function_2
function_3
EOF
My question is how to learn which file include function_1 declaration? In runtime of this script.
...
I'm trying to knock together a little batch script for downloading files, that takes a URL as its first parameter and a local filename as its second parameter. In testing I've learned that its tripping up on spaces in the output filename, so I've tried using sed to escape them, but its not working.
#!/bin/bash
clear
echo Downloading $1...
I have a script running in the background that prints some output. I redirected the standard output to a file for log purposes. However I don't want this file to grow forever, what would be a good way to do rollover without coding the logic myself? (Either rollover based on date or file size).
...
Possible Duplicates:
Favourite command line trick
useful linux commands for programmers?
What is your single most favorite command-line trick using Bash?
I have recently become accustomed to doing most of my development (in various languages) from the bash shell, using command-line tools and interfaces. I have discovered it ...
I just want to get the files from the current dir and only output .mp4 .mp3 .exe files nothing else.
So I thought I could just do this:
ls | grep \.mp4$ | grep \.mp3$ | grep \.exe$
But no, as the first grep will output just mp4's therefor the other 2 grep's won't be used.
Any ideas?
PS, Running this script on Slow Leopard.
...
How would I get awk to output $9 $10 $11 etc as some of my files have spaces in them.
ls -l | grep ^- | awk '{print $9}'
...
I put original git-completion.bash (from git tarball) and source it from my ~/bash_profile.
When using git branch is shows only HEAD, e.g.:
piotr@PiotrMBP ~/Projects/X (master)
$ git co HEAD
but I have:
$ git br -a
NSXMLDocument
* master
origin/HEAD
origin/NSXMLDocument
origin/master
I haven't modified git-completion.ba...
I have the following bash script:
#!/bin/sh
MYSQLHOST="mysql.remote-host.com"
MYSQLDB="mysqldb"
MYSQLTABLE="table"
MYSQLUSER="user"
MYSQLPASS="pass"
MYSQLDUMP="Report/report.csv"
LOG="Report/report.log"
MYSQLOPTS="--user=${MYSQLUSER} --password=${MYSQLPASS} --host=${MYSQLHOST} ${MYSQLDB}"
echo "Report Begin: $(date)"
echo "MySQL Du...
I need to extract some data from a CSV file. The CSV is a 2 column file with multiple records. The first column is the date, the second column is the data that needs to be extracted. The first row of the CSV file is the column headers, so it can be skipped. And I've already created the column header for the extracted data's csv file,...
I would like to time how long it takes to submit a batch of files to an HTTP server running on localhost using Curl and write that to a file. I am having trouble getting the syntax correct.
export TIMEFORMAT="%R"
time -ao times.dat ( curl -v -d @1.batch -X POST $DB )
How can I accomplish this? I imagine it's just a matter of using the...
Hi ,
I tried to remove around 7,000 log files under a directory by using
rm *.log
but failed with error message "too long argument list" . Is there any way to slove it ?
thanks .
...
Hi,
We have a Linux Daemon in c and a bash script to start it. The daemon sometimes fail to start because of some configuration file errors but the script reports the daemon was started successfully. A snippet of the script is shown as below, could someone tell me what's wrong with the script?
...
case "$1" in
start)
echo -n "Starting ...