The shell is unix's command-line interface. You can type commands in a shell interactively, or write scripts to automate tasks.
6
votes
5answers
986 views
Why does shell Command Substitution gobble up a trailing newline char?
As per the following example, and as in my recent question In bash, where has the trailing newline char gone?, I want to know "why" it happens
x="$(echo -ne "a\nb\n")" ; echo -n "$x" | xxd -p
# ...
6
votes
7answers
957 views
Is it bad practice to set root's shell to something other than the default?
Once a friend of mine (who is an experienced Unix/Linux user) told me that setting root's shell to something other than sh (i.e bash or zsh) might create problems, because some script might assume ...
5
votes
3answers
3k views
Find files which are created a certain time after or before a particular file was created
I need a shell script which finds files which are created 1 hour before or 1 hour after a particular file (test.txt) was created.
If I go with find -newer, that means I'd have to create a temporary ...
5
votes
3answers
264 views
“mkdir foo; svn mv * foo”
I often want to do some variant of this idiom:
$ mkdir 2010
$ svn mv * 2010
Of course, I get an error because the glob matches 2010 as well:
svn: Cannot copy path '2010' into its own child ...
4
votes
2answers
2k views
How to get a clean environment in a ksh shell?
I need to get rid of all the environment variables in a Ksh shell. I can fork a new instance, but it will inevitably source some init files (as far as I know .profile, .kshrc). Is there a way to ...
3
votes
1answer
273 views
creating abbreviations for commonly used paths
I am new to linux and was wondering whether it is possible to create abbreviations that can be used in terminal. I know about alias command, but am not sure whether that can be used for what I am ...
3
votes
3answers
668 views
In a regular expression, which characters need escaping?
In general, which characters in a regular expression need escaping?
For example, the following is not syntactically correct:
echo '[]' | grep '[]'
grep: Unmatched [ or [^
This, however, is ...
2
votes
2answers
90 views
Working of rm/ls with [0-9]
I am learning the shell commands and came across the short tags eg.[0-9],[[:digit:]] etc.. As a proof of concept i tried deleting all the files with the rm command(i know its not a good practise but i ...
2
votes
2answers
118 views
Use of quotes in GNU grep regular expressions
I could see that certain patterns in the GNU Grep can be enclosed within brackets and certain others need not be. For example, matching the beginning of a word works only if it is enclosed within ...
2
votes
3answers
403 views
Bash while loop and reading from pipe
I have a Windows command-line program that I'm running in a Bash script in Ubuntu via wine. The Bash script basically looks like this:
wine myprogram.exe | while read line
do
# Process line
done
...
2
votes
3answers
466 views
Switching to superuser while shell script is running
I have a shell script that contains the following lines:
CURRENT_USER=${USER}
echo $CURRENT_USER
su
echo switch to `who am i`
Once the 2nd line is executed, the shell prompts me to enter the root ...
2
votes
2answers
307 views
Can I read and write to the same file in Linux without overwriting it? [duplicate]
Possible Duplicate:
How can I make iconv replace the input file with the converted output?
I frequently connect to amazon ec2 using their public DNS names ...
2
votes
2answers
224 views
How do I output a count of all files with “tty” in the filename in the Linux directory that holds files on system devices
I am having trouble knowing how to output a count of all files with “tty” in the filename in the Linux directory that holds files on system devices.
1
vote
4answers
333 views
Stripping all vowels but the first from a set of strings
I have a string comprised of multiple substrings, separated by underscores. For example: AbcdAEfd_hEgdgE_AbAAAAA. I need to remove all vowels except the first from each substring. So:
AbcdAEfd -> ...
1
vote
1answer
10k views
How do I execute a remote shell script over SSH and be prompted for passwords by commands that require it in that script?
I want to do something like this
ssh user@remote-domain.com ./remote_script.sh
Contents of remote_script.sh
#!/bin/bash
hg pull
This example is much simpler than what I am actually doing. I know ...
1
vote
3answers
1k views
rename multiple files with rename command? [duplicate]
Possible Duplicate:
How can I rename a lot of files using a regex?
Rename All Files with a Certain Name
There are files with
ORDER_EVENTS_SOMETHING_20120117.log
...
0
votes
1answer
2k views
mounting problem during installation of archlinux on dell xps one
I've been trying to install archlinux on xps one.
the screen doesn't work because it has intel g45/g43 express chipset.
I had to use nomodeset option as mentioned in the installation guide.
Arch ...
0
votes
3answers
195 views
Syntax errors in a bash script executed from tcsh
I wrote the line below in order to verify if the first or second fields of a list of numbers are equal to 146.
I want to run the line from tcsh, with one line interpreted by bash.
What's the problem ...
0
votes
1answer
953 views
Script failing with “command not found: ^M”
When I try to run the following script in zsh, via the command /bin/zsh ~/.set_color_scheme.sh I get the following error:
command not found: ^M
The script has u+x permissions and it used to work on ...
0
votes
2answers
129 views
Why does this compound command report errors when copying directories?
if one executes the following two commands in one line, as follows,
rm -rf dir ; cp -r dir2 dir
it may complain that cp can not create directory dir/subdir: File exists
but if these two commands ...
0
votes
2answers
190 views
2 consecutive ssh logins [duplicate]
Possible Duplicate:
Common multiple SSH connections file handling issue
I used to do something like that often:
home $> ssh user@server1
user@server1's password:
server1 $> ssh ...
48
votes
21answers
4k views
Quick directory navigation in the terminal
I would like to frequently switch between directories that are in totally unrelated paths, for example /Project/Warnest/docs/ and ~/Dropbox/Projects/ds/test/.
But I don't want to type cd ...
26
votes
8answers
2k views
Output “Hollywood-hacker-scene” from a shell
This might seem like a strange question, but what would you use for creating the typical hollywood hacking scene?
I got this request from a friend and my brain was blank. All I could think of was ...
22
votes
5answers
1k views
When do you use brace expansion?
I understand what brace expansion is, but I don't know how best to use it.
When do you use it?
Please teach me some convenient and remarkable examples if you have your own tip.
60
votes
6answers
2k views
Run a command that is shadowed by an alias
Let's say i have the following alias in bash - alias ls='ls --color=auto' - and i want to call ordinary ls without options. Is the only way to do that is to unalias, do the command and then alias ...
22
votes
1answer
623 views
Avoiding “BASH-isms” in shell scripts
Does there exist a tool similar to Perl::Critic that will inspect your shell scripts and point out flaws, portability issues, uses of non-standard programs without fallbacks, depreciated program uses, ...
18
votes
4answers
733 views
What's the difference between running a program as a daemon and forking it into background with '&'?
What are the practical differences from a sysadmin point of view when deploying services on a unix based system?
18
votes
2answers
763 views
What does a “< <(…)” redirection mean?
I've seen that rvm (ruby version manager) is installed using the following command:
bash < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer )
So as I ...
26
votes
4answers
2k views
What is the difference between a builtin command and one that is not?
Is there any intrinsic difference between a builtin command and another command which can nominally do the same thing?
eg. Do builtins get "special" treatement? ... is there less overhead running ...
16
votes
3answers
2k views
Clone ownership and permissions from another file?
Is there a command or flag to clone the user/group ownership and permissions on a file from another file? To make the perms and ownership exactly "like" that of another file?
14
votes
4answers
1k views
Process substitution and pipe
I was wondering how to understand the following:
Piping the stdout of a command into the stdin of another is a powerful
technique. But, what if you need to pipe the stdout of multiple
...
11
votes
5answers
6k views
Script to monitor folder for new files?
How do I detect new files in a folder with a bash script? I would like to process the files as soon as they are created in the folder. Is this possible to do so or do I have to schedule a script with ...
15
votes
6answers
1k views
Using VI to edit shell commands in UNIX
I used to have a co-worker who was really good at UNIX.
He showed me how to use Vi to edit my shell commands.
He placed the command in a file that ran every time I logged in.
Since then, I've ...
11
votes
4answers
3k views
Converting relative path to absolute path
Is there a *nix command to get absolute(and canonicalized) path from relative path(with current path) or symbolic link?
4
votes
3answers
988 views
Best practice to use $? in bash?
When I read this answer about $? another question comes to mind.
Is there any best practice for how to use $? in bash?
Let's have a example:
We have a linear script and I we would like to know ...
11
votes
2answers
660 views
echo a file without the first and last lines
Is there a simple way I can echo a file, skipping the first and last lines? I was looking at piping from head into tail, but for those it seems like I would have to know the total lines from the ...
9
votes
4answers
2k 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 ...
7
votes
2answers
2k views
When do you need 'nohup' if you're already forking using '&'?
First this question is related but definitely not the same as this very nice question:
Difference between nohup, disown and &
I want to understand something: when I do '&', I'm forking ...
14
votes
4answers
1k views
How to understand pipes
When I just used pipe in bash, I didn't think more about this. But when I read some C code example using system call pipe() together with fork(), I wonder how to understand pipes, including both ...
12
votes
4answers
3k views
Save complete GNU screen session state
Is it possible to persist the "state" of a GNU screen window (or just a standard shell) so that I can reload everything after a reboot:
The number of opened shells
The name of each shell
The current ...
10
votes
2answers
1k views
How do I test to see if an application exists in $PATH?
I'm trying to write all of my sh startup/env scripts to work with as much DRY and as much: "works on every *nix I clone it to", as possible. This means making sure that if I try to run code that's not ...
9
votes
2answers
919 views
How can I test for POSIX compliance for shell scripts?
Probably the main thing that this website has taught me so far is the importance of writing portable shell scripts.
Considering that POSIX is the closest thing to a common standard between all ...
8
votes
3answers
4k views
Is there a way to set the size of the history list in bash to more than 5000 lines?
No matter how much I set the HISTSIZE environment variable to be larger than 5000, when printing the history list with the history builtin, it prints only the last 5000 commands.
I need that because I ...
8
votes
4answers
365 views
rolling diffs for storage of highly similar files?
At work we do a nightly dump of our mysql databases. From day to day, I would guestimate that close to 90-95% of the data is duplicate, increasing as time goes on. ( Heck at this point some are ...
7
votes
5answers
736 views
Why is the terminal case-sensitive?
When I do - CD .. instead of cd ..
it gives me error saying -
CD: command not found
Why is the terminal case sensitive when it comes to linux commands? I mean you should be able to execute the ...
3
votes
3answers
495 views
Detach a daemon using sudo?
I noticed that sudo continues to run after executing any of the following lines. Is there any way to detach the daemon completely so sudo does not continue running ?
sudo -u user daemon &
sudo -u ...
12
votes
1answer
2k views
ls taking long time in small directory
Running Ubuntu, I open a terminal and do
sudo bash
cd /
ls | head -n 1000
And predictably about 20 directories are returned.
However, if I do an ls, and don't pipe it into anything, the ls just ...
11
votes
6answers
6k 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?
10
votes
2answers
487 views
Where has the trailing newline char gone from my command substitution?
The following code best describes the situation. Why is the last line not outputting the trailing newline char? Each line's output is shown in the comment. I'm using GNU bash, version 4.1.5
...
9
votes
4answers
194 views
+100
Why do I have to re-set env vars in tmux when I re-attach?
I mainly work on a mac and ssh/tmux attach to a Linux machine to do my work. I have ssh-agent running on the Linux machine. I have
set -g update-environment "SSH_AUTH_SOCK SSH_ASKPASS WINDOWID ...
