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)

3
votes
2answers
510 views

What is Linux for OpenVMS DCL Ctrl/T?

From OpenVMS DCL Dictionary: The Ctrl/T function displays a single line of statistical information about the current process. When you press Ctrl/T during an interactive terminal session, it ...
15
votes
2answers
5k views

Rule for invoking subshell in Bash?

I seem to misunderstand the Bash rule for creating a subshell. I thought parentheses always creates a subshell, which runs as its own process. However, this doesn't seem to be the case. In Code ...
8
votes
3answers
7k views

What is the most correct way to pass an array to a function?

Consider I have a very large array $large_list, is there a way to write a function that will take the array as an argument? For example: echo_idx_array () { arr="$1" idx="$2" echo ...
3
votes
3answers
201 views

Exporting just a single file

To make scripts accessible from anywhere in the terminal, one can use the following sequence of commands: PATH=$PATH:some_path_here export PATH Which includes all files at the path sent in ...
8
votes
3answers
2k views

How can I cd to the previous/next sibling directory?

I often have a project directory layout like this project `-- component-a | `-- files... `-- component-b | `-- files... `-- component-c `-- files... I'll usually be working in one of the ...
3
votes
2answers
547 views

Change string occurrences in file while respecting DOS new line sequences

I use Visual Studio for my C# development while using Cygwin for some of the tasks that require scripting. Recently I wanted to change all occurrences of string AAA to BBB in my project's files. I ...
2
votes
4answers
3k views

chown all files based on file name pattern in current directory

I'm trying to chown all files whose filenames begin with ChownFileNames. I've used this command, but it doesnt seem to work: find . -maxdepth 1 |grep 'ChownFileNames*' -exec chown hadoop:hadoop -- {} ...
3
votes
4answers
274 views

Change working directory of 2 terminals at once

I've typically have gnome-terminal open with ~8 tabs, using 2 consecutive tabs for the same task (one has emacs, the other is used to do git checkins and unittest runs and so). When changing tasks, I ...
6
votes
1answer
509 views

differences between echo“”> and > command

I am new to Linux. There is something that is unclear to me. What is the difference between echo "" > logfile and > logfile ? When I run the first one, the logfile size doesn't become zero ...
3
votes
1answer
2k views

Make awk use bash with the system() command

Is there a way to make awk use bash instead of sh when running system commands using the system() call? I want to use some bash-specific features such as [[ ]] and < > string comparison operators: ...
1
vote
1answer
4k views

For cygwin, how do I export the output in a terminal into a file?

I'd like to be able to export the output (and error messages) of my cygwin terminal in a file, especially since I have to click a lot of buttons in order to "mark" the stuff in the cygwin terminal ...
1
vote
2answers
662 views

Search and delete .Trash

I have 4 large USB devices with lots of backups collected over the years. I want to search for all .Trash folders and delete the contents on Fedora 17. I tried the following which failed:- # ...
4
votes
2answers
3k views

Bash Linux random CLI Password generator and `<`

I recently discovered this method for generating a 9 character password from the linux prompt in bash: < /dev/urandom tr -dc A-Za-z0-9_ | head -c9 What is < doing?
141
votes
16answers
89k 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, ...
24
votes
12answers
7k views

Remove duplicate $PATH entries with awk command

I am trying to write a bash shell function that will allow me to remove duplicate copies of directories from my path environment. I was told that it is possible to achieve this with a one line ...
5
votes
1answer
2k views

How do you make DISPLAY variable undefined?

I am using Ubuntu, but I think this applies to all Linux. What's the command to set DISPLAY to be undefined in the shell?
11
votes
3answers
3k views

Stay at same working directory when changing to sudo

When working on the command line, I often change to sudo using sudo -i. However, my working directory changes automatically to /root. I never want to go there; I want to stay where I was! How can I ...
3
votes
3answers
2k views

How can I restore the changes to shell variable?

For the purpose of an experiment... Suppose I did this bash="unset DISPLAY; export DISPLAY" so I can make DISPLAY undefined. How can I restore the original value set? Or at least know what it was? ...
4
votes
3answers
2k views

Opening a PDF file by typing its name

I am on Mac OS X and I usually open PDF files from the terminal (using bash) open myfile.pdf Now I'd be able to type only myfile.pdf and have that opened with the command above. Is there any ...
6
votes
1answer
688 views

Can I make “There are stopped jobs” harder to kill?

Typical scenario: I temporarily need to access a file that my vhost prevents me from accessing. I fire up vim, edit the settings and background vim to tell apache to reload its configuration. ...
3
votes
2answers
7k views

Change directory with space followed by '('

There are two directories I can change to: Program Files/ Program Files (x86)/ I can change to first one by writing: cd Program\ Files But the second for second one: cd Program\ Files\ ...
-4
votes
2answers
162 views

Beginning shell scripting [closed]

I am a new user of this community. I want to learn Unix shell scripting. So please guide me on how to start for the same.
2
votes
2answers
7k views

How to fix “login: no shell: No such file or directory” when I can not even login?

I installed fishfish(a user-friendly interactive command line shell) on a Linux server, later somebody uninstalled it but I don't know it. After I run chsh -s /usr/local/bin/fish without caution, I ...
5
votes
3answers
781 views

Batch copy to multiple directories

I have about 9000 files in a directory and I want to mv them into 90 files in 100 directories by filename order, ignoring any remainder. In Copy multiple files from filename X to filename Y?, Caleb ...
-3
votes
1answer
1k views

Changing IP address of Apache server using PHP statically

I want to statically assign the IP address of my Arch linux using php. I want to change the IP by using netmask,interface,broadcast,address & gateway. The user puts up the values into a html page. ...
3
votes
1answer
618 views

Command substitution: cat with executable content

I have a file called test and the contents are: ubuntu@regina:~$ cat test ** test ** catting this file via command line works fine, but if I use command substitution I get an understandable but ...
3
votes
3answers
110 views

How to include program which only works with in/out files into a pipeline?

I need to process image with several tools in a pipeline tool1 | tool2 | tool3 | .... It appeared though that one of the tools isn't designed to work in a pipeline and only works in format of ...
1
vote
1answer
1k views

Installing a gedit plugin on Fedora

I have been trying to install a gedit plugin called RunC to compile C programs using the text editor. Although the instructions tell me to use ubuntu 9 or 10 for this, I'm currently running Fedora ...
1
vote
2answers
1k views

Writing both output and error stream to the same file

In Unix/Linux you can use pipes to write output and error streams to a file. One can even write them to the same file. Is there a way to write both to the file but maintaining the order. This ...
4
votes
1answer
802 views

In a script, check if standard input comes from a file or pipe

I know this has been poorly covered previously, but those answers either lack explanation or don't apply. Basically at some point my scripts needs check if a file is specified, if it was it will be ...
7
votes
2answers
11k views

Running chsh does not change shell

I want to change my shell from bash to zsh. I have tried running the following while logged in as user zol: $ chsh -s /bin/zsh $ sudo chsh -s /bin/zsh zol $ su -c 'chsh -s /bin/zsh zol' # The above ...
2
votes
1answer
346 views

How can I add an alias for my pwd to an existing file?

I want to add another alias to my "aliases" file for the directory I'm currently in (Present Working Directory) I've tried printf "alias aaa=cd " + pwd >> myfile It's close, but I end up ...
2
votes
2answers
451 views

What is the difference between `terminator -e ranger` and ranger from terminal?

EDIT: I just noticed that when I hit Enter on the ranger (if it is executed with terminator -e ranger) then nano opens while with e it uses my main editor. In contrast, when I use a normal shell to ...
0
votes
4answers
346 views

bash using a file name as input

Im pretty stupid when in comes to bash and I was hoping someone could help me. I would like to take the output of hg resolve -l which is in the format R somefile/filename U somefile/filename R ...
6
votes
2answers
2k views

Can't understand this script. bash <<(curl -s http://xxx.com)

In a rails book, the author wrote the script to install ruby rvm. bash <<(curl -s https://rvm.beginrescueend.com/install/rvm) But I don't understand how it works. Could you explain this?
2
votes
1answer
439 views

Shell from a Firefox tab

I have a requirement for a user in the office where they would like to open a terminal shell within a Firefox tab. Is this at all possible?
1
vote
1answer
221 views

Magic file that redirects to standard output

Is there a magic file name that gives the following effect? $ mkfifo /tmp/fifo1 && cat /tmp/fifo1 & $ foo --log-file /tmp/fifo # now I can see the log as the program runs I want ...
0
votes
1answer
459 views

Redirecting output of program reading from stdin

When I want to redirect an output of a.out program I will use ./a.out > output.txt This doesn't work when the program reads something from stdin. How would you redirect output in this case? I ...
1
vote
2answers
3k views

Run tmux always when I open terminal

I usually open lxterminal with bash shell where I usually type tmux command first. I'd like to have launched tmux command automatically, so I tried to add this command to ~/.bash_profile or to ...
12
votes
4answers
15k views

How to see how many context switches a process makes?

I want to see if my process makes a lot of context switches. I also want to see how manpulating task groups affects the number of context switches.
79
votes
6answers
5k 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 ...
4
votes
1answer
7k views

How to change permissions of multiple files found with find command?

I have a directory with numerous files. Part of the files have the 755 permissions and the other part have 644 permissions. I'd like to convert the files with 755 permissions to 644. I have tried the ...
1
vote
2answers
3k views

Kill all processes related to an application

I have two processes that are temporarily spawned and I need to kill them. Here are the processes from ps aux david 38329 0.0 5.0 3916476 104624 s002 S 11:33AM 0:17.43 ...
4
votes
2answers
5k views

issue with find -exec cp

Consider this example (newbie alert): touch test0 touch timestamp touch test1 sudo find /var/www/import -iname 'test*' -newer timestamp -exec cp {} new \; It actually copies file test1, but it ...
3
votes
1answer
2k 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 ...
2
votes
1answer
813 views

using Set uid to run a root command from non-root user

Consider the following two files. summarize's executable UID bit has been set, so that another user belonging to another group can execute the summarize executable that uses the customers.dat file. ...
1
vote
2answers
140 views

How to copy a file and move it to a location using unix

I need a file to stay in the same location but also move it to a different location. What am I doing wrong? cp RubyTest.sublime-settings \ ~/Library/Application Support/Sublime\ Text\ ...
88
votes
7answers
8k views

Why is cd not a program?

I've always wondered why cd isn't a program, but never managed to find the answer. Anyone know why this is the case?
1
vote
2answers
2k views

How to pass data outside process for zenity progress?

Usually this would be a question about how to pass data from a subprocess to a main process, but maybe zenity has some extra quirks so please focus on zenity. Example: #!/bin/sh ( echo "10" ; sleep ...
3
votes
5answers
3k views

Formatting the output: Underlining

I wrote the following function in ksh that prints its first argument to the screen and underlines it with the appropriate ammount of - character: print_underlined () { word=$1 echo $word ...