Questions tagged [unix]

NOTICE: All Unix questions must be related to programming; those that aren't will be closed. Use this tag only if your question relates to programming using Unix APIs or Unix-specific behavior, not just because you happen to run your code on Unix. General software issues should be directed to Unix & Linux Stack Exchange or to Super User.

Tag usage

The tag can be used for Unix system programming related problems. The tag can also contain programming questions about using the Unix platform. For non-programming Unix usage questions, visit the Unix & Linux Stack Exchange site.

Background

Unix was developed as an in-house operating system for AT&T, but in the 1980s became both a prime academic operating system (with U.C. Berkeley's version, called BSD, being the reference platform for development of what would become the Internet) and a commercial success in the form of AT&T's System V, Microsoft/SCO's XENIX (PCs) and various workstation versions from Sun, Silicon Graphics, and others.

In the 1990s, Sun's Solaris and the free Unix clone Linux would rise in popularity. Linux is largely Unix-compatible but lacks the trademark. Currently, Unix is commonly found on server platforms; the primary desktop variant is Mac OS X, based on BSD.

Apart from its command-line interface, most "Unices" support the standardized X Window System for GUIs. (So does Mac OS X, but its primary GUI is Apple's proprietary Quartz.)

The various Unix implementation (and to a lesser extent, clones such as Linux) are unified in a standard called POSIX. C has been its primary programming language since the 1970s, but many other languages are available.

Read more

47509 questions
24
votes
8 answers

Getting PID of process in Shell Script

I am writing one shell script and I want to get PID of one process with name as "ABCD". What i did was : process_id=`/bin/ps -fu $USER|grep "ABCD"|awk '{print $2}'` This gets PID of two processes i.e. of process ABCD and the GREP command itself…
Mayank Jain
  • 2,504
  • 9
  • 33
  • 52
24
votes
2 answers

What is there behind a symbolic link?

How are symbolic links managed internally by UNIX/Linux systems. It is known that a symbolic link may exist even without an actual target file (Dangling link). So what is that which represents a symbolic link internally. In Windows, the answer is a…
Aravind
  • 555
  • 1
  • 3
  • 12
24
votes
8 answers

Is there a good way to detect a stale NFS mount

I have a procedure I want to initiate only if several tests complete successfully. One test I need is that all of my NFS mounts are alive and well. Can I do better than the brute force approach: mount | sed -n "s/^.* on \(.*\) type nfs .*$/\1/p" |…
Chen Levy
  • 15,438
  • 17
  • 74
  • 92
24
votes
12 answers

shell script: bad interpreter: No such file or directory when using pwd

I want to go through the files in a directory with a for loop but this comes up. echo: bad interpreter: No such file or directory code: #!/bin/bash count=0 dir=`pwd` echo "$dir" FILES=`ls $dir` for file in $FILES do if [ -f $file ] then …
Alek
  • 299
  • 2
  • 4
  • 12
24
votes
1 answer

Naming the legend entry in Gnuplot, while plotting from a data file

I am plotting a data file with six columns in gnuplot. If the plot of column 2 against column 1 is x(t), I want that line in the legend something like x(t), NOT what I currently get for column two against column one, "trial.dat" u 1:2. How would I…
user1535776
  • 599
  • 2
  • 5
  • 10
24
votes
3 answers

In C how do you redirect stdin/stdout/stderr to files when making an execvp() or similar call?

I have the following code: pid_t pid = fork(); if (pid == -1) { // ... } else if (pid == 0) { stdin = someopenfile; stdout = someotherfile; stderr = somethirdopenfile; execvp(args[0], args); // handle error ... } else { …
Matt
  • 21,026
  • 18
  • 63
  • 115
24
votes
5 answers

How to remove setgid (linux/unix)?

I just changed my file permissions using $ sudo chmod g+s filename and my file permissions turned from drwxr-xr-x to drwxr-sr-x. How do I remove it?
bigpotato
  • 26,262
  • 56
  • 178
  • 334
24
votes
4 answers

Creating a string variable name from the value of another string

In my bash script I have two variables CONFIG_OPTION and CONFIG_VALUE which contain string VENDOR_NAME and Default_Vendor respectively. I need to create a variable with name $CONFIG_OPTION ie VENDOR_NAME and assign the value in CONFIG_VALUE to newly…
NeonGlow
  • 1,659
  • 4
  • 18
  • 36
24
votes
2 answers

What content do -shm and -wal files contain after running checkpoint?

I am taking the backup of SQLite DB using cp command after running wal_checkpoint(FULL). The DB is being used in WAL mode so there are other files like -shm and -wal in my folder. When I run wal_checkpoint(FULL), the changes in WAL file get…
Manik Sidana
  • 2,005
  • 2
  • 18
  • 29
24
votes
5 answers

unix cat multiple files - don't cause error if one doesn't exist?

I'm trying to cat a bunch of files, some of which may not exist. Now that's ok if some of them don't exist, but I don't want cat to return an error in this case, if possible. Here's my call: zcat *_max.rpt.gz *_min.rpt.gz | gzip > temp.rpt.gz When…
JDS
  • 16,388
  • 47
  • 161
  • 224
24
votes
3 answers

grep limited characters - one line

I want to look up a word in multiple files, and return only a single line per result, or a limited number of characters (40 ~ 80 characters for example), and not the entire line, as by default. grep -sR 'wp-content'…
Patrick Maciel
  • 4,874
  • 8
  • 40
  • 80
23
votes
10 answers

Change extension of file using shell script

How to change extension of all *.dat files in a directory to *.txt. Shell script should take the directory name as an argument. Can take multiple directories as arguments. Print the log of command result in appending mode with date and timestamp.
Mainak
  • 311
  • 2
  • 4
  • 7
23
votes
5 answers

Run a persistent process via ssh

I'm trying to start a test server via ssh but it always dies once i disconnect from ssh. Is there a way to start a process (run the server) so it doesn't die upon the end of my ssh session?
9-bits
  • 10,395
  • 21
  • 61
  • 83
23
votes
4 answers

Allow request coming from specific IP only

I have application hosted Apache UNIX, and I am allowing users to access the application url from citrix environment (from citrix machine). However, currently its possible to access the url from all the connected machines. I would like to put the…
Mutant
  • 3,663
  • 4
  • 33
  • 53
23
votes
2 answers

Why does printf() in the parent almost always win the race condition after fork()?

There is a somewhat famous Unix brain-teaser: Write an if expression to make the following program print Hello, world! on the screen. The expr in if must be a legal C expression and should not contain other program structures. if (expr) …
比尔盖子
  • 2,693
  • 5
  • 37
  • 53