Copy particular file using "ls -ltr"


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Copy particular file using "ls -ltr"
# 1  
Old 09-28-2012
Copy particular file using "ls -ltr"

Hi all,
I am new in shell scripting and trying to write a script which does the following:
Code:
#!/bin/bash
$PATH =/a/b/c
ls -ltr $PATH
$VARIABLE=???

Code:
$ls -ltr $PATH
-rw-r--r-- 1 18401 1399  127474 Apr 13 07:21 file_abc_1.txt
-rw-r--r-- 1 18401 1399  127474 July 13 07:21 file_abc_2.txt
-rw-r--r-- 1 18401 1399  127474 Aug 13 07:21 file_abc_3.txt
-rw-r--r-- 1 18401 1399  127474 Aug 13 07:21 file_cdf_1.txt

I would like the script to copy the filename (for example: file_abc_3.txt). The latest $PATH/file with txt file_abc* and assign it to some VARIABLE which I want to use further in the script.

Also I would like to ask if I can assign another variable (varB=/a/b/c/file1/txt) from a txt file (text below)
Code:
version: version 2.1
Working directory:  /a/b/c
Data: /source/path/
Total files: 212
Calculated summary file: /a/b/c/file1/txt
log file: /a/b/log.txt

Thanks in advance,
emily

Last edited by emily; 09-28-2012 at 05:37 PM..
# 2  
Old 09-28-2012
I do not understand the second question. What are you trying to get?

First question, one way to do what you want
Code:
var=$( ls -rt | tail -1 )

$var now contains the filename
# 3  
Old 09-28-2012
Quote:
Originally Posted by jim mcnamara
I do not understand the second question. What are you trying to get?

First question, one way to do what you want
Code:
var=$( ls -rt | tail -1 )

$var now contains the filename
Thanks for the first question.

In the second question I want to have another variable assignment. From the txt file, I want the variable2 to have the value /a/b/c/file1/txt

Is it clear now?

thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

3. Shell Programming and Scripting

finding the strings beween 2 characters "/" & "/" in .txt file

Hi all. I have a .txt file that I need to sort it My file is like: 1- 88 chain0 MASTER (FF-TE) FFFF 1962510 /TCK T FD2TQHVTT1 /jtagc/jtag_instreg/updateinstr_reg_1 dff1 (TI,SO) 2- ... (10 Replies)
Discussion started by: Behrouzx77
10 Replies

4. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

5. Shell Programming and Scripting

"~" comes in filename after file copy

I have a windows n/w share mapped to a unix path. I am trying to copy the file from one unix location to this location using "cp" command. After I copy the copy and check the filename logging through unix, I can see it as expected. But, when I check the file from Windows at the n/w share, the... (10 Replies)
Discussion started by: khuman
10 Replies

6. Shell Programming and Scripting

"sed" to check file size & echo " " to destination file

Hi, I've modified the syslogd source to include a thread that will keep track of a timer(or a timer thread). My intention is to check the file size of /var/log/messages in every one minute & if the size is more than 128KB, do a echo " " > /var/log/messages, so that the file size will be set... (7 Replies)
Discussion started by: jockey007
7 Replies

7. Shell Programming and Scripting

cannot copy file using scp when filename has ":"

hi all , does any one know how can we copy a file using scp which have a file name inlcuding "+:" example : ls -lrt *.csv | tail -3 -rw-r----- 1 opern oper 8479 Feb 15 15:39 LKILA.csv -rw-r----- 1 opern oper 8479 Feb 18 12:06 L+KILA.csv -rw-r----- 1... (4 Replies)
Discussion started by: kiranreddy1215
4 Replies

8. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies

9. AIX

CP to copy file is "stuck"

For some reason, when I attempt to copy a file, using cp, from one location to another the cmd is stuck (or taking an unusually long time). Usually copying a 1 GB file will take 3-4 mins, so far it's at 11 mins and yesterday was stuck for several hours. Is there a way I can see WHY or WHAT is... (5 Replies)
Discussion started by: mcubitt
5 Replies
Login or Register to Ask a Question