89 Answered Questions for the topic UNIX

Unix Linux Bash

05/05/19

How do I write stderr to a file while using "tee" with a pipe?

I know how to use `tee` to write the output (`STDOUT`) of `aaa.sh` to `bbb.out`, while still displaying it in the terminal: ./aaa.sh | tee bbb.out How would I now also write `STDERR` to a file... more
Unix Linux Vi

05/05/19

Getting root permissions on a file inside of vi?

Often while editing config files, I'll open one with vi and then when I go to save it realize that I didn't type sudo vi filename Is there any way to give vi sudo privileges to save the file? I... more

05/05/19

How to make the 'cut' command treat same sequental delimiters as one?

I'm trying to extract a certain (the fourth) field from the column-based, 'space'-adjusted text stream. I'm trying to use the `cut` command in the following manner: `cat text.txt | cut -d " " -f... more

05/04/19

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... more
Unix Shell

05/03/19

Unix shell script find out which directory the script file resides?

Basically I need to run the script with paths related to the shell script file location, how can I change the current directory to the same directory as where the script file resides?
Unix Bash Shell Awk

05/03/19

Bash tool to get nth line from a file?

Is there a "canonical" way of doing that? I've been using `head -n | tail -1` which does the trick, but I've been wondering if there's a Bash tool that specifically extracts a line (or a range of... more
Unix Cut Bash

05/03/19

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

05/02/19

sometimes my file just freezes in my vi |vim, what happened?

Sometimes when I edit my file using vi or vim, my file just freezes. Even if I type <kbd>Ctrl+C</kbd> or <kbd>Ctrl+D</kbd>, it still freezes there. I `kill -9 <pid>`... more

05/01/19

How can I copy the output of a command directly into my clipboard?

How can I pipe the output of a command into my clipboard and paste it back when using a terminal? For instance: cat file | clipboard

04/29/19

Java: Date from unix timestamp?

I need to convert a unix timestamp to a date object. I tried this: java.util.Date time = new java.util.Date(timeStamp); Timestamp value is: `1280512800` The Date should be "2010/07/30 -... more

04/28/19

What do 'real', 'user' and 'sys' mean in the output of time(1)?

$ time foo real 0m0.003s user 0m0.000s sys 0m0.004s $ What do 'real', 'user' and 'sys' mean in the output of time? Which one is meaningful when benchmarking my app?
Unix Linux Sed

04/28/19

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 ... more
Unix Vim

04/28/19

What does ^M character mean in Vim?

I keep getting `^M` character in my vimrc and it breaks my configuration.

04/27/19

Is there a way to make mv create the directory to be moved to if it doesn't exist?

So, if I'm in my home directory and I want to move foo.c to ~/bar/baz/foo.c , but those directories don't exist, is there some way to have those directories automatically created, so that you would... more
Unix Find Shell

04/27/19

find without recursion?

Is it possible to use the `find` command in some way that it will not recurse into the sub-directories? For example, DirsRoot |-->SubDir1 | |-OtherFile1 |-->SubDir2 | |-OtherFile2 ... more
Unix Linux Path File

04/20/19

How to get full path of a file?

Is there an easy way I can print the full path of `file.txt` ? file.txt = /nfs/an/disks/jj/home/dir/file.txt The `<command>` dir> <command> file.txt should print ... more

04/20/19

Restarting cron after changing crontab file?

Do I have to restart cron after changing the crontable file?

04/20/19

How to grep a string in a directory and all its subdirectories' files in LINUX?

How to grep a string or a text in a directory and all its subdirectories'files in LINUX ??

04/19/19

What do pty and tty mean?

I noticed there are many mentions of `pty` and `tty` in some opensource projects, could someone can tell me what do they mean and what is the difference between them? Thanks!

Where can I set environment variables that crontab will use?

I have a crontab running every hour. The user running it has environment variabless in the `.bash_profile` that work when the user runs the job from the terminal, however, obviously these don't get... more
Unix C Linux

04/11/19

Why does ENOENT mean "No such file or directory"?

What is "ENT" short for? The `error` : >No such file or directory should just be named by "ENOFILE". Is there any story or reason?

04/04/19

How do I syntax check a Bash script without running it?

Is it possible to check a bash script syntax without executing it? Using Perl, I can run `perl -c 'script name'`. Is there any equivalent command for bash scripts?

04/04/19

How to kill a process running on particular port in Linux?

I tried to close the tomcat using `./shutdown.sh` from tomcat `/bin` directory. But found that the server was not closed properly. And thus I was unable to restartMy tomcat is running on port... more
Unix C Fork Exec

04/03/19

Differences between fork and exec?

What are the differences between `fork` and `exec`?
Unix Linux Ssh

03/27/19

How to download a file from server using SSH?

I need to download a file from server to my desktop. (UBUNTU 10.04) I don't have a web access to the server, just ssh. If it helps, my OS is Mac OS X and iTerm 2 as a terminal.

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.