How to get a filename modified by attaching modified timestamp


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to get a filename modified by attaching modified timestamp
# 15  
Old 05-12-2009
no space between --time and -style use --time-style
ls -l --time -style=+%Y%m%d%H%M%S | awk '{print $7$6}'


[root@Reddyraja test]# ls --version
ls (GNU coreutils) 6.10
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Richard Stallman and David MacKenzie.


[root@Reddyraja test]# ls --help
Usage: ls [OPTION]... [FILE]...
List information about the FILEs (the current directory by default).
Sort entries alphabetically if none of -cftuvSUX nor --sort.

Mandatory arguments to long options are mandatory for short options too.
-a, --all do not ignore entries starting with .
-A, --almost-all do not list implied . and ..
--author with -l, print the author of each file
-b, --escape print octal escapes for nongraphic characters
--block-size=SIZE use SIZE-byte blocks
-B, --ignore-backups do not list implied entries ending with ~
-c with -lt: sort by, and show, ctime (time of last
modification of file status information)
with -l: show ctime and sort by name
otherwise: sort by ctime
-C list entries by columns
--color[=WHEN] control whether color is used to distinguish file
types. WHEN may be `never', `always', or `auto'
-d, --directory list directory entries instead of contents,
and do not dereference symbolic links
-D, --dired generate output designed for Emacs' dired mode
-f do not sort, enable -aU, disable -ls --color
-F, --classify append indicator (one of */=>@|) to entries
--file-type likewise, except do not append `*'
--format=WORD across -x, commas -m, horizontal -x, long -l,
single-column -1, verbose -l, vertical -C
--full-time like -l --time-style=full-iso
-g like -l, but do not list owner
--group-directories-first
group directories before files
-G, --no-group in a long listing, don't print group names
-h, --human-readable with -l, print sizes in human readable format
(e.g., 1K 234M 2G)
--si likewise, but use powers of 1000 not 1024
-H, --dereference-command-line
follow symbolic links listed on the command line
--dereference-command-line-symlink-to-dir
follow each command line symbolic link
that points to a directory
--hide=PATTERN do not list implied entries matching shell PATTERN
(overridden by -a or -A)
--indicator-style=WORD append indicator with style WORD to entry names:
none (default), slash (-p),
file-type (--file-type), classify (-F)
-i, --inode print the index number of each file
-I, --ignore=PATTERN do not list implied entries matching shell PATTERN
-k like --block-size=1K
-l use a long listing format
-L, --dereference when showing file information for a symbolic
link, show information for the file the link
references rather than for the link itself
-m fill width with a comma separated list of entries
-n, --numeric-uid-gid like -l, but list numeric user and group IDs
-N, --literal print raw entry names (don't treat e.g. control
characters specially)
-o like -l, but do not list group information
-p, --indicator-style=slash
append / indicator to directories
-q, --hide-control-chars print ? instead of non graphic characters
--show-control-chars show non graphic characters as-is (default
unless program is `ls' and output is a terminal)
-Q, --quote-name enclose entry names in double quotes
--quoting-style=WORD use quoting style WORD for entry names:
literal, locale, shell, shell-always, c, escape
-r, --reverse reverse order while sorting
-R, --recursive list subdirectories recursively
-s, --size print the size of each file, in blocks
-S sort by file size
--sort=WORD sort by WORD instead of name: none -U,
extension -X, size -S, time -t, version -v
--time=WORD with -l, show time as WORD instead of modification
time: atime -u, access -u, use -u, ctime -c,
or status -c; use specified time as sort key
if --sort=time
--time-style=STYLE with -l, show times using style STYLE:
full-iso, long-iso, iso, locale, +FORMAT.
FORMAT is interpreted like `date'; if FORMAT is
FORMAT1<newline>FORMAT2, FORMAT1 applies to
non-recent files and FORMAT2 to recent files;
if STYLE is prefixed with `posix-', STYLE
takes effect only outside the POSIX locale
-t sort by modification time
-T, --tabsize=COLS assume tab stops at each COLS instead of 8
-u with -lt: sort by, and show, access time
with -l: show access time and sort by name
otherwise: sort by access time
-U do not sort; list entries in directory order
-v sort by version
-w, --width=COLS assume screen width instead of current value
-x list entries by lines instead of by columns
-X sort alphabetically by entry extension
-1 list one file per line

SELINUX options:

