Skip to content
Advertisement

Tag: shell

Checking for installed packages and if not found install

I need to check for installed packages and if not installed install them. Example for RHEL, CentOS, Fedora: How do I do a check in BASH? Do I do something like? And what do I need to use for other distributions? apt-get? Answer Try the following code : or shorter : For debian likes : For archlinux :

Count lines in large files

I commonly work with text files of ~20 Gb size and I find myself counting the number of lines in a given file very often. The way I do it now it’s just cat fname | wc -l, and it takes very long. Is there any solution that’d be much faster? I work in a high performance cluster with Hadoop

How to check if sed has changed a file

I am trying to find a clever way to figure out if the file passed to sed has been altered successfully or not. Basically, I want to know if the file has been changed or not without having to look at the file modification date. The reason why I need this is because I need to do some extra stuff

check if argument is a valid date in bash shell

I am writing a bash shell script in Linux, this program will accept a date (mm-dd-yyyy) as a parameter. I am wondering if there is a simply way to check if the date is valid? is there an operator and I can just use test to check? Answer You can check with date -d “datestring” So date -d “12/31/2012” is

Switch maven version – mvn command does not get bound

I’m trying to switch maven from 2 to 3 (on Linux) using: Anyway mvn -v still gives version 2, so I always have to execute /path/to/maven3/bin/mvn to use maven. How can I rebind the mvn command to the appropriate maven path? Answer which mvn And then recreate symbolic link to point on new Maven version. And verify than environment variable

How to gzip all files in all sub-directories in bash

I want to iterate among sub directories of my current location and gzip each file seperately. For zipping files in a directory, I use but this can just work on current directory and not the sub directories of the current directory. How can I rewrite the above statements so that It also zips the files in all subdirectories? Answer No

Assignment of variables in shell scripting

I am trying to write a shell script to simulate the following problem: File A contains some entries like and File B contains the final file should have (contents of file b which are not there in file a) I was trying something like this but it’s not working: Answer You code has some errors: forgot the closure of if

Advertisement