Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 3 years ago.
Improve this question
I want to copy all data inside the file (stored in var/lib/docker/volumes/...), but always get an error "Permission Denied". I have used xclip -b <filepath to copy file. OS Ubuntu 18 server edition.
Your command consists of two parts: xclip -b and <filepath.
The former (xclip -b) is calling an executable to copy stuff from the stdin to the clipboard.
The latter (<filepath) redirects the content of a file to the stdin of the first part.
Both parts are executed by the shell you are running (as user).
Now when you enhance your command to sudo xclip -b <filepath the two parts are:
sudo xclip -b: copying the stdin to the superuser's(?) X-clipboard
<filename: redirect (as the user who is owning the shell) the content of a file to the first part.
This is not what you want. What you want is:
Copy the stdin to the users's X-clipboard (so xclip should not be run via sudo, but just as is).
Read the file as superuser (so we need some way to tell the shell to apply sudo to the reading).
The simplest way to do this is:
sudo cat filepath | xclip -b
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 2 years ago.
Improve this question
I accidentally created a script that runs automatically when I open the linux terminal on windows.
I completely forgot where I created these files and now I am stumped on how to remove them.
Is there anyway I can remove these scripts or have the Linux terminal be reset to default settings?
I am using Bash on Ubuntu on Windows.
Terminal with automatic scripts
What you are asking is how to find-out-what-scripts-are-being-run-by-bash-on-startup. That link answers that question but here is the short of it:
To find all of them you could run:
echo exit | strace bash -li |& grep '^open'
(-li means login shell interactive; use only -i for an interactive non-login shell.)
This will show a list of files which the shell opened or tried to open. On many systems, they are as follows:
Also it's good to know that by default the following are usually run:
/etc/profile
/etc/profile.d/* (various scripts in /etc/profile.d/)
/home/<username>/.bash_profile
/home/<username>/.bash_login
/home/<username>/.profile
/home/<username>/.bashrc
/home/<username>/.bash_history (Not a script. Simply enables history command)
/usr/share/bash-completion/bash_completion
/etc/bash_completion.d/*
/etc/inputrc (defines key bindings; this is not a script)
FYI: /home/<username>/ is the same as ~ on most systems
For each of the scripts mentioned above you may want to check if they are calling yet another script... An easy way to do that is to grep all of those scripts for keywords implying they are calling another script (although strace will already show that)
You may want to:
cat <script_name> | grep -e 'bash' -e 'source' -e '\.\/'
In the WSL terminal, I would try to check if you are calling a startup file in ~/.bashrc or ~/.bash_profile. These are typical dotfiles that are called when a new BASH session is started. In your case, look for a call to /bin/brew (or a line that may potentially call brew) in these files.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 2 years ago.
Improve this question
I've modified my .bashrc to mount directories when I start first terminal after login.
If mount point still exists when I start new terminal nothing is done.
Now I want to add a bit of code when last linux terminal is closed/exited (e.g. umount those directories, etc..)
Also there is this not-so-intelligent way of discovering how many terminal instances are still running:
ps -au | grep "bash" | grep "grep" -v -c
I'm running Ubuntu 20.04. and I'm using bash shell.
Questions:
Is there a file which is "triggered" on terminal exit just like .bashrc is on terminal startup? I've tried messing around with .bash_logout but it doesn't seem to do anything in my case (echo, touch..)
Is there another way to do what I'm trying to achieve which doesn't include file from question #1 (if such file even exists)?
You can get it done with the help of trap which is a shell builtin.
For example if you want to clear a folder on running exit command in bash >
trap "rm /cache/*" EXIT
The syntax should be like trap <command> <SIGNAL>
Just put this in the bottom of ~/.bashrc with your desired command and it should run before the terminal is killed.
Try trap --help to know more.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 3 years ago.
Improve this question
So I have an assignment in linux terminal asking me to create a file in the home directory and to make the file display all the commands of the bash shell which is found in the /bin directory.
I already tried to use the echo command to display the commands to the file but it is not working:
echo $ls /bin > File1
I expect that the file contains all the commands of the bash shell, but when I type the line above in the linux terminal, the content of the file is just the word "/bin".
Is there any other way to use to meet the expected result?
Here you don't need the echo command, as ls already prints to standard output, which can then be piped to the file. The command you want is:
ls /bin > File1
A good way to go about this is by checking that "ls /bin" by itself will print to standard output the contents of /bin, and once you see the expected output, run it again with the "> File1" to then output to File1.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
I'm working from Mac OSX and am trying to create a script that will ssh user#host and subsequently change the working directory (cd) from within the virtual server.
Googling indicated that ssh -t user#host "command goes here" would allow for this, but when I enter cd /my/path it says that there is no such directory. It also forces me to exit the server. What is the best, simplest way to accomplish this?
I'm assuming that the desired end result is a remote interactive shell, in the desired target directory, which you can interact with from your keyboard. If not, please clarify the question.
Force a TTY with the -t argument to ssh and spawn an interactive shell with an explicit invocation of bash -i:
ssh -t user#host "cd /my/path && exec bash -i"
Scripting/automating the authentication is road already well-traveled (and, thus, duplicative); see existing questions such as Bash: controlling SSH for assistance on that matter.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
Is there a way to switch dir after doing sudo -i (in one command)?
We use lots of ssh connections on work, and it is a pain to manually set them up when you reboot your pc. So I'm trying to make aliases like ssh remote-dev -t 'sudo -i; bash -l', which connects me to a machine and makes me root there (it is required to do that way; because of Kerberos we can't directly ssh root#...)
So what I would like to do now is expanding the above command in a way that I can also tell it to switch to a specific dir after the sudo, or open a specific file, or tail a logfile or something... Is that possible?
-- edit: Of course you could tell it to do some command everytime someone logs in via ssh. But this is a bad option, because only I want to have these commands to be executed; When other people connect to this machine, they probably want different commands.
-- edit: Sorry I posted it here, did not realize it is offtopic in stackoverflow
Try
sudo -i bash -c "cd /path/to/dir; exec bash"