Consider something like B/A/C.txt
.
How can I move the C.txt
file to its parent's parent directory so the result would be B/C.txt
?
For educational purposes
$ man bash
Type /
and fill in ^ +Parameter Expansion
then press ENTER
Alternatively study the Bash guides at www.tldp.org
An example to study:
$ f="B/A/C.txt" $ mkdir -p "${f%/*}" $ touch "$f" $ find "${f%%/*}" ... $ mv "${f}" "${f%/*}/.." $ find "${f%%/*}" B B/C.txt B/A
Please note: This is NOT a general answer, there are caveats; but might be consider to be very close to it.
More to study, restarted from scratch:
$ f="B/A/C.txt" $ mkdir -p "${f%/*}" $ touch "$f" $ ( cd ${f%/*} && mv ${f##*/} .. )
on Linux terminal mv C.txt ../.. make the trick:
$ mkdir -p /tmp/A/B # create as a temporary dir
$ cd /tmp/A/B # get into dir
$ pwd # show were you are
/tmp/A/B
$ echo 'foo' > C.txt # create a file containing text foo
$ mv C.txt ../.. # move file into parent dir of parent dir
$ cd ../../ # get into there
$ pwd # are we there?
/tmp
$ cat C.txt # check your file.
foo
You can accomplish that by doing
mv B/A/C.txt B/
or
mv B/A/C.txt B/C.txt
or
cd B/A/
mv C.txt ..
B/A/C.txt
toB/C.txt
, you're moving it to it's parent directory, not it's parent's parent directory.