LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Shell script help (https://www.linuxquestions.org/questions/linux-newbie-8/shell-script-help-927047/)

bbayne22 02-01-2012 08:50 PM

Shell script help
 
Hello I am new to shell scripts and have looked and researched on how to cut files from one folder and put it in a different folder I think I have all the cut and past cmd but can't get it to work

unSpawn 02-01-2012 09:08 PM

Quote:

Originally Posted by bbayne22 (Post 4591193)
I think I have all the cut and past cmd but can't get it to work

Please actually post what code you've tried and what the error was. The inner workings of Bourne or Bash shell scripts is easier to follow if you "set -vx" or execute as "sh -vx /path/to/script 2>&1 | tee /path/to/script.log".

tommyttt 02-02-2012 12:51 AM

Quote:

Originally Posted by bbayne22 (Post 4591193)
Hello I am new to shell scripts and have looked and researched on how to cut files from one folder and put it in a different folder I think I have all the cut and past cmd but can't get it to work

Basically you're saying you want to MOVE one file from a folder to another folder?? Easiest way to do that is with the "mv" command. Man mv will give you the information that is pertinent.

mv [options] source destination

Tom

kabamaru 02-02-2012 03:46 AM

And, a great site for learning the basic commands and shell scripting > LinuxCommand.org

chrism01 02-02-2012 07:36 PM

See also
http://rute.2038bug.com/index.html.gz
http://linux.die.net/man/
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html

devUnix 02-02-2012 11:57 PM

First note these two things:

Code:


Windows / Generic Terminoloty  <------> Unix/Linux Terminology

Cut (file/directory)                <------> Move (file/directory)

Paste (only in Editor)                <------> Put (such as in Vi or Vim)


Now, let me show you how to move a file from a directory to some other directory.


I am currently in this directory:

Code:


[demo@localhost ~]$ pwd
/home/demo
[demo@localhost ~]$

I have a file in /tmp directory:


Code:


[demo@localhost ~]$ ls /tmp/hello
/tmp/hello
[demo@localhost ~]$


Now I will move the above file into my current directory as shown below:

Code:

[demo@localhost ~]$ mv /tmp/hello .
[demo@localhost ~]$ ls hello
hello
[demo@localhost ~]$

Notice the dot (.) which means the current directory specified in place of the destination directory/location.

Now let's move the file back to its previous location:

Code:

[demo@localhost ~]$ mv hello /tmp

[demo@localhost ~]$ ls hello
ls: cannot access hello: No such file or directory

[demo@localhost ~]$ ls /tmp/hello
/tmp/hello
[demo@localhost ~]$

This time I have specified the destination directory's name/location. The file is not in the current directory hence you see the error above. It is back in the /tmp directory.

Before moving, you can check what you are going to move:

Code:


[demo@localhost ~]$ echo mv /tmp/h*
mv /tmp/hello
[demo@localhost ~]$

Use "echo" command as shown above. It saves your time and helps you see what exactly will happen. The above result means there is one file that begins with "h" and if I remove the "echo" part then it will be moved to my current directory.

To avoid overwriting a file if it is already present in the destination directory, do this:

Code:


[demo@localhost ~]$ mv -i /tmp/hello .
mv: overwrite `./hello'? n
[demo@localhost ~]$

Did you get it?

Note: If you do not provide a destination directory name then the file will be renamed:

Code:

[demo@localhost ~]$ mv /tmp/hello /tmp/hi
[demo@localhost ~]$ ls /tmp/h*
/tmp/hi
[demo@localhost ~]$

You should visit www.tldp.org and download/view the Linux Introduction guide from/on there.


All times are GMT -5. The time now is 01:58 PM.