Find an Online Tutor Now

60 Answered Questions for the topic UNIX


What is the Windows equivalent of the Unix command cat? ?

I want to do exactly what unix "cat" does, but on my PC. Is there a simple equivalent command for the Windows command line? Specifically I want to create a file from all the files of a given type... more
Unix Pi Algorithm


What is the fastest way to get the value of π?

I'm looking for the fastest way to obtain the value of π, as a personal challenge. More specifically, I'm using ways that don't involve using `#define` constants like `M_PI`, or hard-coding the... more
Unix Shell Vim


Delete newline in Vim?

Is there a way to delete the newline at the end of a line in Vim, so that the next line is appended to the current line? For example: Evaluator<T>(): _bestPos(){ } I'd like to put this... more
Unix Linux Bash


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... more
Unix Linux Diff


Given two directory trees, how can I find out which files differ?

If I want find the differences between two directory trees, I usually just execute: diff -r dir1/ dir2/ This outputs exactly what the differences are between corresponding files. I'm interested... more
Unix Linux Bash


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, ... more


Unix: How to check permissions of a specific directory?

I know that using `ls -l "directory/directory/filename"` tells me the permissions of a file. How do I do the same on a directory? I could obviously use `ls -l` on the directory higher in the... more
Unix Bash Shell


How to represent multiple conditions in a shell if statement?

I want to represent multiple conditions like this: if [ ( $g -eq 1 -a "$c" = "123" ) -o ( $g -eq 2 -a "$c" = "456" ) ] then echo abc; else echo efg; fi but when I execute the script,... more
Unix File Newline


Why should text files end with a newline?

I assume everyone here is familiar with the adage that all text files should end with a newline. I've known of this "rule" for years but I've always wondered — why?


How can I extract a predetermined range of lines from a text file on Unix?

I have a ~23000 line SQL dump containing several databases worth of data. I need to extract a certain section of this file (i.e. the data for a single database) and place it in a new file. I know... more


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?


Remove carriage return in Unix?

What is the simplest way to remove all the carriage returns `\\r` from a file in Unix?
Unix Terminal Cat


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
Unix Arrays Bash


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
Unix Grep


grep a tab in UNIX?

How do I `grep` tab (\ ) in files on the Unix platform?
Unix Linux Shell


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 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?
Unix Linux Windows


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
Unix Bash File


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
Unix Shell Sh


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


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
Unix Linux


How to list all users in a Linux group?

How do I list all members of a group in Linux (and possibly other unices)?
Unix Linux Bash


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?
Unix C Linux


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
Unix Linux Grep


How can I exclude directories from grep -R?

I want to traverse all subdirectories, except the "node_modules" directory.
1 3

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.


Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.