Tagged Questions

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)

1
vote
1answer
48 views

How can I use a variable when cd'ing?

How can I use a variable - $BASE in my cd. I tried the following but I get an error $ cd ~/z/repo_1_ruby_193/ 23:23:57 durrantm Castle2012 /home/durrantm/z/repo_1_ruby_193 $ BASE="~/z" 23:24:03 ...
2
votes
2answers
83 views

How can I test for a file having a value?

I am using source ~/.rvm/scripts/rvm repos="repo_1_ruby_193 repo_2_ruby_211 repo_3_ruby_191" > rvm_check.txt for repo in $repos do cd ~/zipcar/$repo 2>rvm_check.txt cd .. echo $repo if ...
0
votes
1answer
27 views

Using a command's output to determine the name of the file to redirect output to

I want to run smartctl -a, and use the device serial number from that output as the name of the file to store the output in. I know this can be done by invoking smartctl twice, and slicing up the ...
-1
votes
0answers
29 views

Command line commands that every one needs to know! [on hold]

Well I'm new to Linux, and I have really never used a Command line before... So I have no idea of its potential. I know some of the basic commands like: apt-get xrandr aptitude clear startx ls cd ...
1
vote
2answers
147 views

how to shutdown another computers by using their IPs in shell script [on hold]

command to shutdown to collection of servers by IP in specific time by shell script "using ssh command"
1
vote
1answer
29 views

How do you make case statements with ranges

I'm supposed to: Make a case statement that will display the a grade after input. With no loop or conditional. A=90-100, B=80-89, C=70-79, D=60-69, F=0-59 This is what I have so far: ...
2
votes
3answers
140 views

How to create multiple files with different names and different extensions?

I'm trying to create some files that has different names and with different extensions. Let say I want to create for example 3 files with following name and extension: File001.000 File002.001 ...
1
vote
1answer
18 views

Root shell sees pip but sudo pip “command not found”

I have installed python 2.7.8 via make and make install and then pip via get-pip. I have to note that I work behind a proxy which I have set up via http_proxy ftp_proxy https_proxy in my user's ...
1
vote
3answers
59 views

0 byte file created in a simple script

I have a script as below: #!/bin/bash df -k | tr -s " " "," | awk 'BEGIN {FS=","} {print $1,$5}'|sed 1d > file1.txt while read partition percentUsed do if [ $percentUsed > 75 ] then echo ...
2
votes
2answers
76 views

How to read from a named pipe after the writer process exits?

I want to use named pipes as asynchrnonous task queues (JMS-like, perhaps). For example, suppose a client sends some data that I wish to insert into a database, but I want the client to disconnect ...
0
votes
0answers
10 views

od: Put offset n to n of a hexdump to a file in proper hexdump -C (hex+ASCII) format

I have a 155GB canonical hex+ASCII hexdump hexdump -C blah > dump.dp Then ran: strings dump.dp | grep -bo 'XXXX' > found.txt So now, that file contains the string's hex offset in the ...
2
votes
3answers
204 views

Bash File existence test is always true

I have the following lines of bash script to test whether a file exists: MYAPPPATH=$(find $APPDIR -iname myapp* -print) if [ -e $MYAPPPATH ] then echo "File exists" fi However when file ...
2
votes
2answers
45 views

Efficiently copy names in shell

I have noticed an efficient technique that some users use to quickly copy directory and file names in the terminal or shell. The behavior/usage is as follows: Issue ls Click on the desired entry, ...
21
votes
4answers
2k views

Is there a simple Bash tool which can quickly render basic HTML?

From time to time I need to do a simple task where I output basic HTML into the console. I'd like to have it minimally rendered, to make it easier to read at a glance. Is there a utility which can ...
1
vote
1answer
49 views

Sh Script using ftp to put a list of files

So my Script looks something like this: #... files="$(find $line/processed/* 2>/dev/null)" #2>/dev/null used for error output suppression if [[ ! -z "$files" ]] then ...
1
vote
1answer
174 views

How to get owner and full path of 50 large size file across all users?

Below command list top 50 files regardless of subfolders. $ls -lR /root/home | sort +4 -5nr | head -50 Current Result: -rw-r--r-- 1 john dpst 192954384 Nov 7 07:36 filenxx1.gz ...
1
vote
2answers
32 views

Store stdout in variable and send command to background

