Support Questions

Find answers, ask questions, and share your expertise

Move files from edge node to hdfs using single command with different file name

avatar

Move files from edge node to hdfs using single command with different file name

6 REPLIES 6

avatar
@Santhosh Reddy

Is this something you are looking for ? if not please elaborate your question on what exactly you want to achieve.

[spark@node-1 ~]$ touch 1
[spark@node-1 ~]$ touch 2
[spark@node-1 ~]$ hadoop fs -put 1 2 /tmp/
[spark@node-1 ~]$ hadoop fs -ls /tmp/
Found 12 items
-rw-r--r--   3 spark     hdfs          0 2018-03-03 02:17 /tmp/1
-rw-r--r--   3 spark     hdfs          0 2018-03-03 02:17 /tmp/2

avatar

I have a file which contains filename.0020180302 and filename.0020180301 and filename.0020182901 in edge node i want to move file to hdfs with file name with particular date . How to do that in single command

avatar

@Santhosh Reddy You can use the data command as below and select the files.

[spark@node-1 ~]$ touch filename.0020180303
[spark@node-1 ~]$ ll filename.00`date +%Y%m%d`
-rw-r--r--. 1 spark hadoop 0 Mar  3 03:20 filename.0020180303
[spark@node-1 ~]$ hadoop fs -put filename.00`date +%Y%m%d` /tmp/
[spark@node-1 ~]$ hadoop fs -ls /tmp/filename*
-rw-r--r--   3 spark hdfs          0 2018-03-03 03:21 /tmp/filename.0020180303

avatar

I can not use * because lets suppose i have 100 files out of which i want to move only files that came in last 3 days . All I am looking for do it in single command . Thanks I appreciate your help

avatar

'*' has been used just to list the files in HDFS, you can use filename.00`date +%Y%m%d` to specify the date format and then move them accordingly.

avatar

Thanks for quick reply .Previously This is what I am doing. Now my question is Can I move all these 4 files in a single command ? Is there any & Operator available
hdfs dfs -copyToLocal /20180217_AAA_02172018_C.dat /tmp/AAA_02172018_C.dat

hdfs dfs -copyToLocal /20180218_AAA_02182018_C.dat /tmp/AAA_02182018_C.dat

hdfs dfs -copyToLocal /20180219_AAA_02192018_C.dat /tmp/AAA_02182018_C.dat

hdfs dfs -copyToLocal /201802120_AAA_021202018_C.dat /tmp/AAA_02182018_C.dat