LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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 01-05-2009, 06:52 PM   #1
edpatterson
LQ Newbie
 
Registered: Aug 2003
Location: Florida
Distribution: Ubuntu
Posts: 12

Rep: Reputation: 0
Bash equivelant of dir /a-d?


I need a way to get a list of file names (no directories, no links) from a directory. I will then process that list. One of the steps in the process is to move and rename the file.

the result of for file in /path/* contains the path to the file so a resultant mv $file /newpath/$file fails.

Files are being dropped into /tmp I need to copy them out to a different directory then move them to yet another directory with the current date and time integrated into the file name.

(from others who are helping)
Code:
#!/bin/bash

for file in *                  
do
 if [ -r "$file" ]; then        

 cp "$file" "$file.extension"   

 mv "$file" "$(date stuff)$file"
fi
done
 
Old 01-05-2009, 07:47 PM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,254

Rep: Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328
You can use the basename cmd to extract the filename see
man basename

eg
Code:
basename /home/test
test
or more explicitly
Code:
new_file=$(basename $file)
 
  


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
Bash script to compare dir contents Boffy Programming 2 08-02-2005 07:08 AM
Bash Scripts for Dir listing jchristman Linux - General 6 08-26-2004 09:58 AM
-bash no such file or dir slackwarefan Slackware 3 06-12-2004 08:49 AM
simple bash question -- changing dir towlie Programming 3 05-28-2004 12:55 PM
bash script to rm all files in a dir keirobyn Programming 8 07-19-2002 08:53 AM


All times are GMT -5. The time now is 10:13 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration