bash

Learning bash?

I am currently learning java. But I always see mentioned that you should learn one programming language a year. So my question is it ok to learn bash with java or should I wait a year before I tackle it? ...

Applying AWK on Set of Files with Same Extension

I want to apply the following "awk" command on files with extension "*.txt" awk '$4 ~ /NM/{ sum += $2 } END{ print sum }' But why this command doesn't work: for i in *.txt do echo awk '$4 ~ /NM/{ sum += $2 } END{ print sum }' $i; done Normally, awk '$4 ~ /NM/{ sum += $2 } END{ print sum }' file1.txt would work. ...

Favourite command line trick

bash, bat, whatever... What is your favourite command line hyperproductivity trick? ...

How can I ssh directly to a particular directory?

I often have to login to one of several servers and go to one of several directories on those machines. Currently I do something of this sort: localhost ~]$ ssh somehost Welcome to somehost! somehost ~]$ cd /some/directory/somewhere/named/Foo somehost Foo]$ I have scripts that can determine which host and which directory I need t...

Is there a shell command to recursively give permission to directories and files?

Can someone please give me a recursive command that will go through a directory and make all normal files permission 644 and all sub directories 755? I am really getting tired of doing this manually every time I have to install something on my host. I don't know enough BASH (Shell?) command to do this. ...

Filter directory listing with shell script

If I have a BASH variable: Exclude="somefile.txt anotherfile.txt" How can I get the contents of a directory but exclude the above to files in the listing? I want to be able to do something like: Files= #some command here someprogram ${Files} someprogram should be given all of the files in a particular directory, except for those i...

Moving All Files From Directories One Step Up

Dear all, I have a directories that look like this fool@brat:/mydir/ucsc_mm8> tar -xvf *.tar 1/chr1.fa.masked 1/chr1_random.fa.masked 2/chr2.fa.masked 3/chr3.fa.masked 4/chr4.fa.masked 5/chr5.fa.masked 5/chr5_random.fa.masked 19/chr19.fa.masked Un/chrUn_random.fa.masked What I want to do is to move out all the "*.masked" files in th...

UNIX command to list folders with file counts

I want to get a list of folders at the current level (not including their subfolders) and simply print the folder name and a count of the number of files in the folder (preferably filtering to *.jpg if possible). Is this possible in the standard bash shell? ls -l prints about everything but the file count :) ...

Unable to move pictures from Desktop to a specific folder

I have pictures from Picture_1.png to Picture_77.png in my Desktop. I am now at a folder called Pictures in terminal. I would like to move the pictures to the folder where I am at the moment. I tried the following code unsuccessfully mv Picture_[1-77].png I am not sure what I should add for the target folder because I am at the targ...

Unable to scp from my server to my computer

The following code does not work scp /home/username/public_html/site/pictures/* myUsernameAtMyMac@myIpAddress:/home/Masi/Desktop/ I have "Allow only essential services" in my Mac's firewall. How can you solve the problem? [edit] I get the following error after I have "Remote Login" in the list of allowed services. I also allowed "A...

Unable to put a .txt -file to the end of another .txt -file

How can I put .Txt file A at the end of .Txt file B in terminal without opening the files? ...

Determine the path of the executing BASH script

In a Windows command script, one can determine the directory path of the currently executing script using %~dp0. For example: @echo Running from %~dp0 What would be the equivalent in a BASH script? ...

Converting XCF and other files using command line with GIMP?

If I have an XCF file (or any other supported by Gimp) how can I convert it to, for example, PNG for display or further processing? ...

Force base_profile to run

When I login to a sun box: SunOS domain.com 5.8 Generic_117350-57 sun4u sparc SUNW,Sun-Fire-V240 I start in the sh shell: SHELL=/bin/sh I type bash to start a bash shell, then have to type . .bash_profile to load my profile. Is there a way it can be set to automatically load the profile? ...

Errors on beginner bash script

Hi guys, could u help me out? I run this on cygwin as ./test.sh and I get unexpected end of file on line 51. Any thoughts? Thx in advance LAST EDIT: final version 'runnin on CygWin, the problem was with the line break, CrLf instead Lf. #!/bin/sh ################################################## ## USAGE ##############################...

Bash history re-runs: possible command to avoid using !bang! ?

Scenario: You are doing your daily Bash shell stuff. You want to run a previous command so you type: history | grep foocommand Then you get a list of all the foocommand stuff you did for however long your history has kept track, in a list like so: 585 foocommand --baz --bleet 750 foocommand | grep quux 987 history grep | fooco...

What is the XDG_SESSION_COOKIE environment variable for?

Hi all. I've been fighting with crontab recently because in Intrepid the gconftool uses a dbus backend, and that means that when used from crontab it doesn't work. To make it work I have had to export the relevant environment variables when I log in so that it finds the dbus session address when the cron comes to run. Out of curiosity...

Unable to make a range of dummy files

I need to make files called from File1, File2, ... to File99. I tried the following unsuccessfully cat test > {File1 .. File99} The command without the word File did not work. ...

Default encoding for python for stderr?

I've got a noisy python script that I want to silence by directing its stderr output to /dev/null (using bash BTW). Like so: python -u parse.py 1> /tmp/output3.txt 2> /dev/null but it quickly exits prematurely. Hmm. I can't see the traceback because of course that goes out with stderr. It runs noisily and normally if I don't direct ...

Redirect stderr and stdout in a bash script

I want to redirect both stdout and stderr of a process to a single file. How do I do that in bash? ...