89 Answered Questions for the topic UNIX
In Unix, can I run 'make' in a directory without cd'ing to that directory first?
In Unix, can I run 'make' in a directory without cd'ing to that directory first?
Unix Carriage Return
05/26/19
Remove carriage return in Unix?
What is the simplest way to remove all the carriage returns `\\r` from a file in Unix?
05/26/19
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...
more
Loop through an array of strings in Bash?
I want to write a script that loops through 15 strings (array possibly?) Is that possible?
Something like:
for databaseName in listOfNames
then
# Do something
end
05/26/19
How to assign 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 can't...
more
What are the uses of the exec command in shell scripts?
Can anyone explain what are the uses of the exec command in shell scripting with simple examples?
05/22/19
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 get no value !
echo $VAR
...
more
05/22/19
What does "opt" mean (as in the "opt" directory)? Is it an abbreviation?
What does "opt" mean (as in the "opt" directory)? I commonly see this directory in Unix systems with development tools inside.
Is it an abbreviation?
How to convert DOS/Windows newline (CRLF) to Unix newline (LF) in a Bash script?
How can I programmatically (i.e., not using `vi`) convert DOS/Windows newlines to Unix?
The `dos2unix` and `unix2dos` commands are not available on certain systems. How can I emulate these with...
more
05/21/19
How to do a logical OR operation 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 [...
more
How to split a large text file into smaller files with equal number of lines?
I've got a large (by number of lines) plain text file that I'd like to split into smaller files, also by number of lines. So if my file has around 2M lines, I'd like to split it up into 10 files...
more
How to read a file into a variable in shell?
I want to read a file and save it in variable, but I need to keep the variable and not just print out the file.
How can I do this? I have written this script but it isn't quite what I needed:
...
more
05/18/19
How can I reverse the order of lines in a file?
I'd like to reverse the order of lines in a text file (or stdin), preserving the contents of each line.
So, i.e., starting with:
foo
bar
baz
I'd like to end up with
baz
bar
foo
Is there...
more
How to find encoding of a file in Unix via script(s)?
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 that is of interest to...
more
Unix Linux
05/16/19
How to list all users in a Linux group?
How do I list all members of a group in Linux (and possibly other unices)?
How can I recall the argument of the previous bash command?
Is there a way in Bash to recall the argument of the previous command?
I usually do `vi file.c` followed by `gcc file.c`.
Is there a way in Bash to recall the argument of the previous command?
C fopen vs open?
Is there any reason (other than syntactic ones) that you'd want to use FILE *fdopen(int fd, const char *mode);or FILE *fopen(const char *path, const char *mode);instead of int open(const...
more
How can I exclude directories from grep -R?
I want to traverse all subdirectories, except the "node_modules" directory.
Replacing some characters in a string with another character?
I have a string like
<!-- language: lang-none -->
AxxBCyyyDEFzzLMN
I want to replace all `x` and `y` and `z` with `_` so that the output is
A_BC_DEF_LMN
How to do that?
I know a...
more
Copying files across computers using SSH and MAC OS X Terminal?
I'm trying to copy my .profile, .rvm and .ssh folders/files to a new computer and I know how to use the `cp` and `ssh` commands but I'm not sure how to use them in order to transfer files from one...
more
05/11/19
What is a bus error?
What does the "bus error" message mean, and how does it differ from a segfault?
05/11/19
What does the number in parentheses shown after Unix command names in manpages mean?
For example: man(1), find(3), updatedb(2)? What do the numbers in parentheses (Brit. "brackets") mean?
05/06/19
Argument list too long error for rm, cp, mv commands?
I have several hundred PDFs under a directory in UNIX. The names of the PDFs are really long (approx. 60 chars).
When I try to delete all PDFs together using the following command:
rm -f...
more
What are the differences between .so and .dylib on osx?
.dylib is the dynamic library extension on OSX, but it's never been clear to me when I can't / shouldn't use a traditional unix .so shared object.Some of the questions I have: - At a conceptual...
more
Still looking for help? Get the right answer, fast.
Ask a question for free
Get a free answer to a quick problem.
Most questions answered within 4 hours.
OR
Find an Online Tutor Now
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.