Using the mv command - file deleted? [closed] - unix

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 9 years ago.
Improve this question
This is probably a very stupid question, but is it possible that files can be deleted with the "mv" command?
I'm asking because I when I was attempting to move a file up to its parent directory, I accidentally typed one "." too many and now I can't find my file.
So instead of:
$ mv myfile.txt ..
I had put:
$ mv myfile.txt ...
Now my file is gone. Did I delete it accidentally, and is it possible to get it back at all?
Thanks!

Your file has been renamed to "..." do an ls -a to see dot files.
Try mv ... ../myfile.txt to get do what you originally wanted.

you file is now named as ..., check it with ls -al in your current dir.

On UNIX systems, file names starting with a dot are hidden from directory listings by default.
ls -lA
will display dot files.
You can rename the file back
mv ... myfile.txt

Your file is now called ... and is not visible thru the simple ls command.
Use ls -a to make "system" files (starting with a dot) visible or rename it back mv ... your_file.
And to answer the title-question:
Yes and no.
It' s not possible, but moving the file to /dev/null will delete it as well. :D

Related

How to delete line from file which matches string [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
This post was edited and submitted for review 1 year ago and failed to reopen the post:
Original close reason(s) were not resolved
Improve this question
I have a file which contains below information-
SOURCE "defrust"
DESIGN "2_3"
SYSTEM SPICE
NETLIST SOURCE
NETS "NONE"
//NETS "NONE"
//VARIABLE "cell2"
DESIGN "hello one"
How can i use unix commands to delete full lines which are starting from SOURCE ,DESIGN and //
output be somewhat like-
SYSTEM SPICE
NETLIST SOURCE
NETS "NONE"
thanks in advance
Use this Perl one-liner:
perl -i.bak -ne 'print if !m{^(SOURCE|DESIGN|//)}' file_name
The Perl one-liner uses these command line flags:
-e : Tells Perl to look for code in-line, instead of in a file.
-n : Loop over the input one line at a time, assigning it to $_ by default.
-i.bak : Edit input files in-place (overwrite the input file). Before overwriting, save a backup copy of the original file by appending to its name the extension .bak.
^ : beginning of the line in regex.
SEE ALSO:
perldoc perlrun: how to execute the Perl interpreter: command line switches
perldoc perlre: Perl regular expressions (regexes)

how to find the number of occurence of a particular word from text file in unix [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have a text file in which i have 17000 lines, example:
another instance started
another instance started
instance not started
bss instance started
like this.
I have to find the number of times the word 'another' is in printed in the above example my output should be 2. I need shell script command for the above example. Can any one help me with shell coding or command?
First you should try to search harder, the answer can be found easily.
Second:
grep -c another yourfilepath
Just use good old grep.
grep -c 'word' file
\<another\> is a word boundary and it won't match abcanother or anotherxyz etc.
grep -o '\<another\>' file.txt | wc -l
grep -c flip article.txt
10
See http://www.linuxjournal.com/article/2384
and http://www.cyberciti.biz/faq/grep-regular-expressions/

Remove character from a File [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions must demonstrate a minimal understanding of the problem being solved. Tell us what you've tried to do, why it didn't work, and how it should work. See also: Stack Overflow question checklist
Improve this question
Using UNIX Scripting it is possible to remove all the firsts characters from a file till a specific character is found ?
I have a file with "garbage" at the beginning. I want to remove that "garbage, meaning that all the character till the first "{" must be removed. How can I do this ?
cat file.txt | grep -A 1000000000 '{' | sed '1 s/^[^{]*//'
This will print the changed contents (i. e. without the garbage) to stdout. You can redirect this using > outfile.txt appended to the command:
cat file.txt | grep -A 1000000000 '{' | sed '1 s/^[^{]*//' > outfile.txt
And if you want to change the file in-place, this can be done by renaming the outfile.txt to the original name file.txt afterwards:
mv outfile.txt file.txt

How to copy recursive directory structure while creating symbolic file links only? [closed]

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
What's the best way to copy a whole recursive directory structure where all files are just copied as symbolic links?
In other words, the copy should mirror the whole directory (sub-)structure of the original directory but each file should just be a symbolic link.
I guess ... first you want to make your directories...
cd "$source"
find . -type d -exec mkdir -p "$target/{}" \;
Next, make your symlinks...
cd "$source"
find . -type f -print | (
cd "$target"
while read one; do
deep=$(echo "${one:2}" | sed 's:[^/][^/]*:..:g')
ln -s "${deep:3}/${one:2}" "$(basename "$one")"
done
)
Note that this will fail if you have linefeeds or possibly other odd characters in your filenames. I can't think of a quick way out of this (I mean by doing this in a find -exec), since you need to calculate $deep differently for each level of directory.
Also, this is untested, and I'm not planning to test it. If it gives you inspiration, that's great. :)
This is not the solution that will make symbolic links but it will make hard links.
cp -rl $src $dst
Cons:
it is harder to see if the file replaced in the tree
the both trees should be on the same filesystem

How to convert relative path to absolute path in Unix [closed]

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 12 months ago.
The community reviewed whether to reopen this question 12 months ago and left it closed:
Original close reason(s) were not resolved
Improve this question
I want to convert
Relative Path - /home/stevin/data/APP_SERVICE/../datafile.txt
to
Absolute Path - /home/stevin/data/datafile.txt
Is there a built-in tool in Unix to do this or any good ideas as to how can I implement this?
readlink -f /home/stevin/data/APP_SERVICE/../datafile.txt should do what you're looking for, assuming your Unix/Linux has readlink.
Something like this can help for directories: (For files, append with basename)
echo $(cd ../dir1/dir2/; pwd)
For files,
filepath=../dir1/dir2/file3
echo $(cd $(dirname $filepath); pwd)/$(basename $filepath)
I'm surprised nobody mentions realpath yet. Pass your paths to realpath and it will canonicalize them.
$ ls
Changes
dist.ini
$ ls | xargs realpath
/home/steven/repos/perl-Alt-Module-Path-SHARYANTO/Changes
/home/steven/repos/perl-Alt-Module-Path-SHARYANTO/dist.ini
Based on Thrustmaster's answer but with pure bash:
THING="/home/stevin/data/APP_SERVICE/../datafile.txt"
echo "$(cd ${THING%/*}; pwd)/${THING##*/}"
Of course the cd requires the path to actually exist, which may not always be the case - in that case, you'll probably have a simpler life by writing a small Python script instead...
This is my helper function
# get a real path from a relative path.
function realPath() {
if [[ -d "$1" ]]; then
currentPath="$(pwd)" # save current path
cd "$1" || exit 1 # cd to the checking dir
pwd
cd "$currentPath" || exit 1 # restore to original path
else
echo "$(cd "$(dirname "$1")" && pwd -P)/$(basename "$1")"
fi
}

Resources