The shell is unix's command-line interface. You can type commands in a shell interactively, or write scripts to automate tasks. Use this tag for questions applying to /bin/sh and most compatible shells (ash, bash, ksh, zsh, …).

learn more… | top users | synonyms (1)

0
votes
1answer
28 views

Running a “scheduled”/delayed script as sudo on server, via ssh - and right before ssh exit

This would have probably been answered by Keep running a script via ssh, if I didn't have to run a command as superuser. Let me try with an example: say on my server, I have this script as ...
1
vote
3answers
53 views

Shell script to find and count total number of characters in all the files

How can I make a script that finds every file in your home directory that is less than 3 days old and then gets a count of the total number of characters in all of these files?
0
votes
1answer
30 views

Error while executing a.out from C shell

I am in my home directory. And there is an executable a.out in there. I want to execute it like- /bin/csh ~/a.out ^F^E@@@@@▒^A▒^A^H^C^D^B^B@^B@^\^\^A^A^E@@: Event not found. Its not that I cannot ...
1
vote
1answer
91 views

Set up graphic interface (desktop) for remote connection

I was assigned a CentOS VM that I manipulate through Putty. Everything I do to it is by command line so far, and I have admin rights to it. The VM is stored in the corporate data center served up by ...
0
votes
2answers
61 views

Use .sh or .bash extension for bash scripts?

