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)

4
votes
2answers
792 views

What does '//' mean in return from `which`

I have an executable script test under the full path /home/sawa/foo/bar/test. The directory /home/sawa/foo/bar is within $PATH, and has priority over the default ones including /usr/bin. When I do ...
4
votes
3answers
2k views

Intercept input and output from specific executable

I have a certain Linux executable that is called from a bigger application to perform some calculations. I want to modify the way the calculations are performed, for that I first need to understand ...
1
vote
4answers
1k views

How to run my C program from anywhere within the System (Ubuntu 10.10)?

Friends, I want to add my C program's path to the environment variable PATH. My C program called "md5". So that I can execute it from anywhere (i.e any directory). My md5 program is located at ...
6
votes
1answer
360 views

Can I have my shell history record how wildcards expanded?

If I run: $ ls * foo bar buzz $ history | tail -1 ls * You can see that in my shell history it remembers that I ran ls * rather than ls foo bar buzz. Ideally, I'd like to record both in separate ...
4
votes
3answers
10k views

checking an argument to a bash script is a string of all digits

The Bash FAQ says If you're validating a simple "string of digits", you can do it with a glob: # Bash if [[ $foo = *[!0-9]* ]]; then echo "'$foo' has a non-digit somewhere in it" else echo ...
5
votes
4answers
5k views

Is it possible in unix to search inside zip files

I have 100s of directories and within those I have a few zip files. Now there are images named abc.jpg in those zip files. The zip files may be in any folder or in any subfolder so its difficult to ...
9
votes
1answer
770 views

I'm confused as to why “| true” in a makefile has the same effect as “|| true”

I have a makefile where I'm stopping a service before removing a file. When it couldn't stop the service, it would break on error. This is clearly unwanted so I thought I'd add || true but missed a |. ...
2
votes
3answers
2k views

How can I create multiple files in the current directory in bash?

Is there a command to create multiple files in the current directory? i.e. if I would like to create __init__.py, views.py, models.py and admin.py as follows: > COMMAND __init__.py views.py ...
13
votes
2answers
5k views

How to diff a file and output from the command?

Normally you would write: diff file1 file2 But I would like to diff a file and output from the command (here I make command a trivial one): diff file1 <(cat file2 | sort) Ok, this work when I ...
7
votes
5answers
19k views

How copy and rename files found in “find” function Linux?

I have a folder named /home/user/temps which has 487 folders. In each folder I have a file called thumb.png. I want to copy all files named thumb.png to a separate folder and rename them based on ...
2
votes
1answer
511 views

Single command to move a domain from cPanel's localdomains to remotedomains file?

I find myself needing to do this a few times daily and would love an easier way to do it. The domain example.com's email is handled by a third party, so the server needs to be told this by listing ...
2
votes
1answer
2k views

Cron daemon error : Permission Denied

I am having trouble setting up a cron job. My set up is as follows: crontab -e */10 * * * * OTP_ProJect/PandaServerInfo/SVN/PandaQueueMonitoring/trunk/submit_cron_test.sh the shell script has ...
5
votes
3answers
4k views

Why the double quotes and backquotes in a shell script?

I'm looking at this script mysql backup script and I don't understand what is the reason for using both backticks and double quotes around command names? 379 WHICH="`which which`" 380 AWK="`${WHICH} ...
6
votes
3answers
2k views

Print mac address to file

With a bash script, can I read the mac address of my eth0 and print it to a file?
3
votes
1answer
3k views

Grep - ^(\s*$) vs ^\s*$

I want to search for a field that only has spaces. When counting, this two commands gave me different results: grep "^\s*$" -E -c grep "^(\s*$)" -E -c Another thing. What is the correct way to say ...
2
votes
4answers
1k views

different shell for root and non-root user

When I ssh as root, my shell is bash, but when it's a non-root user it is sh. How can I make them both to use bash? This actually goes against the logic in this question: Why root's default shell is ...
35
votes
4answers
5k 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 ...
4
votes
5answers
2k views

Replacing text from a list of replacements. Added complication: backslashes

I have a file A that contains pairs of strings, one per line: \old1 \new1 \old2 \new2 ..... I would like to iterate over file A, and for each line perform the replacement (e.g. "\old1 -> \new1") ...
4
votes
1answer
3k views

Why is 'while.. read.. <<EOL' performing variable expansion, yet <file and | don't?

Aside from the variable expansion mentioned in the question's heading, I also experience another alarming issue when reading inline data to <<EOL... When the data contains a backtick `, it ...
119
votes
3answers
30k views

What does “--” (double-dash) mean? (also known as “bare double dash”)

I have seen -- used in the compgen command. For example: compgen -W "foo bar baz" -- b What is the meaning of the --.
3
votes
2answers
105 views

Generate suggestions for errors from a lookup dictionary

EDIT: the files were changed to tsv to deal better with spaces in text fields I have 2 csv files in the following form: File 1: availableText.csv (can be very big) "id1" , "text1-1" "id1" , ...
3
votes
2answers
380 views

Unix Shell and colours

Can any one please help me understand this code snippet that I found in .profile file echo -en "\e[32;44m $(hostname) \e[m";echo -e "\e[m"
0
votes
2answers
291 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 ...
5
votes
1answer
12k views

How to assign values to multiple variables in command line with bars

I am essentially trying to assing certain portions of the output of a shell command to mulitple variables, but I don't know how to do that. For simplicity's sake, assume that the command on the ...
20
votes
11answers
3k views

Linux - command to list files (except ls)

