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
596
votes
29 answers

Linux: copy and create destination dir if it does not exist

I want a command (or probably an option to cp) that creates the destination directory if it does not exist. Example: cp -? file /path/to/copy/file/to/is/very/deep/there
flybywire
  • 261,858
  • 191
  • 397
  • 503
593
votes
8 answers

How to do a logical OR operation for integer comparison in shell scripting?

I am trying to do a simple condition check, but it doesn't seem to work. If $# is equal to 0 or is greater than 1 then say hello. I have tried the following syntax with no success: if [ "$#" == 0 -o "$#" > 1 ] ; then echo "hello" fi if [ "$#" == 0…
Strawberry
  • 66,024
  • 56
  • 149
  • 197
591
votes
13 answers

What are file descriptors, explained in simple terms?

What would be a more simplified description of file descriptors compared to Wikipedia's? Why are they required? Say, take shell processes as an example and how does it apply for it? Does a process table contain more than one file descriptor. If…
Nishant
  • 20,354
  • 18
  • 69
  • 101
587
votes
10 answers

Aborting a shell script if any command returns a non-zero value

I have a Bash shell script that invokes a number of commands. I would like to have the shell script automatically exit with a return value of 1 if any of the commands return a non-zero value. Is this possible without explicitly checking the result…
Jin Kim
  • 16,562
  • 18
  • 60
  • 86
572
votes
12 answers

Restarting cron after changing crontab file?

Do I have to restart cron after changing the crontable file?
bArmageddon
  • 8,088
  • 6
  • 22
  • 40
551
votes
5 answers

What are .a and .so files?

I'm currently trying to port a C application to AIX and am getting confused. What are .a and .so files and how are they used when building/running an application?
Dunc
  • 7,688
  • 10
  • 31
  • 38
534
votes
22 answers

grep a tab in UNIX

How do I grep tab (\t) in files on the Unix platform?
Sachin
  • 20,805
  • 32
  • 86
  • 99
522
votes
14 answers

What's a concise way to check that environment variables are set in a Unix shell script?

I've got a few Unix shell scripts where I need to check that certain environment variables are set before I start doing stuff, so I do this sort of thing: if [ -z "$STATE" ]; then echo "Need to set STATE" exit 1 fi if [ -z "$DEST" ];…
AndrewR
  • 10,759
  • 10
  • 45
  • 56
520
votes
5 answers

How can I assign a name for a screen?

I'm using the Screen multiplexer tool on the command shell and open a lot of screens. I then forget which process ID associates with which task. I would like to set a name for a screen, but I can't find an option in the man page. Currently, listing…
spankmaster79
  • 21,555
  • 10
  • 42
  • 73
519
votes
5 answers

Why is 1/1/1970 the "epoch time"?

Why is 1 January 1970 00:00:00 considered the epoch time?
rahul
  • 184,426
  • 49
  • 232
  • 263
514
votes
17 answers

Equivalent of *Nix 'which' command in PowerShell?

How do I ask PowerShell where something is? For instance, "which notepad" and it returns the directory where the notepad.exe is run from according to the current paths.
DevelopingChris
  • 39,797
  • 30
  • 87
  • 118
500
votes
15 answers

sed edit file in-place

How do I edit a file in a single sed command? Currently, I have to manually stream the edited content into a new file and then rename the new file to the original file name. I tried sed -i, but my Solaris system said that -i is an illegal option. …
amphibient
  • 29,770
  • 54
  • 146
  • 240
496
votes
17 answers

Delete empty lines using sed

I am trying to delete empty lines using sed: sed '/^$/d' but I have no luck with it. For example, I have these lines: xxxxxx yyyyyy zzzzzz and I want it to be like: xxxxxx yyyyyy zzzzzz What should be the code for this?
jonas
  • 5,259
  • 4
  • 16
  • 11
494
votes
12 answers

How can I grep for a string that begins with a dash/hyphen?

I want to grep for the string that starts with a dash/hyphen, like -X, in a file, but it's confusing this as a command line argument. I've tried: grep "-X" grep \-X grep '-X'
Mike
  • 58,961
  • 76
  • 175
  • 221
475
votes
4 answers

Unlimited Bash History

I want my .bash_history file to be unlimited. e.g. So I can always go back and see how I built/configured something, or what that nifty command was, or how some command broke something weeks ago. How do I change this setting?
Francis Haart
  • 5,083
  • 3
  • 16
  • 13