LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Command to move file from one dir to another (https://www.linuxquestions.org/questions/linux-newbie-8/command-to-move-file-from-one-dir-to-another-4175422937/)

gingernate 08-19-2012 08:55 PM

Command to move file from one dir to another
 
I need to move binutils-2.22.tar.bz2 from the Downloads dir to /mnt/lfs/sources. Here is what i have tried;



nathan@nathan-linux:~/Downloads$ mv /Downloads/binutils-2.22.tar.bz2 /mnt/lfs/sources
mv: cannot stat `/Downloads/binutils-2.22.tar.bz2': No such file or directory


When i cd to Downloads and ls i get this;

nathan@nathan-linux:~/Downloads$ ls
autoconf-2.68.tar.bz2 lfs-bootscripts-20120229.tar.bz2
automake-1.11.3.tar.xz libpipeline-1.2.0.tar.gz
bash-4.2.tar.gz libtool-2.4.2.tar.gz
binutils-2.22.tar.bz2

So the file does exist.... So what am i missing?


EDIT: I have tried to use GUI and i cant because i do not have proper permissions to move from main user to my LFS(linux from scratch) user

byannoni 08-19-2012 09:06 PM

Quote:

Originally Posted by gingernate (Post 4758623)
mv /Downloads/binutils-2.22.tar.bz2 /mnt/lfs/sources

You don't need a / for files in the current directory.

Do this:
Code:

mv ~/Downloads/binutils-2.22.tar.bz2 /mnt/lfs/sources

gingernate 08-19-2012 09:07 PM

THANK YOU!!! Worked like a charm!

gingernate 08-19-2012 09:17 PM

Hey is there anyway to move all these files?

nathan@nathan-linux:~/Downloads$ ls
automake-1.11.3.tar.xz libpipeline-1.2.0.tar.gz
bash-4.2.tar.gz libtool-2.4.2.tar.gz
bison-2.5.tar.bz2 linux-3.2.6.tar.xz
bzip2-1.0.6.tar.gz lxterminal.desktop
check-0.9.8.tar.gz m4-1.4.16.tar.bz2
coreutils-8.15.tar.xz make-3.82.tar.bz2
dejagnu-1.5.tar.gz man-db-2.6.1.tar.gz
diffutils-3.2.tar.gz man-pages-3.35.tar.gz
e2fsprogs-1.42.tar.gz mpc-0.9.tar.gz
expect5.45.tar.gz mpfr-3.1.0.tar.bz2
file-5.10.tar.gz ncurses-5.9.tar.gz
findutils-4.4.2.tar.gz patch-2.6.1.tar.bz2
flex-2.5.35.tar.bz2 perl-5.14.2.tar.bz2
gawk-4.0.0.tar.bz2 procps-3.2.8.tar.gz
gcc-4.6.2.tar.bz2 psmisc-22.15.tar.gz
gdbm-1.10.tar.gz readline-6.2.tar.gz
gettext-0.18.1.1.tar.gz sed-4.2.1.tar.bz2
glibc-2.14.1.tar.bz2 shadow-4.1.5.tar.bz2
gmp-5.0.4.tar.xz sysklogd-1.5.tar.gz
grep-2.10.tar.xz sysvinit-2.88dsf.tar.bz2
groff-1.21.tar.gz tar-1.26.tar.bz2
gzip-1.4.tar.gz tcl8.5.11-src.tar.gz
iana-etc-2.30.tar.bz2 texinfo-4.13a.tar.gz
inetutils-1.9.1.tar.gz udev-181.tar.xz
iproute2-3.2.0.tar.xz udev-config-20100128.tar.bz2
kbd-1.15.2.tar.gz util-linux-2.20.1.tar.bz2
kmod-5.tar.xz vim-7.3.tar.bz2
less-444.tar.gz xz-5.0.3.tar.bz2
lfs-bootscripts-20120229.tar.bz2 zlib-1.2.6.tar.bz2

suicidaleggroll 08-19-2012 09:24 PM

You mean like
Code:

mv ~/Downloads/* /path/to/destination/dir/
?

gingernate 08-19-2012 09:28 PM

suicidaleggroll, YESSSS!!!!!!!!!!! thanks so much!

David the H. 08-20-2012 01:57 PM

Please use ***[code][/code] tags*** around your code and data, to preserve formatting and to improve readability. Please do not use quote tags, bolding, colors, or other fancy formatting.

Code:

/Downloads/binutils-2.22.tar.bz2
When a pathname starts with "/" it signifies the absolute path to the file, starting from the system root. So this is looking for the file in "rootdir > downloads", not "rootdir > home > user > Downloads", the directory it's actually in.

If you are already in the directory with the file, you don't need to use the full path. Just use the relative path. Naming the file itself alone is usually enough, or alternately you can prefix it with ".", which means the current directory (and ".." means the parent directory).

Also, "~" is a pathname shortcut for your home dir, so you can include it instead of the "/home/user" part of the pathname. You could also use the $HOME variable, which contains the same string.

So any of these should work to move the file, assuming you are currently in the Downloads directory:
Code:

mv Downloads/binutils-2.22.tar.bz2 /mnt/lfs/sources
mv ./Downloads/binutils-2.22.tar.bz2 /mnt/lfs/sources
mv ~/Downloads/binutils-2.22.tar.bz2 /mnt/lfs/sources
mv $HOME/Downloads/binutils-2.22.tar.bz2 /mnt/lfs/sources
mv /home/user/Downloads/binutils-2.22.tar.bz2 /mnt/lfs/sources


To work with multiple files at once, have a look at globbing:

http://mywiki.wooledge.org/glob
http://wiki.bash-hackers.org/syntax/expansion/globs


Finally, it's also vital to understand how the shell handles arguments and whitespace. If a filename contains whitespace you'll need to quote or backslash it:
http://mywiki.wooledge.org/Arguments
http://mywiki.wooledge.org/WordSplitting
http://mywiki.wooledge.org/Quotes


All times are GMT -5. The time now is 05:14 PM.