The shell is unix's command-line interface. You can type commands in a shell interactively, or write scripts to automate tasks.
6
votes
3answers
280 views
how to count total number of words in a file?
I am looking for a command to count number of all words in a file. For instance if a file is like this,
today is a
good day
then it should print 5, since there are 5 words there.
3
votes
2answers
29 views
Cron job for every minute executing out of order?
I'm setting up some shell scripting to be executed every five minutes, then every minute on our client's system, to poll a log and pull some timing information to be stored and accessed by another ...
2
votes
2answers
35 views
Delete files except n files with the “bigger” name?
I want to create a shell script that deletes old release files except last n files. In other words, only mantain last n releases when I deploy a new release.
File names have this format:
...
1
vote
2answers
27 views
I quite like mercurial .hgignore-style globbing. Is there a Linux shell that supports it?
I quite like mercurial .hgignore-style pattern globbing.
Globs are rooted at the current directory; a glob such as *.c will only match files in the current directory ending with .c.
The ...
4
votes
3answers
44 views
Reading a binary file as an array of bytes or 16 or 32 bits using shell script
I am working on ARM-based modem Linux host machine and I need to read a bin file as an 8-,16- or 32- bits array. I basically need to encrypt the file in question and was thinking of just XOR-ing the ...
1
vote
3answers
537 views
How can I switch between different audio output hardware using the shell?
I use my laptop with an external monitor which has speakers. When the monitor is attached through HDMI I can switch (using the GUI: Sound Setting --> Hardware) between the normal laptop audio output ...
0
votes
1answer
56 views
List partitions in grub2 shell?
I've been doing some spring cleaning of my hard drive. This cleaning caused my grub configuration to get messed up ( no surprise there ). So when I boot I wind up in the grub2 shell. ( The shell with ...
1
vote
3answers
37 views
how does built in commands of a shell implemented in Linux? as a function or thread of shell process?
I know that external commands are run in the shell by creating a separate process. But what exactly happens when a built in command is run in a shell.
Are they executed as a function or if the shell ...
80
votes
14answers
11k views
How to do integer & float calculations, in bash or other languages/frameworks?
Using echo "20+5" literally produces 20+5
What command can I use to get the actual sum, e.g. 25 in this case.
Also, what's the easiest way to do it just using bash for floating point, e.g.
echo ...
0
votes
3answers
40 views
Is there a way to switch to “su -” after switching users through “su”?
Maybe the title wasn't worded quite clear. But basically what I want to be able to do is to switch to having used "su -" instead of the traditional hyphenless "su" after already using "su" to switch ...
19
votes
2answers
3k views
Is it possible to rename a Unix user account?
I installed an ubuntu on a computer that is now used by somebody else. I renamed the account with her name, but it only changes the fullname, not the user name, which is still displayed in the top ...
2
votes
3answers
41 views
Why do 'ssh host echo $PATH' and printing the $PATH after ssh'ing into the machine give different results?
On a particular host, when I ssh into the machine and enter echo $PATH I get
/home/wxy/bin64:/home/wxy/bin:/usr/kerberos/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/bin:/usr/bin
and if I ...
-3
votes
1answer
51 views
“not a valid identifier” when I do “export $PATH”
When I run export $PATH in bash, I get the error not a valid identifier. Why?
Here's my ~/.bashrc file
# ~/.bashrc: executed by bash(1) for non-login shells.
# see ...
3
votes
1answer
60 views
How can I background a shell script during a Kickstart?
I have a Red Hat Kickstart process which reports its progress at key points via a POST request to a status server.
This is fine during %pre and %post, but when the actual build is taking place ...
3
votes
1answer
75 views
How to trigger error using Trap command
I am using Ubuntu 12.04.2. I am trying to use "trap" command to capture abnormal or error in my shell script but I am also trying to manually trigger "Error" exit.
I have tried exit 1, but it won't ...
2
votes
1answer
225 views
Xubuntu 12.04: slow login
I'm running Xubuntu 12.04, and after I ran the update, my login started slowing down big time. I've dabbled a little bit with the programs in Settings -> Settings Manager -> Session and Startup, and ...
0
votes
0answers
31 views
Easy way to push data into MongoDB from Bash shell script?
I know you can create a Javascript file that the MongoDB shell will execute upon startup. But I'm hoping for something more "lightweight" than that. I am using a Linux program that has a scripting ...
0
votes
2answers
30 views
Why are there empty lines in the output of my command?: find ~/x/y/ | shuf > ~/Desktop/z.txt
As it turns out the reason for this problem was one filename with several newlines. (No idea how that happened.)
find ~/x/y/ | shuf > ~/Desktop/z.txt
This command works pretty much as expected ...
3
votes
2answers
54 views
cd to directory of a symbolically linked file
Before I write a script, anyone know an easy way to do the following:
$ pwd
/foo/bar
$ ls -l
lrwxr-xr-x 1 username admin 48 Apr 17 2012 foo.sh -> /bar/foo.sh
$ cd /bar
$ ls
foo.sh
i.e., in ...
1
vote
1answer
89 views
How to open process substituted file from php?
Here's what I tried to do myself:
$ type 1.sh
#!/bin/bash -eu
php -r 'var_dump(file_get_contents($_SERVER["argv"][1]));' -- <(echo 1)
$ ./1.sh
PHP Warning: file_get_contents(/dev/fd/63): failed ...
6
votes
2answers
189 views
Executing piped commands in parallel
Consider the following scenario. I have two programs A and B. Program A outputs to stdout lines of strings while program B process lines from stdin. The way to use these two programs is of course
...
1
vote
8answers
110 views
remove content of directory in elegant way
I would like to remove all content of the current working directory.
How to do it in efficient and elegant way?
I have several files, directories and some of them starts with dot, like:
touch .abc; ...
4
votes
3answers
4k views
How to specify characters using hexadecimal codes in `grep`?
I am using following command to grep character set range for hexadecimal code 0900 (instead of अ) to 097F (instead of व). How I can use hexadecimal code in place of अ and व?
bzcat archive.bz2 | grep ...
4
votes
3answers
61 views
Terminating a bash shell script running in the background
I often use bash shell scripts to run simple commands for many different files. For example, suppose that I have the following bash shell script, called script.sh, that runs the program/command foo ...
9
votes
2answers
589 views
How to manage huge amount of files in shell?
$ ls
./dir_with_huge_amount_of_files/errors/
Suppose a directory is full of pictures with unix timestamps, I mean a lot measured in many GBs or even more. Shell-commands like ls will get ...
-1
votes
1answer
51 views
SED command and filenames with space
I was hacked, for my php files was infected.
Example: http://www.nwww.ma.mk/oscommerce/configweb/apexfash-wp-blog.txt
Bad Code:
<?php ...
4
votes
3answers
886 views
Selinux is denying access to mysqld
I have a script that dumps a mysql database. It then compresses the file and this gets stored in my home folder by using cron. The problem is I seem to be getting an error message.
mysqldump: ...
4
votes
2answers
43 views
Convert MAC address to Link-local address with bash
How can I convert a Mac address into an ipv6 Link-Local address?
you have to add fe80:: at the start and insert ff:fe in the middle
furthermore all leading zeros must be stripped
3
votes
2answers
52 views
how to loop through arguments in a bash script
I would like to write a bash script with unknown amount of arguments.
How can I walk through these arguments and do something with them?
A wrong attempt would look like this:
#!/bin/bash
for i in ...
4
votes
4answers
62 views
How to deal with spaces in a variable
I'm working on some scripting:
for x in `find ./ -name *.pdf`
do
echo pathname $x
done
My filenames are Test1 ( Volume II), Test2 ( Volume II).
I'm getting a return of
pathname Test1
pathname (
...
3
votes
3answers
644 views
Why $SHELL doesn't change when I run new shell?
$ echo $SHELL
/bin/bash
$ /bin/ksh93
$ echo $SHELL
/bin/bash
$ file /bin/ksh93
/bin/ksh93: ELF 64-bit LSB executable, x86-64, version 1 (SYSV),
dynamically linked (uses shared libs), for ...
-1
votes
1answer
44 views
Strange combination of symbols UNIX [closed]
I was looking at one korn shell script examples and I saw this strange combination of symbols: %?
So my question is what does it mean?
11
votes
6answers
7k views
How do I can get the size of a file in a bash script?
How do I can get the size of a file in a bash script?
How do I assign this to a bash variable so I can use it later?
3
votes
2answers
42 views
Do redirection operators always open file descriptors in parallel?
1. Consider snippet#1:
$ cat test.txt > test.txt
cat: test.txt: input file is output file
It seems that cat makes its input file descriptor point to test.txt and then when it tries to set its ...
1
vote
2answers
60 views
Reduce redundant logfile
I often have longer redundant log files, redundant in the sense that blocks of text repeat with minor changes. The length of the files makes it difficult to spot the actual information. I had the idea ...
7
votes
2answers
143 views
When is double-quoting necessary?
The old advice used to be to double-quote any expression involving a $VARIABLE, at least if one wanted it to be interpreted by the shell as one single item, otherwise, any spaces in the content of ...
1
vote
2answers
47 views
Shell hangs when doing command from ssh
I'm trying to automate a server update process.
What this should do is check for git diff files and list them, to later be copied from one place to the other.
Here's my script on my local machine:
...
6
votes
4answers
1k views
cp or rsync, is cp really worth it?
I hope this does not count as a question without a real answer, as I can't seem to find a good reason to use cp(1) over rsync(1) in virtually all circumstances. Should one typically favour rsync over ...
6
votes
2answers
2k views
How can I convert a .cue / .bin ( with cdr tracks) image into a single .iso file?
The title is descriptive as is: How can I convert a .cue / .bin (cdr track) image into a single .iso file?
I have
Fedora 16 (x86-64)
Linux 3.1.9-1.fc16.x86_64 #1 SMP Fri Jan 13 16:37:42 UTC 2012 ...
2
votes
1answer
56 views
redirection to file issues with nohup and pipe
For the following command:
ssh -t esolve@hostname 'sudo nohup bash -c "ls > log 2>&1 &"'
I always got error information:
nohup: ignoring input and appending output to ...
3
votes
2answers
70 views
Quoted vs unquoted string expansion
for i in $(xrandr); do echo "$i" ; done
for i in "$(xrandr)"; do echo "$i"; done
for i in "$(xrandr)"; do echo $i; done
I understand why 1 differs from 2. But why does 3 give a different output ...
2
votes
1answer
36 views
Is there a text-only equivalent (no curses) of `zenity --question`?
For my mercurial commit hook, I want to run my test cases and be asked whether I really want to commit if any of the tests fail. I'm thinking something like <run-the-tests> || ...
5
votes
7answers
111 views
Bash way to check if a process is already running in the background (and skip re-execution based on that)?
Can I make a bash command line that only runs a certain command if the process is not already running (in the background)?
How do I check*, if a command is already running?
(so I can add the next ...
2
votes
3answers
68 views
How to use arguments with 'find -exec'? [duplicate]
I'm trying to generate static html files for all php scripts inside dir:
find . -name "*.php" -exec php {} > {}.html \;
But it just dumps all results to {}.html. How to do it properly? And how ...
2
votes
4answers
52 views
1
vote
2answers
58 views
Debugging bash functions [closed]
So here I have a simple function that I wish to debug. However, I am unable to debug the desired function even with set -o functrace enabled. Before resorting to asking this question, I had managed ...
106
votes
4answers
5k views
What's the difference between $(stuff) and `stuff`?
Running top -p $(pidof init) and top -p `pidof init` gives the same output. Are these two ways of doing the same thing, or are there differences?
24
votes
11answers
6k views
Get exit status of process that's piped to another
I have two processes foo and bar, connected with a pipe:
$ foo | bar
bar always exits 0; I'm interested in the exit code of foo. Is there any way to get at it?
1
vote
1answer
32 views
How can I convert this bash function to the fish shell
I'm trying out the fish shell 2.0 to replace bash. I'm trying to convert the following bash function to a fish function, but its giving me hell. I have a several similar functions so if someone ...
4
votes
3answers
93 views
How to alias cp with cp -i by default
Is there a good way to alias the command cp file1 file2 to cp -i file1 file2?
Apologies if this is a dumb question, I'm a Unix novice.