I have a command in a bash script which I want to capture the output of and then send it to the background. How do I get this done? The following doesn't seem to work (it keeps blocking and outputs ...
3
votes
1answer
52 views

how to run multiple versions of one shell on a single machine

In order to test some scripts1 in as many environments as possible, I've set up several VMs with UNIX (or Unix-like operating systems): Linux Solaris OS X2 FreeBSD I assume, though, that in many ...
0
votes
1answer
22 views

How do I add text to an output file?

I have a script for doing whois lookups: #!/bin/bash for domain in `cat /Users/jason/Desktop/letters.txt `; do echo $domain >> /Users/jason/Desktop/whois-results.txt whois $domain | grep ...
5
votes
3answers
269 views

How to iterate a zero padded integer in bash?

How does one iterate a string with the form "[A-Z][0-9]*" Or for example: "A000001"? After receiving the variable I split: current_=$(mysql -h"$mysqlhost" -u"$mysqluser" -p"$PASS" "$DBNAME" -se ...
3
votes
1answer
41 views

Run vsim from dmenu — it only works when directly invoked in the terminal

Works: vsim, sh -c vsim Doesn't work: echo "vsim" | sh, echo "vsim" | xargs -I {} sh -c "{}" I want to run ModelSim (vsim) with dmenu, which is triggered using xbindkeys. Details vsim is a ...
1
vote
2answers
36 views

How to find number of Subdirectories under a given directory

In windows you get a count of the number of subdirectories within a directory.Is there any equivalent on Linux ? I'd like it to count recursively & Not stop at a single level.
1
vote
1answer
31 views

Make parent directories while creating a new file

I am aware of the fact that mkdir -p /path/to/new/directory will create a new directory, along with parent directory (if needed ). If I have to create a new file, along with it's parent directories ...
0
votes
1answer
33 views

How to ssh and execute a remote script within a local shell script?

I have a shell script which will kick off a series of jobs on a remote server. I can ssh into this server (but it does require a password!) and run the scripts manually, but there are certain steps ...
0
votes
2answers
41 views

Convert a float to the next integer up as opposed to the nearest?

The context is there are 2 variables that get divided to a floating point result like so: printf "%0.5f\n" $(echo 305/15 | bc -l) 20.33333 How can I always round up to the next integer i.e. 21? ...
2
votes
3answers
48 views

Remove files from listing that are created/modified on Saturday

I am not sure if it is possible. I do ls -l, it gives all the files in the current directory. Is there a way to say list only files that weren't created/modified on Saturday's with shell command?
2
votes
1answer
25 views

Problems with find, xargs and egrep

I this is what I what I'm trying to end up with (except working) find ./ -mindepth 1 -type f -mtime +60 -print0 | xargs -0 egrep -vZ 'vvv|iii' What am I doing wrong? $ ll total 0 -rw-rw-r-- 1 ...
0
votes
1answer
38 views

Command not found when run with sudo bash

I ssh into my machine and then, in order to run some commands, I need to sudo bash first. In an interactive terminal session, if I do this: [vagrant@33 ~]$ sudo bash [root@33 vagrant]# which bundle ...
0
votes
2answers
43 views

How to list files and directories of a mount point

Given a mountpoint such as /dev/sda1 how can I list the contents of this file system using shell script. My objective is to delete the oldest file in this drive.
0
votes
2answers
23 views

Number of occurences of letters in a word?

I would like to find out the number of occurrences of each of the alphabets in a word. Eg input aabbbddd output a@2 b@3 c@0 d@3 How can I perform this using shell script?
1
vote
1answer
30 views

Using double or no quotes with wildcards

I came across this article which attempts to explain the find command.It gives an example of find /tmp -iname "data*.txt" now this article here states that Double quotes do not suppress the ...
2
votes
4answers
66 views

unix test when to use eq vs = vs == in test commands?

When should I use -eq vs = vs == e.g. [[ $num -eq 0 ]] [[ $num = 'zzz' ]] I've observed a pattern of using -eq (and -ne, etc.) for numbers and = for strings. Is there a reason for this and ...
3
votes
2answers
67 views

Execute code on remote machine and copy the results back

I'm using some old Fortran code that uses some peculiar memory handling. To make the long story short, it runs on my local machine but fails on the remote one. This is why I would like to ssh to my ...
28
votes
7answers
2k views

Is test or [ or [[ more portable both between bash shells and between other shells?

I see I can do $ [ -w /home/durrantm ] && echo "writable" writable or $ test -w /home/durrantm && echo "writable" writable or $ [[ -w /home/durrantm ]] && echo ...
2
votes
2answers
108 views

Left and right square brackets treated differently by sed/bash

I have a file with the following contents: [root@server list]# cat filenames.txt [AAA','ACMEDEMO2','ACMEDEMO3','ACMEDEMO4','RENTCOGH','TESTENT','DORASINE','LOKAWINK','BBB] [root@qa4app01 list]# I ...
3
votes
2answers
71 views

What is the format for piping a message into sendmail?

I am using the following command to create messages on the fly, and send them: echo "Subject:Hello \n\n I would like to buy a hamburger\n" | sendmail email@example.com It seems that when you send ...
4
votes
1answer
38 views

Are there problems with hyphens in functions, aliases, and executables?

In my testing (in Bash and Z Shell), I saw no problems with defining functions or aliases or executable shell scripts which have hyphens in the name, but I'm not confident that this will be okay in ...
4
votes
3answers
146 views

Change case of n-th letter in a string

I want to change the case of the n-th letter of a string in BASH (or any other *nix tools, e.g. sed, awk, tr, etc). I know that you can change the case a whole string using: ${str,,} # to lowercase ...
1
vote
3answers
66 views

What return/exit values can I use in bash functions/scripts?

I want to know what return values we can use that will not be mistaken by for ex. SIGINT? ex.: $sleep 10 $#hit ctrl+c $echo $? 130 so I know I must not use anything like return 130 or exit 130 so ...
1
vote
3answers
38 views

How to remove matching files from directory A in directory B in the command line?

I have some duplicate files in directories A and B, how could I delete the dupes in B using the filenames from A in bash? How to do it in other shell's is a welcome bonus.
6
votes
3answers
453 views

How do I print '-e' with echo?

I know that echo -e is not an ordinary command. I have tried echo '-e' and echo \-e but they still don`t work.
1
vote
1answer
11 views

RYSNC over SSH not working for restricted shell

I need to give access to some Mr X in my production server so that he can push files to my server. Since there is no necessity to give him shell access , I decided to use restricted shell (rssh) so ...
1
vote
1answer
11 views

How do I get a list of the values of matching attributes using xmllint and xpath?

I'm trying to use xmllint to parse names of Solr cores from the configuration file. This works: xmllint --xpath /solr/cores/core/@name solr.xml |grep -Po '(?<=name=")[a-z-]+(?=")' And it returns ...
2
votes
1answer
41 views

Help with using quotes in grep searches

I have a file with variables in it of the form a(i)%b(j)%c where the a, b, and c are always the same, but the indices i and j may be different (including multiple characters). So I've played around ...
2
votes
2answers
23 views

Adding “ubuntu” user to Vagrant ubuntu instance

I am using a vagrant box : uname -a Linux precise64 3.2.0-23-generic #36-Ubuntu SMP Tue Apr 10 20:39:51 UTC 2012 x86_64 x86_64 It does not have ubuntu user setup , instead it has vagrant one ,so I ...
2
votes
1answer
36 views

GDB cannot exec my test program

My computer run with Ubuntu 14.04. GDB seems to be abnormal in different account. For example I make a very simple test. I write a file under ~/test/test.c like this: #include <stdio.h> ...
0
votes
2answers
45 views

Bash getting integer expression expected

I have following script to check disk usage #!/bin/bash # set alert level 90% is default ALERT=10 OIFS=$IFS IFS=',' storage=$(df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " ...
4
votes
1answer
75 views

Executing a “fork bomb” safely

We've all seen the "fork bomb" that will render a host non-responsive, even if executed in an unprivileged shell: Warning: Do not execute the following shell script. Just don't. :(){ :|:& };: ...
0
votes
4answers
40 views

Print only directories with more than 31 files

I am using this script to count files on my directory and sub-directories: for i in $(find . -type d) ; do printf "$i %s\t" ; ( find $i -type f | wc -l ) ; done This script works fine. What I ...
2
votes
2answers
40 views

Tar a list of files which don't all exist

I'm running a command from a script like tar -c -f ar.tar a b c d where b, c, and d may not exist, and may be directories. The solutions that I've come up with are piping the output of ls -d to ...