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
474
votes
5 answers

Going to a specific line number using Less in Unix

I have a file that has around million lines. I need to go to line number 320123 to check the data. How do I do that?
Stole
  • 4,978
  • 3
  • 20
  • 18
471
votes
21 answers

Concatenate multiple files but include filename as section headers

I would like to concatenate a number of text files into one large file in terminal. I know I can do this using the cat command. However, I would like the filename of each file to precede the "data dump" for that file. Anyone know how to do…
Nick
  • 5,411
  • 4
  • 19
  • 7
451
votes
13 answers

Can I export a variable to the environment from a Bash script without sourcing it?

Suppose that I have this script: export.bash: #! /usr/bin/env bash export VAR="HELLO, VARIABLE" When I execute the script and try to access to the $VAR, I don't get any value! echo $VAR Is there a way to access the $VAR by just executing…
Salah Eddine Taouririt
  • 24,925
  • 20
  • 60
  • 96
445
votes
14 answers

What is the cleanest way to ssh and run multiple commands in Bash?

I already have an ssh agent set up, and I can run commands on an external server in Bash script doing stuff like: ssh blah_server "ls; pwd;" Now, what I'd really like to do is run a lot of long commands on an external server. Enclosing all of these…
Eli
  • 36,793
  • 40
  • 144
  • 207
444
votes
9 answers

Extract file basename without path and extension in bash

Given file names like these: /the/path/foo.txt bar.txt I hope to get: foo bar Why this doesn't work? #!/bin/bash fullfile=$1 fname=$(basename $fullfile) fbname=${fname%.*} echo $fbname What's the right way to do it?
neversaint
  • 60,904
  • 137
  • 310
  • 477
439
votes
23 answers

How to convert DOS/Windows newline (CRLF) to Unix newline (LF)

How can I programmatically (not using vi) convert DOS/Windows newlines to Unix newlines? The dos2unix and unix2dos commands are not available on certain systems. How can I emulate them with commands such as sed, awk, and tr?
Koran Molovik
  • 4,415
  • 3
  • 16
  • 3
438
votes
19 answers

Shell script - remove first and last quote (") from a variable

Below is the snippet of a shell script from a larger script. It removes the quotes from the string that is held by a variable. I am doing it using sed, but is it efficient? If not, then what is the efficient…
user1263746
  • 5,788
  • 4
  • 24
  • 28
438
votes
3 answers

What does `set -x` do?

I have a shell script with the following line in it: [ "$DEBUG" == 'true' ] && set -x
Ole
  • 41,793
  • 59
  • 191
  • 359
437
votes
31 answers

How to get the primary IP address of the local machine on Linux and OS X?

I am looking for a command line solution that would return me the primary (first) IP address of the localhost, other than 127.0.0.1 The solution should work at least for Linux (Debian and RedHat) and OS X 10.7+ I am aware that ifconfig is available…
sorin
  • 161,544
  • 178
  • 535
  • 806
435
votes
13 answers

How do I escape spaces in path for scp copy in Linux?

I want to copy a file from remote to local system. Now I'm using scp command in linux system. I have some folders or files names are with spaces, when I try to copy that file, it shows the error message: "No such file or directory". I tried: scp…
AlexPandiyan
  • 4,467
  • 2
  • 14
  • 11
430
votes
8 answers

How can I format my grep output to show line numbers at the end of the line, and also the hit count?

I'm using grep to match string in a file. Here is an example file: example one, example two null, example three, example four null, grep -i null myfile.txt returns example two null, example four null, How can I return matched lines together with…
London
  • 14,986
  • 35
  • 106
  • 147
425
votes
16 answers

How do I grep for all non-ASCII characters?

I have several very large XML files and I'm trying to find the lines that contain non-ASCII characters. I've tried the following: grep -e "[\x{00FF}-\x{FFFF}]" file.xml But this returns every line in the file, regardless of whether the line…
pconrey
  • 5,805
  • 7
  • 29
  • 38
420
votes
9 answers

How do I use the nohup command without getting nohup.out?

I have a problem with the nohup command. When I run my job, I have a lot of data. The output nohup.out becomes too large and my process slows down. How can I run this command without getting nohup.out?
Ofer
  • 4,879
  • 6
  • 20
  • 26
418
votes
19 answers

How can I find encoding of a file via a script on Linux?

I need to find the encoding of all files that are placed in a directory. Is there a way to find the encoding used? The file command is not able to do this. The encoding of interest to me is ISO 8859-1. If the encoding is anything else, I want to…
Manglu
  • 10,744
  • 12
  • 44
  • 57
412
votes
8 answers

Use space as a delimiter with cut command

I want to use space as a delimiter with the cut command. What syntax can I use for this?
Jaelebi
  • 5,879
  • 8
  • 32
  • 34