LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-01-2012, 08:50 PM   #1
bbayne22
LQ Newbie
 
Registered: Jan 2012
Posts: 1

Rep: Reputation: Disabled
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
 
Old 02-01-2012, 09:08 PM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by bbayne22 View Post
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".
 
Old 02-02-2012, 12:51 AM   #3
tommyttt
Member
 
Registered: Oct 2009
Location: Federal Way, WA
Distribution: openSUSE 11.4 x86_64, openSuSE 12.1, Fedora 15
Posts: 207

Rep: Reputation: 34
Quote:
Originally Posted by bbayne22 View Post
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
 
Old 02-02-2012, 03:46 AM   #4
kabamaru
Member
 
Registered: Dec 2011
Location: Greece
Distribution: Slackware
Posts: 276

Rep: Reputation: 134Reputation: 134
And, a great site for learning the basic commands and shell scripting > LinuxCommand.org
 
Old 02-02-2012, 07:36 PM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,348

Rep: Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749
See also
http://rute.2038bug.com/index.html.gz
http://linux.die.net/man/
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
 
Old 02-02-2012, 11:57 PM   #6
devUnix
Member
 
Registered: Oct 2010
Posts: 606

Rep: Reputation: 59
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to pass command line arguments from one shell script to another shell script VijayaRaghavanLakshman Linux - Newbie 5 01-20-2012 09:12 PM
Executing a Shell script with 654 permissions inside another shell script. changusee2k Linux - Newbie 2 06-07-2011 07:58 PM
help with execute mulitple shell script within shell script ufmale Programming 6 09-13-2008 12:21 AM
shell script problem, want to use shell script auto update IP~! singying304 Programming 4 11-29-2005 05:32 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:16 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration