Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
In linux terminal, I accidentally mistyped
sudo mv myfile.zip /~
My purpose was to move under the home folder but it was not there.
Although I tried to find it by both
sudo find / -name 'myfile.zip'
and
sudo locate myfile.zip
could not find it. Where it can be?
Thanks in advance.
You might be surprised to find a file named ~ right under /.
It's called /~. That's a perfectly valid filename (remember, shell only expands ~ at the * beginning* of a path and you typed it in the middle, so the shell left it at that).
You moved it to /~ --- it is at root and named ~.
Your file is now no longer named myfile.zip, but ~. You should find it exactly where you told it to go, at: /~
It will be under / and its name will be ~.
You'll be surprised that unlike Windows, Unix-like systems can take a lot of things very literally, you can even create a file with the name *.* if you quote properly. The system won't complain about it, and it will even work.
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 6 years ago.
Improve this question
I'm trying to symlink all files in a directory to a target directory, by doing:
ln -s /directory/* /target-directory
Problem is when I go into the target-directory, I'm seeing this '*', an asterisk in quotes, instead of all the files in the first directory. What am I doing wrong? Thanks.
Normally, what'd happen when you run ln -s /directory/* /target-directory is that the shell would expand /directory/* into a list of the (currently existing, visible) files in /directory/, and then pass that to ln in its argument list. The result would be equivalent to something like ln -s /directory/file1.txt /directory/file3.pdf /directory/file3.c /target-directory. Note that the ln command would not see the "*", and so would not include it in either the link source or target name.
Since "*" is being used as the link name, it's not getting expanded. There are a couple of reasons this might happen:
You might have the noglob shell option set. But you said in the comments that's not the case.
The shell expansion might not have matched any files, in which case the shell will simply pass it unchanged to ln, giving the result you describe. You said you created a file in the source directory, but did you re-test after doing that? Another possibility is that there's a typo in the directory path, so it's not finding a matching directory (let alone any files in it).
Oh, one more note: you said when you go to the target directory, you see an asterisk in quotes. Exactly how are you looking? Because if you're just using ls, it should not include quotes in the listing unless they're actually part of the filename. [Edit: Mark Plotnick pointed out that some versions of GNU ls do add quotes to some filenames.] I have no idea how the command you gave could add quotes to the filename.
Do not create the destination directory and do
ln -sd ./source ./destination
If you set the failglob option, you will get an error message if expansion of * is not possible.
shopt -s failglob
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 9 years ago.
Improve this question
I am using CentOS minimal version and I am trying to locate a file, but I have no idea how to search all of the server for the file.
I am sure there is a command out there to do it, can anyone help me?
Try this command:
find / -name file.look
CentOS is Linux, so as in just about all other Unix/Linux systems, you have the find command. To search for files within the current directory:
find -name "filename"
You can also have wildcards inside the quotes, and not just a strict filename. You can also explicitly specify a directory to start searching from as the first argument to find:
find / -name "filename"
will look for "filename" or all the files that match the regex expression in between the quotes, starting from the root directory. You can also use single quotes instead of double quotes, but in most cases you don't need either one, so the above commands will work without any quotes as well. Also, for example, if you're searching for java files and you know they are somewhere in your /home/username, do:
find /home/username -name *.java
There are many more options to the find command and you should do a:
man find
to learn more about it.
One more thing: if you start searching from / and are not root or are not sudo running the command, you might get warnings that you don't have permission to read certain directories. To ignore/remove those, do:
find / -name 'filename' 2>/dev/null
That just redirects the stderr to /dev/null.
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I am receiving an error from an application I am running
The error looks like this:
I am curious what the dots mean in /usr/local/bin/../../etc/
Is this a shortcut I can use for something when writing a bash script?
I know this is probably a Linux noob question...
cd /usr/local/bin/../../etc/yarbu/conf/default
Is simply
cd /usr/etc/yarbu/conf/default
And that directory doesn't exist. It's likely located in /etc/yarbu/conf/default which is why it doesn't find it in /usr/etc...
.. is the shortcut for parent directory and . is the shortcut for current directory.
Well...
. means same directory
.. means parent directory
~ means home
/ means root
So,
/usr/local/bin/../../etc/yarbu/conf/default
is the same as,
/usr/etc/yarbu/conf/default
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
How do I change shell in a remote PC? I am logged into a cluster with a Bash and the output I see is
elan#l01:~ $ chsh
chsh: can only change local entries; use ypchsh instead.
elan#l01:~ $ ypchsh
-bash: ypchsh: command not found
Since I have no root privilege there, I can not install ypchsh in the cluster. Is there any other way to change shell without invoking ypchsh?
Note 1:
Browsing, it looks like another user who installed the same software (currently not available for questioning) has .cshrc in his directory, with the right settings. His .bashrc is minimal and has no redirections.
The /etc/passwd has no entry for either of us.
getent passwd
shows entry for both of us, but shows only /bin/bash for both.
Note 2:
The sofware has been developed with autotools, and using bash instead of tcsh is known to have created wrong builds. (I am not changing shell because I fancy it.)
Thank you,
Elan
In your .bashrc, put exec tcsh last.
Once you're in bash in the cluster, why don't you just type tcsh? And if that works, why not just add it as the last line of .bashrc?
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
I am working on linux scripts , Assume that the directory is consisting of these following scripts .
ls *.sh
test.sh
MyScripts.sh
My question is , before making any modifications to test.sh script , i want to keep a backup copy of it , so that if anything messes up , i will be not screwed up .
please tell me how can i keep a copy of test.sh in the same directory ?? before making any modifications to the actual file test.sh .
Thank you very much .
Consider using revision control, such as git or Subversion.
You can make a copy before your work too:
cp test.sh test.sh.orig
The usual approach is to
cp test.sh test.sh~
(or test.sh.bck or whatever naming convention). In fact, any decent editor should have an option to do this automatically for you. Vim does it by default (saves a backup name filename~ on modification)
May I heartily suggest a version control solution for this purpose instead?
Good 'starter' options include:
bazaar
mercurial
I personally vouch for git.
I took care to name (D)VCS methods that have ample interoperability options so as to prevent data lockin.
cp test.sh test.sh.`date +"%m_%d_%Y"`
Will make a timestamped backup named test.sh.10_10_2011