unix

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 :) ...

How to code in the unix spirit? (small single task tools)

Hello, I have written a little script which retrieves pictures and movies from my camera and renames them based on their date and then copies them on my harddrive, managing conflicts automatically (same name? same size? same md5?) Works pretty well. But this is ONE script. From time to time I need to check if a picture is already hidde...

Ignoring SIGCHLD in some cases but not others

In my program, I fork() several times depending on user input. In certain instances, I want to handle SIGCHLD and say something like "Process # Finished". In other cases though, I want to ignore this signal. How can I do this? ...

Algorithm for Counting Sorted Strings (Homebrew "uniq -c")

Hi all, I have the following already sorted data: AAA AAA TCG TTT TTT TTT I want to count the occurrence of each string yielding AAA 2 TCG 1 TTT 3 I know I can do that with "uniq -c", but here I need to do extra processing on the overall C++ code I have. I am stuck with this construct (modified according to 'pgras' suggestion) #...

zcat pipe to grep

ls -ltr|grep 'Mar 4'| awk '{print $9 }'|zcat -fq |grep 12345 I want to find all files modified on a certain date and then zcat them and search the fiels for a number string. the above doesn't work because it searches the file name for the string not the file itself. Any help? M ...

zcat to grep with file name

ls -ltr|grep 'Mar 4'| awk '{print $9 }'|xargs zcat -fq |grep 12345 I'm now using this command to list the records that contain my numeric string how can i alos get this command to print the name of the file the strings were found in? thanks ...

How to detemine the file type in Linux?

If someone sends me a document (.pdf,.doc,.xls, ppt, .ogg, mp3, png, etc) without the extension, how can I determine the file type? The /usr/bin/file command doesn't always guess right or it simply says that I have a Microsoft Office document. I would like to know exactly so I can add the extension to the file name. ...

ksh: how to probe stdin?

I want my ksh script to have different behaviors depending on whether there is something incoming through stdin or not: (1) cat file.txt | ./script.ksh (then do "cat <&0 >./tmp.dat" and process tmp.dat) vs. (2) ./script.ksh (then process $1 which must be a readable regular file) Checking for stdin to see if it is a terminal[ -t 0...

What are best practices for permissions on Apache-writable directories?

Sometimes I want to allow users to upload files through Apache. There are two different ways I could set the permissions so that Apache can write the uploaded files to the directory. I can make the user Apache is running as the owner of the directory so that it looks like this: drwxr-xr-x 2 www admin 68 Sep 24 2007 uploade...

Encoding Keyboard Command Onto Bash Script

Dear all, I have the following way to submit a job with cluster using qsub: Submitting jobs from standard input To submit a PBS job by typing job specifications at the command line, the user types qsub [options] <return> then types any directives, then any tasks, followed by (in UNIX) C...

Shared library terminology

What is the difference between "shared library text" and "shared library data"? Also, what does it mean for shared library data to be "pre-relocated"? This question is in reference to a couple of AIX-specific features involving shared libraries. http://publib.boulder.ibm.com/infocenter/systems/topic/com.ibm.aix.genprogc/doc/genprogc/...

Can you prevent a command from going into the bash shell command history?

Is there a way to prevent a command from being added to the bash shell's command history? I would like to be able to prevent certain "dangerous" commands from being added to the history, such as "rm -rf ~/some/dir", so that it is not accessible to me by pressing the up-arrow to reach previous commands. In this way, it would not be poss...

POSIX Semaphores on Mac OS X: sem_timedwait alternative

I am trying to port a project (from linux) that uses Semaphores to Mac OS X however some of the posix semaphores are not implemented on Mac OS X The one that I hit in this port is sem_timedwait() I don't know much about semaphores but from the man pages sem_wait() seems to be close to sem_timedwait and it is implemented From the man p...

Ruby: In unix find if user who executed the program is root

Hi, I'm writing a rake script and would like to detect (using Ruby rather than bash if possible) if the user who executed the rake script has root privileges. If it is not root then I would like to terminate the script. Regards, Chris ...

Convert Unix path to DOS path in a Korn shell script

I have a variable that stores a Unix path, for example: typeset unixpath=/foo/bar/ And I have to convert it to a DOS path using Korn shell scripting: dospath=\\foo\\bar\\ ...

Changing unix group for files

I have a file that a colleague and I are editing together, on a unix system. We are using unix group permissions to edit it. We have one unix group that we are both members of. Whenever I save the file, it changes the unix group to one that he is not a member of. Is there any way to stop it from doing that? ...

How to keep a file's format if you use the uniq command (in shell)?

In order to use the uniq command, you have to sort your file first. But in the file I have, the order of the information is important, thus how can I keep the original format of the file but still get rid of duplicate content? ...

Append name of parent folders and subfolders to the names of the multiple files

I have folders and subfolders with 10K photos in them. Now I need to put all 10K files into one folder. I want to append the folder and subfolder name with the existing file name so that the file name becomes meaningful to me. I need help ...

Best way to determine uniqueness and repetition in a text file.

I have a text file of about 20 million lines. Each line is 25 characters long. I estimate that there are probably about 200k-300k unique lines. What I want to find out is exactly how many unique lines there are, and how many occurrences of each line there are (I expect the result to be power-law-esque). I could do this: sort bigfile...