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
2answers
63 views

How to create an alias for a sequence of commands?

I know it for one command but how to work with a sequence?
4
votes
3answers
5k views

bash: /home/user/.ssh/authorized_keys: No such file or directory

Create a ssh key: $ ssh-keygen -t rsa –P "" Moving the key to authorized key: $ cat $HOME/.ssh/id_rsa.pub >> $HOME/.ssh/authorized_keys bash: /home/user/.ssh/authorized_keys: No such file ...
0
votes
2answers
27 views

how to extract path from file location using shell

how to extract path location from below given string. /opt/oracle/app/oracle/product/12.1.0/bin/tnslsnr expected output. /opt/oracle/app/oracle/product/12.1.0/bin (or) ...
76
votes
8answers
88k views

Colorizing your terminal and shell environment?

I spend most of my time working in Unix environments and using terminal emulators. I try to use color on the command-lin, because color makes the output more useful and intuitive. What are some good ...
0
votes
5answers
34 views

find the max value of column 1 and print respective record from column 2 from file

How to find the max value from the column 1 and echo the respective path location from a file which contains n number of records. $ cat version.log 112030 /opt/oracle/app/oracle/product/11.2.0 ...
2
votes
3answers
26 views

How to parse env variable in a quoted string?

I'm having a hard time getting the value of an environment variable ($GHREPO) in a quoted string. Here is the command I'm running. I'm trying to make a directory with the value of ...
2
votes
1answer
52 views

find and sed (find and replace) causes illegal byte sequence on Mac OS X