--lcontext Display security context. Enable -l. Lines
will probably be too wide for most displays.
-Z, --context Display security context so it fits on most
displays. Displays only mode, user, group,
security context and file name.
--scontext Display only security context and file name.
--help display this help and exit
--version output version information and exit
# 16  
Old 06-02-2009
~$ ls -la file*
-rw-r--r-- 1 leen leen 0 2009-06-02 22:02 file

~$ mv file file_`ls -l --time-style=+%G%d%H%M%S |awk '{print $6}'|tail -1`

~$ ls -la file*
-rw-r--r-- 1 leen leen 0 2009-06-02 22:02 file_200903201848


Something like that?
# 17  
Old 06-03-2009
Bug Use this

mv siddhesh siddh_new.`date +%Y%m%d`

I have tested the same, and it works properly fine.

-----Post Update-----

I have tested this command and it works fine.

mv siddhesh siddh_new.`date +%Y%m%d`

Regards,
SIddhesh
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Find all files containing string not following symlinks CAT (modified) output content to /filename

This should recursively walk through all dirictories and search for a specified string in all present files, if found output manicured content (eg some regex) with CAT into a specified directory (eg /tmp/) one by one, keeping the original names This is what I have so far, which seems to... (1 Reply)
Discussion started by: lowmaster
1 Replies

2. Shell Programming and Scripting

Find file by filename or with newest modified date

Hi, I have a directory that has numerous files in it, and there is two which are named "filerec_ddmmyyHH24MMSS" by the time they are created so "filerec_010615012250" was created at 01:22:50 on 1st June 2015. I need to find the most recently created of those 2 files and get the contents of... (4 Replies)
Discussion started by: finn
4 Replies

3. Shell Programming and Scripting

How to read and write last modified timestamp to files?

Need help reading file last modified date in format: Filename (relative path);YYYYMMDDHHMMSS And then write it back. My idea is to backup it to a text file to restore later. Checked this command but does not work: Getting the Last Modification Timestamp of a File with Stat $ stat -f... (5 Replies)
Discussion started by: Tribe
5 Replies

4. UNIX for Dummies Questions & Answers

Finding the modified timestamp of files from the piped output of du command

Version Info +++++++++++++++ RHEL 5.4 Since ls command lists file sizes in Bytes which can be long I use du command like below. I have run the du command for the below files as shown below. But I want pipe this output to ls command just to see the modified timestamp for these files. ... (7 Replies)
Discussion started by: kraljic
7 Replies

5. Shell Programming and Scripting

Shell script to use the last modified filename in a variable

Forgive me if this is a trivial question, but I haven't been able to find the answer to this. Basically I've got a list of files in a particular directory that have the general form t_*.dat. (I have other files in the same directory as well). Essentially what I want to do is obtain the name... (1 Reply)
Discussion started by: lost.identity
1 Replies

6. Shell Programming and Scripting

Getting modified time & filename only

Hi, When we use "ls -l" we are getting like below, -rw-r--r-- 1 mdskl mds 4161479 Apr 12 14:57 VTTF2008.20080412145748.cc But i need only modified time and filename only like below, Apr 12 14:57 VTTF3008.20080412145748.cc Thanks-:) Senthil (4 Replies)
Discussion started by: senthil_seera
4 Replies

7. UNIX for Advanced & Expert Users

Find and store files based on FileName and Modified Time

Hi, I am currently using the following command: files=(ls enuCPU??.????.exp ntuCPU??.????.exp) I need to now change the commmand to store the file names of files that have been modified before datetime equal to say '02/16/2008 20:30:00' What could I use? (2 Replies)
Discussion started by: edisonantus
2 Replies

8. UNIX for Dummies Questions & Answers

how to retrieve original contents of a modified file (modified using vi)

Made changes to a file using vi editor and saved those changes now realised that the changes are not required How can I get the previous version of the file.i.e the one which was there on which I had made changes (3 Replies)
Discussion started by: novice100
3 Replies

9. Shell Programming and Scripting

Last Modified Date

Hello, I'm on a practical training and i have to change a shell script which print out a HTML-File with all Printers (and features example: IP, Mac etc.) they have in the factory. The Features of the Printers are on each separate file. i mean every printer have an own file with it features. ... (12 Replies)
Discussion started by: cengiz
12 Replies

10. Programming

File last modified

I cannot read the last moment the file was modified - it returns "Most recent access" instead: code: </td> <th><?FILE *fatr=fopen(iindname.c_str(), "r"); if(fatr){ struct stat statbuf; fstat(fileno(fatr), &statbuf); fclose(fatr); ?> ... (4 Replies)
Discussion started by: szzz
4 Replies
Login or Register to Ask a Question