Today (Saturday) We will make some minor tuning adjustments to MySQL.

You may experience 2 up to 10 seconds "glitch time" when we restart MySQL. We expect to make these adjustments around 1AM Eastern Daylight Saving Time (EDT) US.


Usage of '.' in MV command


 
Thread Tools Search this Thread
# 1  
Usage of '.' in MV command

Hi,

Could you please let me know, why we should not use '.' in move command, if we use it, is it something wrong.. Please share the details on it.

Code:
 
/home/rahualux/emp.csv /home/rahualux/details/employee_files/.

Or other example for mutlipile files

Code:
 
/home/rahualux/*.csv /home/rahualux/details/employee_files/.

# 2  
Every directory has a shorthand name to refer to itself. That special name is the `.' (dot) and it is a map to the inode of the directory.
It is quite useful when you are in a directory and you only have to enter a `.' to refer to where you are, instead of the whole path.
That's why people refer to the `.' as the "current directory". Or "`this' directory".

Using your example:
Code:
/home/rahualux/details/employee_files/.

It would be as saying: "`That' directory" and it doesn't make much sense, since you have to enter the full path already, including the name of the `that' employee_files directory.

In /home/rahualux/details, there can not be two inodes that has the same name, which means, there can NOT be a file named employee_files and a directory employee_files. Therefore, the trailing `/' in /home/rahualux/details/employee_files/ is not necessary.
mv knows that it is a directory.

To summarize the concepts using your example:
Code:
mv /home/rahualux/emp.csv /home/rahualux/details/employee_files

In human terms, it means, move the file emp.csv to employee_files, if employee_files is a directory, that directory gets a file named emp.csv, if employee_files is a file, that's what emp.csv would be called.

Code:
/home/rahualux/*.csv /home/rahualux/details/employee_files

employee_files has to be a directory, since multiple `anything.csv' can not be renamed to be called employee_files, due to the rule I mentioned before of "there can not be two inodes that have the same name, in the same directory"

Last edited by Aia; 05-14-2016 at 02:38 PM..
This User Gave Thanks to Aia For This Post:
# 4  
I agree with what Aia said, but there are cases where adding a "/." (or just "/") to the end of a pathname that is supposed to be a directory can be helpful. For example, with the command:
Code:
mv /home/rahualux/*.csv /home/rahualux/details/employee_files

it is true that mv will issue a diagnostic if /home/rahualux/*.csv expands to a list of more than one file if /home/rahualux/details/employee_files is not a directory; but if the *.csv only matches one file and employee_files does not exist (or is a non-directory file), the file matching *.csv will be copied to or linked to employee_files destroying its previous contents if there were any. While, under these circumstances, the command:
Code:
mv /home/rahualux/*.csv /home/rahualux/details/employee_files/

will get a diagnostic saying that employee_files is not a directory.

When I am typing a command into the shell to move a file into a directory, I usually add a trailing "/" on the directory name just to protect against typing mistakes. I tend not to do that in scripts if I am sure that the directory structure is safe. If the script I'm writing is moving files around in an file hierarchy where several people have write access and multiple people/processes might be rearranging files while the script is running, I frequently use a trailing "/" on the target directories so the script fails as soon as something goes wrong.

Whether or not you decide to add a "/" or "/." to the ends of directory names is something that will probably depend on your typing skills, how many times you lose a file by accidentally misspelling a directory name, how much pain you have gone through while trying to recover a file you accidentally lost due to typing mistakes, and how important the files you are moving at the moment are to you.
These 2 Users Gave Thanks to Don Cragun For This Post:
 

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Usage of '-' in eval command.

Hi, I am trying to use eval command to evaluate a variable(HAPROXY_LISTENER_rabbitmq_project-test-BRHM_PORT) which consists of '-' but unfortunately the eval command is unable to interpret the value of variable and trims the variable name after '-' and produces the string output rather than the... (10 Replies)
Discussion started by: Kuldip
10 Replies

2. Shell Programming and Scripting

Help on scp command usage

As part of our project dev , we need to create a shell script that COPY FILES FROM A SEPCIFIC DIRETORY OF THE LOCAL SYSTEM INTO A SPECIFIC LOCATION OF A REMOTE SERVER. USER1@SERVER1/Dir1/*.* ------- >USER2@SERVER2/Dir2 The main issues with this is requirement are : 1. THERE'S ONLY... (4 Replies)
Discussion started by: kumarjt
4 Replies

3. Shell Programming and Scripting

cp -v command usage?

I am trying to output a log file from cp usage. I think this can be achieved. In my code I have this. cp -i -v ~/files/* ~/backups/oldfiles/;; > ~/logs/logfile.logThe error I get is "syntax error near unexpected token '>' What am I missing? (7 Replies)
Discussion started by: gameinn
7 Replies

4. Shell Programming and Scripting

Usage cut command

cut command usages ?? i have a file named test contents : srikanth hyd 123 vinoth chn 234 vijay chn 345 hemanth hyd 456 $cut -f2 test should display: hyd chn chn hyd but am gettg full file?? (2 Replies)
Discussion started by: Diddy
2 Replies

5. UNIX for Dummies Questions & Answers

Command to display the space usage (memory usage) of a specific directory.

Hi all, Can you please tell me the command, with which one can know the amount of space a specific directory has used. df -k . ---> Displays, the amount of space allocated, and used for a directory. du -k <dir name> - gives me the memory used of all the files inside <dir> But i... (2 Replies)
Discussion started by: abhisheksunkari
2 Replies

6. HP-UX

Glance command Usage

Hello We have used Glance command to check Cpu Uage , bit new to Glance command , HP-UXdev # glance B3692A GlancePlus C.03.71.00 18:21:16 nedunix2 9000/800 Current Avg High -------------------------------------------------------------------------------- CPU Util S SN NU | 43% 59%... (1 Reply)
Discussion started by: lukas_pise
1 Replies

7. AIX

How to monitor the IBM AIX server for I/O usage,memory usage,CPU usage,network..?

How to monitor the IBM AIX server for I/O usage, memory usage, CPU usage, network usage, storage usage? (3 Replies)
Discussion started by: laknar
3 Replies

8. Shell Programming and Scripting

grep command usage

what is the grep command to get the second occurence of pattern in a file or how to do with sed ? (1 Reply)
Discussion started by: santosh1234
1 Replies

9. HP-UX

how can I find cpu usage memory usage swap usage and logical volume usage

how can I find cpu usage memory usage swap usage and I want to know CPU usage above X% and contiue Y times and memory usage above X % and contiue Y times my final destination is monitor process logical volume usage above X % and number of Logical voluage above can I not to... (3 Replies)
Discussion started by: alert0919
3 Replies

10. Shell Programming and Scripting

Usage of Touch Command

HI all, I am wrkin on HP Unix .. can any1 let me know da usage of Touch command in shell scripting (1 Reply)
Discussion started by: ravi.sadani19
1 Replies

Featured Tech Videos