I am attempting to perform a find and replace of underscores to dots in a directory for certain filetypes only (.mkv, .mp4, .avi). This is the code that I am using (I'm on Mac OS X 10.9): find . \( ...
25
votes
2answers
2k views

Why is using a shell loop to process text considered bad practice?

Is using a while loop to process text generally bad practice in POSIX shells? As Stéphane Chazelas pointed out, some of the reasons for not using shell loops are conceptual, reliability, legibility, ...
5
votes
3answers
156 views

what's the difference between using 'single quotes' or not in find command

find ~/ -name *test.txt find ~/ -name '*test.txt' Can anyone help me to construct an example where the first form fails but the second still works. And tell me the difference between them.Thanks!
-2
votes
0answers
49 views

Does anyone know how to make a text based game in Unix [on hold]

please help me I don't know what I'm doing send a link from a video or code I only know Unix code
2
votes
2answers
906 views

Using sudoers to allow php to run command

I am trying to get my php page to run this command: shell_exec("sudo /home/xbian/433Utils/RPi_utils/codesend {$num}"); So I added this entry to my sudoers file with visudo: www-data ALL=NOPASSWD: ...
83
votes
3answers
5k views

Why not use “which”? What to use then?

When looking for the path to an executable or checking what would happen would you enter a command name in a Unix shell, there's a plethora of different utilities (which, type, command, whence, where, ...
4
votes
2answers
79 views

Using `case` to handle script arguments

Can I use the case statement to handle arguments? So, using -restart I'd like execute "-umount" and "-mount" #!/bin/bash case "$1" in -mount mount /ip/share1 /local/share1 ;; -umount umount ...
4
votes
7answers
437 views

Command line tool to “cat” pairwise expansion of all rows in a file

Suppose I have a file (call it sample.txt) that looks like this: Row1,10 Row2,20 Row3,30 Row4,40 I want to be able to work on a stream from this file that is essentially the pairwise combination of ...
1
vote
0answers
44 views

Update process name in shell, is it possible?

In C/C++ it is in general possible to do strcpy(argv[0], "new process name"). It's a hack used in malicous software to hide real process name. Is such operation possible via shell? What I want to do ...
23
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
2answers
52 views

Compare and print data from different text files to one in Shell

How can I compare and print data from different text files to one in Shell. I have captures NAS details of three different boxes using SSH, now I need to combine all the three text files to one file ...
1
vote
1answer
24 views

How do I put a time stamp with: wget --output-file=[FILENAME] [URL]

So I've been trying to put a timestamp on some images I'm downloading from a webcam, but so far it's been saving the images with the names camera3_date' here's my line that I enter: wget ...
0
votes
1answer
22 views

check status process output

I wanted to understand how to create a script sh that allows me to see if an additional script functions correctly. For now this is the script that I created. if /run.sh status echo "$SERVICEXE ...
2
votes
3answers
2k views

cshrc execute bashrc within itself?

My school has our Linux accounts using csh/tcsh by default. I, however, have a lot setup on my home bashrc and I'd like to use that at school. BUT there's also some important stuff that happens in our ...
1
vote
1answer
52 views

How to keep running a process in Android when disconnecting adb terminal?

I'm trying to analyze the reason for random reboots of my phone (see here). Therefore I wanted to record the logcat and kernel messages till the restart to see the logs even after the usb disconnects, ...
0
votes
1answer
24 views

Trying to debug /etc/init.d/named, no output, replace > /dev/null with /var/log/named.log?

I'm trying to debug named, when I try: [root@test master]# service named start Starting named: [FAILED] it fails silently, so I tried: sed -i ...
15
votes
3answers
5k views

Bash: double equals vs -eq

I am doing integer comparison in bash (trying to see if the user is running as root), and I found two different ways of doing it: Double equals: if [ $UID == 0 ] then fi -eq if [ $UID -eq 0 ] ...
2
votes
2answers
85 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 ...
13
votes
14answers
3k views

How to read an IP address backwards?

If we have this string (IP address): 192.168.1.1 How can I derive the (DNS reverse record form) from this string, so it will be shown like 1.1.168.192.in-addr.arpa using a shell script?
3
votes
2answers
2k views

Close all file descriptors in bash

Is there a way to close all the open file descriptors, without having an explicit list of them beforehand?
3
votes
4answers
283 views

How to use sed to selectively remove leading zeros

How can I substitute/remove 0's in this, using sed: 2001:0db8:03cd:0000:0000:ef45:0006:0123 to make it looks like this: 2001:db8:3cd:::ef45:6:123 There are 8 pieces of 4's divided by : in the ...
1
vote
3answers
3k views

Removing a directory from PATH

I'm trying to compile wxWidgets using MingW, and I have cygwin in my path, which seems to conflict. So I would like to remove /d/Programme/cygwin/bin from the PATH variable and I wonder if there is ...
10
votes
2answers
10k views

How to print only the duplicate values from a text file?

Suppose there is a column of numeric values like following: File1: 1 2 3 3 3 4 4 4 5 6 I want the output: 3 4 That is, only the repeated lines. Is there any command line tools to find this ...
112
votes
15answers
55k views

How to do integer & float calculations, in bash or other languages/frameworks?

Using echo "20+5" literally produces the text "20+5" What command can I use to get the numeric sum, e.g. 25 in this case. Also, what's the easiest way to do it just using bash for floating point, ...
2
votes
3answers
64 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 ...
3
votes
2answers
106 views

single quote within double quotes and the bash reference manual

In section 3.1.2.3 titled Double Quotes, the bash manual says: Enclosing characters in double quotes (‘"’) preserves the literal value of all characters within the quotes, with the exception ...
12
votes
2answers
770 views

How can variables use “~” for 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
110 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 ...
1
vote
2answers
180 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
votes
0answers
37 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 ...
4
votes
2answers
399 views

What are the shell's control and redirection operators?

I often see tutorials online that connect various commands with different symbols. For example: command1 | command2 command1 & command2 command1 || command2 command1 && command2 ...
1
vote
3answers
65 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 ...
1
vote
1answer
34 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
148 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
20 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 ...
2
votes
6answers
9k views

Extract date from a variable in a different format

Let me explain you the problem $ date +%c -d "$d" Tue 31 Dec 2013 01:13:06 PM CET $ date +'Today is %F' -d "$d" Today is 2013-12-31 This solution corresponds to current date. But I have one ...
1
vote
3answers
241 views

Brackets in if condition: why am I getting syntax errors without whitespace?

I am using the below script to move two days back when script runs at starting two days of the year and also check first and second days of every month and move two days back. if [$month="01"] ...
2
votes
3answers
211 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 ...
10
votes
4answers
5k views

symbolic link to a directory and relative path

I've created symlink with absolute path to the directory (Blink) and have for example following tree: $ ls -l /tmp/A total 0 lrwxrwxrwx 1 root root 6 Apr 3 12:27 Blink -> /tmp/B -rw-r--r-- 1 root ...
6
votes
6answers
1k views

How to clean up file extensions?

I have a directories with .MP3 files which I'd like to change the extensions to .mp3. What's the easiest way to do this? I'm think something along the lines of: find /RootPath -type f -iname "*.mp3" ...
0
votes
0answers
11 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
2answers
48 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, ...
5
votes
3answers
272 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
42 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 ...