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
4answers
501 views

Command substitution grepping ls output causes error

I'm trying to make a tar.tgz file using command substitution There are backups of 17 Aug 2012 -rw-r----- 1 ossec 502 804M Aug 17 2012 BKPMDISINT_i6nir20j.F_bkp -rw-r----- 1 ossec 502 2.7G Aug 17 ...
2
votes
2answers
54 views

How to specify a different “top level” name for tar?

I would like to tar root (/) and let it appear as /abc in the tar archive. Is there a tar flag for specifying a custom top-level name?
-2
votes
1answer
180 views

Archive file with date-stamp [duplicate]

I want to move(archive) the multiple files from say directory /users/wahasan to /users/wahasan/old. The archive files should be autodated. files are of the format CHKBOI.pos, CHKUTI.pos, ...
4
votes
3answers
562 views

Unpack file compressed in .txz and .tar with one command

I have a file compressed in *.txz. After unpacking it I received a *.tar file. Is there any way to unpack it twice with one command? I mean unpack file (*.tar).txz with one command? For know I'm do ...
1
vote
1answer
32 views

Writing a tab completion script for bash

I made a shell script that reads input from user and kills a process. But in bash if the user presses Tab key then bash suggests some keyword or file names. My script however doesn't suggest anything. ...
7
votes
7answers
8k views

What's the best way to count the number of files in a directory?

If parsing the output of ls is dangerous because it can break on some funky characters (spaces, \n, ... ), what's the best way to know the number of files in a directory? I usualy rely on find to ...
2
votes
3answers
259 views

“ sudo: source: command not found”

$ source /etc/environment $ sudo source /etc/environment [sudo] password for t: sudo: source: command not found It seems that a different shell than bash is run to execute source ...
1
vote
2answers
41 views

Show output of a command run inside screen if it exits with errors

I am using the screen command for starting server running in foreground. But in case there is an error when starting server I am not able to see the output of command. I have to run it again without ...
1
vote
2answers
92 views

how to run script with a clean login shell

I am connected to remote machine Linux RH6 directly via ssh (key imported on server), when I execute a shell script with arguments for restarting the java service, I have a strange issue with ulimit: ...
2
votes
2answers
62 views

Weird behaviour when setting environment variables with .bash_profile: only last export works properly

I am trying to export some environment variables in Unix using the .bash_profile It reads now like this: export PATH=${PATH}:/usr/local/cuda-6.0/bin/ export ...
0
votes
1answer
58 views

Strange output when echoing variable from a different user

$ sudo su - user1 -c 'echo $DOMAIN_HOME' /app/user1/DOMAINHOME This looks fine, right? However, let's dig a little deeper: $ sudo su - user1 -c 'echo $DOMAIN_HOME' | tee test.out $less test.out ...
1
vote
2answers
38 views

Copy line in file if we know the pattern [closed]

We have a file which has 10 lines, and I know that some line has text QWERTY. How can I manipulate the file so that it copies that line and paste it. The output is similar to that yy and p command ...
11
votes
4answers
452 views

Why isn't apt-cache policy output piped?

Cannot get why $ apt-cache policy foo N: Unable to locate package foo but $ apt-cache policy foo 2>&1 | grep . is empty. Where in the latter call am I doing the wrong assumption? The ...
0
votes
1answer
24 views

zsh alias with linefeeds, commas and quotes

In my zshrc I have an alias like this: alias sl='screen -list' It fits my need (seeing what screens I have running), but the output is rather ugly: [pts/7]~% sl There are screens on: ...
7
votes
5answers
447 views

Storing shell scripts [duplicate]

What is the good common practice to store shell scripts? (bash, sh, ...) For now, I have a few bash and sh scripts in my $HOME directory and I invoke them with $ bash $HOME/script1.bash arg1, arg2, ...
2
votes
2answers
1k 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: ...
1
vote
1answer
34 views

process id and command

I want to write the process id and command of all processes with some name and from some user (for example root and init). What should I do? ps -f -u root -C init or ps -f -U root -C init ...
2
votes
2answers
31 views

Replace screen process from within screen

I have configured my shell to exec screen when it starts, unless it's already running within a screen session. So in a TTY, the process tree will look like something like this: ...
82
votes
8answers
11k views

Why *not* parse `ls`?

I consistently see answers quoting this link stating definitively "Don't parse ls!" This bothers me for a couple of reasons: It seems the information in that link has been accepted wholesale with ...
0
votes
1answer
26 views

Syntax Error while running command from another hosts [duplicate]

I run a command to fetch server uptime as below [root@localhosts ~]# printf "`uname -n` `uptime| awk -F " " {'print $3,$4'}`\n" localhosts 75 days, Now when I run same command from another ...
1
vote
1answer
26 views

How does this text reformatting happen with ack?

If I do a plain ack for a string, I get a line with the filename, and then the line numbers and the matching lines, like so: $> ack function mymodule.file 8: function myfunction1() { 16: public ...
4
votes
7answers
4k views

How to remove blank lines from a file in shell?

I want to remove all empty lines from a file. Even if the line contains spaces or tabs it should also be removed.
4
votes
1answer
146 views

weird output when typing letter c in shell (non english input)

I had keyboard set to Georgian language input. Forgot to switch it back to English and typed letter c in shell. c = ც english c key is mapped to georgian letter ც - if this makes any difference. ...
4
votes
5answers
539 views

Only output most recent 10 (or n) lines of a lengthy command output

I have a command that outputs thousands of lines. I actually need these lines in order to see the progress of the command. But I do not need to see more than the 10 most recent lines. How can I do ...
0
votes
1answer
71 views

Shell Script Help - Automatically assign users to group

Recently, I have just started to learn linux and I am currently trying to make a shell script that can automate the task of creating user accounts, assigning them passwords and then assigning them to ...
6
votes
2answers
125 views

Identify alias for the command typed

Is there any shell/shellscript which identifies that there is already an alias for the command I have typed on the command line. Eg On shell I type git checkout master Shell prints "You can use ...
20
votes
1answer
5k views

Difference between environment variables and exported environment variables in bash

Bash seems to differentiate between variables which have been exported and those which have not. example: $ FOO=BAR $ env | grep FOO $ set | grep FOO FOO=BAR set sees the variable but env does ...
1
vote
1answer
35 views

Unzip specific files from multiple zip files

I'm new to Unix and am trying to extract specific pattern filename from the multiple zip files. I'm using find to find the zip files, and then trying to extract files having the filename CTL in the ...
0
votes
1answer
1k views

How to execute Netscaler commands through a remote machine via SSH connection

I have been trying to execute some NetScaler commands like "bind" & "unbind" through a Linux Box via an SSH Connection. Now the Problem is, Manually we are able to enter & execute commands on ...
3
votes
4answers
139 views

How to maintain a specific number of processes running?

I'm trying to write a shell script for converting a lot of .wav files to .mp3. I use the "find" command to find them, then the "lame" command to convert. I can use a simple for loop for this but I ...
0
votes
3answers
72 views

Remove lines in a shell script

I have this file: # more file.txt 2c2 lns-ld-wall-01-t2 old:261,260 4c4 Prive_ORANGE old:258,259 I need to remove all lines like this one 2c2 and this one 4c4. How can I do in a shell script?
7
votes
1answer
3k views

Why does redirection (>) not work sometimes but appending (>>) does?

While studying for the RHCE, I came across a situation where stdin redirection does not work in bash: # file /tmp/users.txt /tmp/users.txt: cannot open `/tmp/users.txt' (No such file or directory) ...
3
votes
5answers
76 views

`xargs` with spaces in filenames

I'm trying to list only non-image files, searching only in the most recent 500 files. So I run ls -t | head -500 | file | grep -v 'image' which isn't right: it displays a help message. Changing it ...
7
votes
2answers
7k views

Is it possible for nohup to write the output both to the file nohup.out AND to the screen/terminal?

I am using the bash shell. I frequently use nohup to ensure that my processes are not stopped when I close the shell/terminal that started them. I use a syntax like: nohup myprocess When ...
16
votes
6answers
59k views

How can I read line by line from a variable in bash?

I have a variable which contains multiline output of a command. What's the most effecient way to read the output line by line from the variable? For example: jobs="$(jobs)" if [ "$jobs" ]; then ...
4
votes
3answers
857 views

Why read works if stdin is redirected to fd4?

What does the following script mean? exec 4<&0 0</etc/XX/cfg read line1 exec 0<&4 It redirects fd0 to fd4, and "/etc/XX/cfg" to fd0. So why does read still work, shouldn't that ...
0
votes
1answer
26 views

Run Application without Holding up terminal [duplicate]

If i wanted to run an application from the terminal (linux, ubuntu), how do I do so so that the terminal is still usable or that so if I close the terminal, the application still runs.
13
votes
3answers
8k views

Replace multiple spaces with one using 'tr' only

I have a file, f1.txt: ID Name 1 a 2 b 3 g 6 f The number of spaces is not fixed. What is the best way to replace all the white spaces with one space using only tr? ...
5
votes
3answers
3k views

What's the meaning of a dot before a command in shell?

While following android eclipse debug tutorial, I encounter following commands. cd /path/to/android/root . build/envsetup.sh lunch 1 make emulator My problem is what the dot before ...
0
votes
1answer
56 views

How do I center-align a column in UNIX?

I’m trying to center-align a column using the command column. The output should look like this: temperatures 50 12 89 63 How can I do this?
1
vote
1answer
42 views

Script executes differently if run from udev

I'm having an issue with a script that seems really weird; it appears to stop executing prematurely when run from udev, but not when I run it manually from the command line. I've tried troubleshooting ...
0
votes
1answer
134 views

Why isn't this `expr … | bc -l` command working?

I'm noticing an error: bash: syntax error near unexpected token `-105.5*7+50*3' When executing the below script/expression: expr (-105.5*7+50*3)/20 + (19^2)/7 | bc -l Is there any other way ...
1
vote
1answer
46 views

Host linux distro without GUI?

I saw this video on Youtube: Run Kali Linux on Android The phone uses the app: Linux deploy, which uses the phone to host the distro, but there's is no GUI. The only way to connect to Kali, is by ...
1
vote
1answer
890 views

Adding multiple user with shell script on Ubuntu

Can someone help me in providing me the shell script for creating multiple users on Ubuntu. Password needs to be different for each user. Thanks in advance
2
votes
2answers
33 views

universal help/man command: help builtin partial matches

I found a nice little script which iterates through a couple of manuals for a specific command. As a last resort, it will Google it and open a browser window. Source here: ...
-2
votes
2answers
69 views

Parsing a flat file using shell script

I have a file like in following format User:blala Pass:blala IP:***.***.**.** I tried with IFS but it is not working input="/path/to/your/input/file.cvs" while IFS=',' read -r f1 f2 f3 f4 f5 f6 ...
2
votes
1answer
35 views

Shell Scripting: Deleting or moving files from one directory that match filenames from another directory

I have a very specific and odd problem to solve. I'm working as a research assistant and I've been producing a ton of figures. In one directory, I dump .pngs to view casually (limited space here) and ...
0
votes
1answer
54 views

How to avoid executing a command if a process doesn't exist

In a korn shell script, I am running expdp. I have made the script to where it can be reusable so if a later process fails, I can run it again without running the already completed steps. I am running ...
6
votes
3answers
159 views

Get files with a name containing a date value less than or equal to a given input date

One of my folders contains files in the following format: 3_20150412104422154033.txt 3_2015041211022775012.txt 3_20150412160410171639.txt 3_20150412160815638933.txt 3_20150413161046573097.txt ...
1
vote
1answer
48 views

How can I prepending a character for every output of a command?

I'm running commands which I want to specifically group them by every command, as shown in the example below. Tried printing with echo -e '| $line' but it only affects commands that output the text ...