Imagine you were working on a system and someone accidentally deleted the ls command (/bin/ls). How could you get a list of the files in the current directory? Try it. I tried many ...
3
votes
1answer
476 views

Multiple renaming files [duplicate]

Possible Duplicate: How to clean up file extensions? I'd like to rename files with extension .flac.mp3 to extension .mp3. I used the following command $ for i in *; do mv $i `echo $i | sed ...
1
vote
1answer
627 views

Execute file in its native directory with shell script

I'm executing a php file from the php-cli with a shell script. One of the php files creates a file named available_data during the course of its execution. The problem is that the php file needs to ...
57
votes
7answers
53k views

What's the difference between /sbin/nologin and /bin/false

Technically, unless pam is set up to check your shell with pam_shells neither of these can actually prevent your login, if you're not on the shell. On my system they are even different sizes, so I ...
18
votes
5answers
30k views

Shell: How to read the bytes of a binary file and print as hexadecimal?

In shell, how can I read the bytes of a binary file I have, and print the output as hexadecimal numbers?
3
votes
1answer
456 views

Why does the rc.status file set the LC_ALL locale

I am currently creating a daemon service and in order to leverage existing service functionality, the startup script sources from /etc/status. This causes a problem with our service because within ...
5
votes
1answer
1k views

How to determine if disk is compact flash or standard hard drive

I need to determine in a shell script if a given block device (e.g. /dev/sda) is a compact flash disk or a regular hard drive. Google did not help me out for once, and while udevadm info --query=all ...
22
votes
4answers
36k views

Why is Debian's root shell colorless?

Are there any security concerns? What is the best way to enable it?
1
vote
0answers
250 views

How can I make scripts run when a file/directory changes in Linux (like Mac OS X’s launchd)? [duplicate]

Possible Duplicate: Can a bash script be hooked to a file? On Mac OS X, there’s a handy daemon called launchd which (amongst other things) allows you to have scripts run when files or ...
1
vote
1answer
195 views

Aliases for programs in /sbin/

I have a weird problem, unfortuantely I don't know what I did to cause this, since I tried out lots of stuff on my Linux (Archlinux, 2.6.38 kernel). The problem is: My shell is not finding programs in ...
38
votes
5answers
8k views

Timing out in a shell script

I have a shell script that's reading from standard input. In rare circumstances, there will be no one ready to provide input, and the script must time out. In case of timeout, the script must execute ...
5
votes
1answer
7k views

How do I get which to show aliases? [duplicate]

Possible Duplicate: How to use which on an aliased command? I'm used to working on systems where which would list aliases, so e.g. if I have an alias like this: alias ...
1
vote
4answers
314 views

linux shell global linux memory in mem variable - from shell

Is there any way for me to set an env variable without editing files to be in memory and effect other shells as well, which will take effect on any new user who connects that machine and will take ...
2
votes
1answer
5k views

How to run sh from sh file

I developed a Java application. I divided the application into 5 sub-applications, and created a service wrapper to each sub application using shell scripts: subaap1/bin/app.sh subaap2/bin/app.sh ... ...
3
votes
1answer
1k views

A tee >( process ) is truncating its stdout when writing a file

When I use tee to pipe stdout directly to a "specific block of code" (which then writes the modified data to a file), I always get the full complement of exptected output lines in the file. ...
0
votes
2answers
2k views

How to call a kuu from a shell script

I want to kuu to an account which requires a password, but I want to do this inside a shell script. How can I provide the password from the shell script?
5
votes
4answers
4k views

“internet connection checker one-liner”

With this I can check, that there is "internet connection". if there is no "internet connection" (succesfull pings to this 2 places), then it waits 600 sec, then it runs along: ping -W 1 -c 4 ...
3
votes
2answers
3k views

SSH slow at starting session

Starting an Interactive shell over SSH is slow to one of my servers. Everything leading up to it including negotiating encryption is fast, but then it hangs for 45 seconds. After that, it finishes ...
45
votes
4answers
7k views

How to use `which` on an aliased command?

Like most users, I have a bunch of aliases set up to give a default set of flags for frequently used programs. For instance, alias vim='vim -X' alias grep='grep -E' alias ls='ls -G' The problem is ...
1
vote
2answers
346 views

Listing all my files modified more than X days ago, in long format

How can I list in long format all files (located in a directory) which belong to me (rights) and were modified more than 7 days ago?
3
votes
3answers
3k views

How can I loop through lines of a file and find files matching each line?

In a BASH shell, I would like to take the lines of a file (eg pattern.txt) and find the files on my system whose names contain the patterns in each line of my file. So, I have the following for loop ...
6
votes
3answers
15k views

Shell console clearing

Is there a way to clear up what is displayed on the shell console (in ubuntu linux) in just a single key or two? When I get flood of lines from grep and that exceeds the height of the window, I want ...
7
votes
3answers
4k views

How to run a script from another path, and know the script's path?

I need to run a script that access a file in the same path it is located. For example: I have the script in /home/me/folder/script.sh, and this script will access the file /home/me/folder/myfile. As ...
5
votes
2answers
7k views

How do I give all the permissions to a file for a single user that's not me?

When I want to grant access to another user to my file, I use chmod 777 file, but if I want to be sure I'm granting permission just for that user, how can I do it? -- update The file is owned by ...
29
votes
4answers
16k views

How can I make iconv replace the input file with the converted output?

I have a bash script which enumerates through every *.php file in a directory and applies iconv to it. This gets output in STDOUT. Since adding the -o parameter ( in my experience ) actually writes ...
9
votes
2answers
863 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 ...