(See Use #!/bin/sh or #!/bin/bash for Ubuntu-OSX compatibility and ease of use & POSIX) If I want my scripts to use the bash shell, does using the .bash extension actually invoke bash or does it ...
9
votes
4answers
474 views

Use #!/bin/sh or #!/bin/bash for Ubuntu-OSX compatibility and ease of use & POSIX

I know that I can use either as the first line of scripts to invoke the desired shell. Would #!/bin/sh be recommended if compatibility with all unix systems is an absolute requirement? In my case ...
0
votes
1answer
23 views

Can I treat all what I typed after a command as raw string?

I made a bash func for myself so I can through some words into a tree_hole file, it looks like this in bashrc: function th { echo -e "\n$@" >> /Users/zen1/zen/pythonstudy/tree_hole; } export -f ...
1
vote
4answers
50 views

Create copies of files in same directory

Lets say I have a directory with the following files: 1.txt 2.txt 3.txt I want to copy these and basically paste in the same directory making new files eg: 1.txt 1(1).txt 2.txt 2(1).txt 3.txt ...
0
votes
1answer
60 views

How to know, when a shell command running in the backround getting killed or died

I am running a shell command which is invoking an avconv session. The command is running as a background process. When the script starts executing I am doing a curl post to a url with the created ...
7
votes
2answers
261 views

How do redirection in a symbols work in a sequence?

I have file1, file2, file3. file1 contains 1 file2 contains 2 file3 contains 3 I use command cat file1 > file2 > file3 Results in: file1 1 file2 (contains nothing) file3 1 Why ...
0
votes
2answers
33 views

Integer input constraints

I want to make an input constraint on read: Terminal Shell; read x read y echo $(($x+$y)) I want to make a constraint of x, I want x to be -100 <= x <= 100. What's the command I insert ...
1
vote
3answers
65 views

Cronjob doesn't execute shell script, but when I am executing it standalone it works. Why?

Shell Type: >echo $SHELL /bin/ksh Cronjob : 15 * * * * /bin/ksh /wls_domains/resMGT/logs/bea/wlr3queuetransaction.sh > /wls_domains/resMGT/logs/bea/data/script.log The script is as below: ...
1
vote
1answer
59 views

Running init script which starts a deamon in background for reducing boot time?

I'm looking for ways to speed up the boot time on a single core embedded Linux system. Significant lag happens during start up of some custom daemons. Once they are up, they do run in the background, ...
4
votes
3answers
115 views

How to use GNU parallel effectively

Suppose I want to find all the matches in compressed text file: $ gzcat file.txt.gz | pv --rate -i 5 | grep some-pattern pv --rate used here for measuring pipe throughput. On my machine it's about ...
1
vote
0answers
33 views

Cannot change bash shell in Mac OS X

I'm trying to update bash shell on my Mac OS Mavericks. $ brew install bash $ which -a bash /bin/bash /usr/local/bin/bash $ which bash /bin/bash $ chsh -s /usr/local/bin/bash $ which bash /bin/bash ...
1
vote
2answers
59 views

How to extract a part of file name in unix/linux shell script

My file name is Oracle.2347263_testing_152607.csv I tried this : echo Oracle.2347263_testing_152607.csv | sed -e 's/.*G.//' \-e 's/.csv//' but I didn't get the result I expected. I want to ...
3
votes
1answer
73 views

Triple dot wildcards

I have a very large directory structure of source code that is very difficult to work with. I would like to run a tool to transform it to a Maven like structure that works better for me. When I have ...
13
votes
4answers
1k views

Write Python stdout to file immediately

When trying to write the stdout from a Python script to a text file (python script.py > log), the text file is created when the command is started, but the actual content isn't written until the ...
0
votes
1answer
79 views

“too many arguments in [ (test) statement”

this is my first "if-else" script on linux. It gives the error [: too many arguments Code: n=0 if [ $n % 2 -eq 0 ] then echo "even number" fi How to correct it.
2
votes
1answer
46 views

Multi-month view in calendar (cal) in OS X

I am hoping to run some of the commands listed in this article, e.g.: cal -3 which is supposed to show me the last month, this month, and next month. This command does not work in OS X. $ cal -3 ...
5
votes
4answers
262 views

How to move all files inside present subfolders up here

I have 50 folders with some subfolders too, with more than 1000 audio files total. I need to remove all subfolders and put all files in present level. Tried mv */* ./ but it complaints: argument list ...
15
votes
5answers
2k views

Generating a random password; why isn't this portable?

I want to generate a random password, and am doing it like so: </dev/urandom tr -dc [:print:] | head -c 64 On my laptop, which runs Ubuntu, this produces only printable characters, as intended. ...
4
votes
1answer
68 views

Unix: Problem with cmp command

Let me give you an idea of what I am doing. I am running a script that is doing basic OS processes for two systems Linux and SunOS. Well the first directory it runs is called sol0. The script puts ...
1
vote
1answer
33 views

Calling bash getopts from a function fails the 2nd time

I'm trying to parse arguments passed to a bash function using getopts inside that function. It works when the function is called for the first time but fails on all subsequent calls. Here is a simple ...
19
votes
2answers
998 views

Pipes, how do data flow in a pipeline?

I don't understand how the data flows in the pipeline and hope someone could clarify what is going on there. I thought a pipeline of commands processes files (text, arrays of strings) in line by line ...
2
votes
1answer
34 views

Intercept and modify commands in bash scripts

I have some scripts and some commands in the scripts are like this ./executable arg1 arg2 .. argn I want to change the above command to LD_PRELOAD=/some/lib ./executable my_arg1 my_argn arg1 arg2 ...
3
votes
2answers
63 views

Execute command after inotifywait established watches

Inside shell script (test.sh) I have inotifywait monitoring recursively some direcotry - "somedir": #!/bin/sh inotifywait -r -m -e close_write "somedir" | while read f; do echo "$f hi"; done When I ...
-1
votes
4answers
188 views

How do I list files ending in txt only on Unix?

I have a directory with nine files in it. 1 ending in .bat 2 ending in .bak 4 ending in .txt 2 ending in .xtxt My question is, how do i list only the files ending in txt, but without the period. ...
3
votes
3answers
54 views

How to bump file timestamps by 3 months (for a directory tree)?

I am looking at the touch command line utility (on Linux), and from the examples I found in tutorials, I see how one can bump the access or modification timestamp to a specified time, the current ...
0
votes
1answer
16 views

What port uses my backportpackage or bzr?

I am working in a company what uses Ubuntu Precise on the desktops behind a proxy. The Proxy is available in /etc/environment and set as: http_proxy, https_proxy, ftp_proxy, no proxy and their ...
0
votes
1answer
62 views

Bash escaping is confusing me

Lets say that I have a file (executable) called literally 'a\b'. It just echoes some stuff. Now I want to call that and I can do it by inputting user@machine:~/test$ ./a\\b into my console. Now ...
0
votes
1answer
32 views

Compare two files [closed]

I want to compare two files in which the data is delimited by a pipe |. Both the files have the same results but only few fields might vary. File 1: A|B|C|D File 2: A|B|F|D I want to compare ...
1
vote
2answers
47 views

List the files of another format while finding a certain name pattern

I had wanted to edit the txt files of videoA and videoB only if the movs files names contains the namespace -test For eg. videoDir |-videoA |- videoA_v001_test.mov |- ...
1
vote
1answer
31 views

What is the most Unix-y way to handle stdout for a backup command that might fail?

I am writing a utility/script (in Python, as it happens) to run on Linux, which backs up data from a remote server, and outputs to stdout. At the moment, I run this script on the hour from cron, and ...
0
votes
2answers
29 views

Root to the Minimal

I am building a script to automate and minimize access to root. I am going to try do it via SSH. I am currently having an issue using sed to replace UID and GID 0 shell to /sbin/nologin. Why am I ...
2
votes
1answer
12 views

CInt Configure Script: Syntax error at left parenthesis

I am trying to install CInt. When running ./configure, I get the following error: ./configure: 23: ./configure: Syntax error: "(" unexpected Here is the relevant section of configure: # configure ...
2
votes
1answer
54 views

How do I securely download files in shell scripting?

I am writing some shell scripts to automatically download software packages off my server and set them up on customer servers. At some point within the script, the download command is wget ...
1
vote
1answer
34 views

How to zip only files under multiple subdirectories?

I have a folder working and its structure is something like this - working/ 100/ 1/ 2/ 3/ 200/ 1/ 2/ 3/ 300/ 1/ 2/ 3/ And each of these 1 ...
2
votes
2answers
66 views

Export Command History into a Shell Script

Often I have complicated installation procedures to follow, like having to build dependencies for buildtools, to build dependencies for the application I wish to install from source. Once I have done ...
0
votes
1answer
20 views

Insert space at specified position in a file

I have this sample file: 234234|111||J1X0H8|SERP||R|D|666|M 234235|222||J1X0N5|SERP||C||555|M For each line, I need to insert a space after the 3rd character of the 4th column, like so: ...
-4
votes
2answers
49 views

How do I print all env vars beginning with the letter 'T'?

This was an exercise for a course I'm on and I got really stuck at frustrated. I think my main problem is I keep putting the ">>" the wrong way round and then getting stuck in an editor which I don't ...
1
vote
1answer
40 views

Save and restore terminal tabs with custom tabs title

I have a Terminal window with a dozen named tabs open *(gnome-terminal) I would like to save the current configuration and have it restored with names and directories. Is there a way to do this? I've ...
0
votes
2answers
64 views

Untar and gzip from multiple sub directories

I have a directory which consists of multiple sub-directories. Each subdirectory has a tar.gz file which on untar gives two files namely R1.fastq and R2.fastq. I want to untar the tar file and ...
0
votes
1answer
82 views

Opening a socket in Kali Linux using bash scripts

I know how to open a TCP or UDP socket in Ubuntu, with the following command : exec 3<>/dev/tcp/google.com/80 for example: we can open a TCP socket on port 80, but in Kali Linux there's no ...
1
vote
1answer
41 views

Is there a way to change the number of processors a program sees?

Is there any way I can trick a program into thinking the system has fewer processors? To explain: I am debugging a program that creates as many threads as it has processors, using ...
1
vote
1answer
53 views

Read a character from an x-y coordinate on the screen

Is there a way in bash to read a character from an x-y coordinate on the screen? This command would be something similar to cget 12 30 which would return the character at the 12th row and 30th ...
0
votes
2answers
33 views

redirect output from interface?

I am echoing an AT command to a modem interface (/dev/ttyUSB3) and the command runs successfully. For instance the below command works and has an output of OK: echo -e "ATZ\r" > /dev/ttyUSB3 I ...
0
votes
2answers
39 views

The best way to add Unix Shell variables to CURL GET request

Let’s say I use curl –X GET command with the following link: “$WEBSITE_URL/ACTION_NAME/ACTION1;id=$ID?Command=TEST&id1=$ID1&id2=$ID2&id3=$ID3” As you can see, there are some $variables ...
0
votes
0answers
30 views

Pass a function arguments?

How would you make a function that gets arguments? function arg_example { arg "c" # This is imaginary but it would return 'true' if it found the argument -c. did_find_arg=$? # Get the ...
10
votes
5answers
825 views

How to get the last N files in a directory?

I have many files that are ordered by file name in a directory. I wish to copy the final N (say, N=4) files to my home directory. How should I do it? cp ./<the final 4 files> ~/